You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: add reasoning tokens into token metrics in stream mode for gemini models (#2259)
**Description**
The previous implementation on tokens tracking is like
```
if chunk.UsageMetadata.CandidatesTokenCount >= 0 {
tokenUsage.SetOutputTokens(uint32(chunk.UsageMetadata.CandidatesTokenCount)) //nolint:gosec
}
```
The output tokens should include both the reasoning tokens and the
candidates tokens. Thus fix this by reusing the the variable `usage`,
just like non-streaming mode. Also updated the tests to include
reasoning tokens
---------
Signed-off-by: yxia216 <yxia216@bloomberg.net>
Co-authored-by: Ignasi Barrera <ignasi@tetrate.io>
wantTokenUsage: tokenUsageFrom(5, 0, -1, 3, 8, 0), // Does not support Cache Creation.
1246
+
wantTokenUsage: tokenUsageFrom(5, 0, -1, 13, 18, 10), // Does not support Cache Creation.
1247
1247
},
1248
1248
{
1249
1249
name: "stream chunks with thought signature on text part",
@@ -1252,7 +1252,7 @@ data: [DONE]
1252
1252
},
1253
1253
body: `data: {"candidates":[{"content":{"parts":[{"text":"let me think about this.", "thought": true}]}}]}
1254
1254
1255
-
data: {"candidates":[{"content":{"parts":[{"text":"The answer is 42.", "thoughtSignature": "dGVzdHNpZ25hdHVyZQ=="}]}}],"usageMetadata":{"promptTokenCount":10,"candidatesTokenCount":8,"totalTokenCount":18}}`,
1255
+
data: {"candidates":[{"content":{"parts":[{"text":"The answer is 42.", "thoughtSignature": "dGVzdHNpZ25hdHVyZQ=="}]}}],"usageMetadata":{"promptTokenCount":10,"candidatesTokenCount":8,"totalTokenCount":33,"thoughtsTokenCount":15}}`,
1256
1256
stream: true,
1257
1257
endOfStream: true,
1258
1258
wantError: false,
@@ -1261,11 +1261,11 @@ data: {"candidates":[{"content":{"parts":[{"text":"The answer is 42.", "thoughtS
1261
1261
1262
1262
data: {"choices":[{"index":0,"delta":{"content":"The answer is 42.","role":"assistant","reasoning_content":{"signature":"dGVzdHNpZ25hdHVyZQ=="}}}],"object":"chat.completion.chunk"}
0 commit comments