From 723d094ba2e655f97361061867403b8ef6ed9ab7 Mon Sep 17 00:00:00 2001 From: oilbeater Date: Tue, 15 Oct 2024 16:09:59 +0800 Subject: [PATCH] update deepseek usage Signed-off-by: oilbeater --- src/providers/deepseek.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/providers/deepseek.ts b/src/providers/deepseek.ts index 4799c6c..cd7b3ed 100644 --- a/src/providers/deepseek.ts +++ b/src/providers/deepseek.ts @@ -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 }; } } }