Skip to content

Commit

Permalink
feat(llm-bridge): Azure OpenAI Provider returns the token usage when …
Browse files Browse the repository at this point in the history
…requested with include_usage (#906)

as described in:

- Azure/azure-sdk-for-net#44237

Azure OpenAI has added support for this feature.
  • Loading branch information
woorui committed Sep 11, 2024
1 parent 29fce94 commit 141b747
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/bridge/ai/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ func (srv *Service) GetChatCompletions(ctx context.Context, req openai.ChatCompl
completionUsage = streamRes.Usage.CompletionTokens
totalUsage = streamRes.Usage.TotalTokens
}
if len(streamRes.Choices) == 0 {
continue
}
if tc := streamRes.Choices[0].Delta.ToolCalls; len(tc) > 0 {

choices := streamRes.Choices
if len(choices) > 0 && len(choices[0].Delta.ToolCalls) > 0 {
tc := choices[0].Delta.ToolCalls
isFunctionCall = true
if j == 0 {
firstCallSpan.End()
Expand All @@ -321,7 +321,7 @@ func (srv *Service) GetChatCompletions(ctx context.Context, req openai.ChatCompl
toolCallsMap[index] = item
}
j++
} else if streamRes.Choices[0].FinishReason != openai.FinishReasonToolCalls {
} else if !isFunctionCall {
_ = writeStreamEvent(w, flusher, streamRes)
}
if i == 0 && j == 0 && !isFunctionCall {
Expand Down

0 comments on commit 141b747

Please sign in to comment.