mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-09 02:03:42 +08:00
feat: enhance reasoning token handling in OpenAI adaptor
This commit is contained in:
@@ -66,6 +66,9 @@ func StreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*model.E
|
||||
if choice.Delta.Reasoning != nil {
|
||||
reasoningText += *choice.Delta.Reasoning
|
||||
}
|
||||
if choice.Delta.ReasoningContent != nil {
|
||||
reasoningText += *choice.Delta.ReasoningContent
|
||||
}
|
||||
|
||||
responseText += conv.AsString(choice.Delta.Content)
|
||||
}
|
||||
@@ -99,6 +102,12 @@ func StreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*model.E
|
||||
return ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), "", nil
|
||||
}
|
||||
|
||||
// If there is no reasoning tokens in the completion, we should count the reasoning tokens in the response.
|
||||
if len(reasoningText) > 0 &&
|
||||
(usage.CompletionTokensDetails == nil || usage.CompletionTokensDetails.ReasoningTokens == 0) {
|
||||
usage.CompletionTokens += CountToken(reasoningText)
|
||||
}
|
||||
|
||||
return nil, reasoningText + responseText, usage
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user