Skip to content

Commit 0cbdb93

Browse files
authored
openai: don't skip chunk when having token usage (#706)
1 parent f170eeb commit 0cbdb93

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

model/openai/openai.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,8 @@ func (m *Model) shouldSuppressChunk(chunk openai.ChatCompletionChunk) bool {
13481348
// 2. Check content - if valid, don't skip (even if empty string)
13491349
// 3. Check refusal - if valid, don't skip
13501350
// 4. Check toolcalls - if valid but array is empty, skip (defensive against panic)
1351-
// 5. Otherwise, skip
1351+
// 5. Check usage - if valid, don't skip
1352+
// 6. Otherwise, skip
13521353
func (m *Model) shouldSkipEmptyChunk(chunk openai.ChatCompletionChunk) bool {
13531354
// No choices available, don't skip (let it be processed normally).
13541355
if len(chunk.Choices) == 0 {
@@ -1373,6 +1374,10 @@ func (m *Model) shouldSkipEmptyChunk(chunk openai.ChatCompletionChunk) bool {
13731374
return len(delta.ToolCalls) == 0
13741375
}
13751376

1377+
if chunk.Usage.CompletionTokens > 0 || chunk.Usage.PromptTokens > 0 || chunk.Usage.TotalTokens > 0 {
1378+
return false
1379+
}
1380+
13761381
// Otherwise there is no meaningful delta, skip the chunk.
13771382
return true
13781383
}

0 commit comments

Comments
 (0)