Skip to content

Commit

Permalink
update deepseek usage
Browse files Browse the repository at this point in the history
Signed-off-by: oilbeater <[email protected]>
  • Loading branch information
oilbeater committed Oct 15, 2024
1 parent cf44c66 commit 723d094
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/providers/deepseek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ function getTokenCount(c: Context): { input_tokens: number, output_tokens: numbe
const output = buf.trim().split('\n\n').at(-2);
if (output && output.startsWith('data: ')) {
const usage_message = JSON.parse(output.slice('data: '.length));
return {
input_tokens: usage_message.usage.prompt_tokens || 0,
if ('usage' in usage_message) {
return {
input_tokens: usage_message.usage.prompt_tokens || 0,
output_tokens: usage_message.usage.completion_tokens || 0
};
};
}
return { input_tokens: 0, output_tokens: 0 };
}
}
}
Expand Down

0 comments on commit 723d094

Please sign in to comment.