Commit 2c0fd291 by CaIon

fix: improve usage calculation in GeminiTextGenerationStreamHandler

parent 16997a69
...@@ -130,7 +130,13 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, resp *http.Response, info ...@@ -130,7 +130,13 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, resp *http.Response, info
// 如果usage.CompletionTokens为0,则使用本地统计的completion tokens // 如果usage.CompletionTokens为0,则使用本地统计的completion tokens
if usage.CompletionTokens == 0 { if usage.CompletionTokens == 0 {
usage = service.ResponseText2Usage(responseText.String(), info.UpstreamModelName, info.PromptTokens) str := responseText.String()
if len(str) > 0 {
usage = service.ResponseText2Usage(responseText.String(), info.UpstreamModelName, info.PromptTokens)
} else {
// 空补全,不需要使用量
usage = &dto.Usage{}
}
} }
// 移除流式响应结尾的[Done],因为Gemini API没有发送Done的行为 // 移除流式响应结尾的[Done],因为Gemini API没有发送Done的行为
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment