mirror of
https://github.com/songquanpeng/one-api.git
synced 2026-05-01 13:54:26 +08:00
Compare commits
1 Commits
4e5305de52
...
a6499fd72f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6499fd72f |
@@ -64,9 +64,6 @@ func StreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*model.E
|
|||||||
if choice.Delta.Reasoning != nil {
|
if choice.Delta.Reasoning != nil {
|
||||||
reasoningText += *choice.Delta.Reasoning
|
reasoningText += *choice.Delta.Reasoning
|
||||||
}
|
}
|
||||||
if choice.Delta.ReasoningContent != nil {
|
|
||||||
reasoningText += *choice.Delta.ReasoningContent
|
|
||||||
}
|
|
||||||
|
|
||||||
responseText += conv.AsString(choice.Delta.Content)
|
responseText += conv.AsString(choice.Delta.Content)
|
||||||
}
|
}
|
||||||
@@ -143,17 +140,10 @@ func Handler(c *gin.Context, resp *http.Response, promptTokens int, modelName st
|
|||||||
return ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
return ErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if textResponse.Usage.TotalTokens == 0 ||
|
if textResponse.Usage.TotalTokens == 0 || (textResponse.Usage.PromptTokens == 0 && textResponse.Usage.CompletionTokens == 0) {
|
||||||
(textResponse.Usage.PromptTokens == 0 && textResponse.Usage.CompletionTokens == 0) {
|
|
||||||
completionTokens := 0
|
completionTokens := 0
|
||||||
for _, choice := range textResponse.Choices {
|
for _, choice := range textResponse.Choices {
|
||||||
completionTokens += CountTokenText(choice.Message.StringContent(), modelName)
|
completionTokens += CountTokenText(choice.Message.StringContent(), modelName)
|
||||||
if choice.Message.Reasoning != nil {
|
|
||||||
completionTokens += CountToken(*choice.Message.Reasoning)
|
|
||||||
}
|
|
||||||
if choice.ReasoningContent != nil {
|
|
||||||
completionTokens += CountToken(*choice.ReasoningContent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
textResponse.Usage = model.Usage{
|
textResponse.Usage = model.Usage{
|
||||||
PromptTokens: promptTokens,
|
PromptTokens: promptTokens,
|
||||||
|
|||||||
@@ -102,9 +102,6 @@ func postConsumeQuota(ctx context.Context, usage *relaymodel.Usage, meta *meta.M
|
|||||||
var quota int64
|
var quota int64
|
||||||
completionRatio := billingratio.GetCompletionRatio(textRequest.Model, meta.ChannelType)
|
completionRatio := billingratio.GetCompletionRatio(textRequest.Model, meta.ChannelType)
|
||||||
promptTokens := usage.PromptTokens
|
promptTokens := usage.PromptTokens
|
||||||
// It appears that DeepSeek's official service automatically merges ReasoningTokens into CompletionTokens,
|
|
||||||
// but the behavior of third-party providers may differ, so for now we do not add them manually.
|
|
||||||
// completionTokens := usage.CompletionTokens + usage.CompletionTokensDetails.ReasoningTokens
|
|
||||||
completionTokens := usage.CompletionTokens
|
completionTokens := usage.CompletionTokens
|
||||||
quota = int64(math.Ceil((float64(promptTokens) + float64(completionTokens)*completionRatio) * ratio))
|
quota = int64(math.Ceil((float64(promptTokens) + float64(completionTokens)*completionRatio) * ratio))
|
||||||
if ratio != 0 && quota <= 0 {
|
if ratio != 0 && quota <= 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user