Skip to content

Commit

Permalink
fix: panic if usage is null in stream mode
Browse files Browse the repository at this point in the history
  • Loading branch information
heimoshuiyu committed Feb 20, 2025
1 parent c03dbef commit e4919bb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pages/Chatbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,14 @@ export default function ChatBOX() {
audio: null,
logprobs,
response_model_name,
usage,
usage: usage ?? {
prompt_tokens: prompt_tokens,
completion_tokens: responseTokenCount,
total_tokens: prompt_tokens + responseTokenCount,
response_model_name: response_model_name,
prompt_tokens_details: null,
completion_tokens_details: null,
},
response_count: responseTokenCount,
};
if (allChunkTool.length > 0) newMsg.tool_calls = allChunkTool;
Expand Down Expand Up @@ -293,7 +300,7 @@ export default function ChatBOX() {
token: data.usage?.completion_tokens_details
? data.usage.completion_tokens -
data.usage.completion_tokens_details.reasoning_tokens
: (data.usage.completion_tokens ?? calculate_token_length(msg.content)),
: data.usage.completion_tokens ?? calculate_token_length(msg.content),
example: false,
audio: null,
logprobs: data.choices[0]?.logprobs,
Expand Down

0 comments on commit e4919bb

Please sign in to comment.