Skip to content

Commit

Permalink
🔖 chore: coze Count tokens. #221
Browse files Browse the repository at this point in the history
  • Loading branch information
MartialBE committed May 25, 2024
1 parent 34e1543 commit e2020cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions providers/coze/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ func (p *CozeProvider) convertToChatOpenai(response *CozeResponse, request *type
}},
}

p.Usage.CompletionTokens = 0
p.Usage.PromptTokens = 1
p.Usage.TotalTokens = 1
p.Usage.CompletionTokens = common.CountTokenText(response.String(), request.Model)
p.Usage.TotalTokens = p.Usage.CompletionTokens + p.Usage.PromptTokens
openaiResponse.Usage = p.Usage

return
Expand Down Expand Up @@ -187,9 +186,8 @@ func (h *CozeStreamHandler) convertToOpenaiStream(chatResponse *CozeStreamRespon
choice.FinishReason = types.FinishReasonStop
} else {
choice.Delta.Content = chatResponse.Message.Content

h.Usage.TotalTokens = 1
h.Usage.PromptTokens = 1
h.Usage.CompletionTokens += common.CountTokenText(chatResponse.Message.Content, h.Request.Model)
h.Usage.TotalTokens = h.Usage.CompletionTokens + h.Usage.PromptTokens
}

streamResponse.Choices = []types.ChatCompletionStreamChoice{choice}
Expand Down

0 comments on commit e2020cd

Please sign in to comment.