From c03dbef7983bbc56ad10c9358dfd5241a4ff7632 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Sat, 8 Feb 2025 14:25:12 +0800 Subject: [PATCH] add response count to ChatStoreMessage and update message creation --- src/pages/Chatbox.tsx | 15 +++++++++++---- src/types/chatstore.ts | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pages/Chatbox.tsx b/src/pages/Chatbox.tsx index 9fd81cf..f1d2985 100644 --- a/src/pages/Chatbox.tsx +++ b/src/pages/Chatbox.tsx @@ -45,7 +45,8 @@ import { ImageGenDrawer } from "@/components/ImageGenDrawer"; const createMessageFromCurrentBuffer = ( chunkMessages: string[], reasoningChunks: string[], - tools: ToolCall[] + tools: ToolCall[], + response_count: number ): ChatStoreMessage => { return { role: "assistant", @@ -62,6 +63,7 @@ const createMessageFromCurrentBuffer = ( logprobs: null, response_model_name: null, usage: null, + response_count, }; }; @@ -184,7 +186,10 @@ export default function ChatBOX() { allChunkMessage.join("") + allChunkTool.map((tool) => { return `Tool Call ID: ${tool.id}\nType: ${tool.type}\nFunction: ${tool.function.name}\nArguments: ${tool.function.arguments}`; - }) + }) + + "\n" + + responseTokenCount + + " response count" ); } } catch (e: any) { @@ -194,7 +199,8 @@ export default function ChatBOX() { const partialMsg = createMessageFromCurrentBuffer( allChunkMessage, allReasoningContentChunk, - allChunkTool + allChunkTool, + responseTokenCount ); chatStore.history.push(partialMsg); setChatStore({ ...chatStore }); @@ -255,6 +261,7 @@ export default function ChatBOX() { logprobs, response_model_name, usage, + response_count: responseTokenCount, }; if (allChunkTool.length > 0) newMsg.tool_calls = allChunkTool; @@ -286,7 +293,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, diff --git a/src/types/chatstore.ts b/src/types/chatstore.ts index d795a93..893f833 100644 --- a/src/types/chatstore.ts +++ b/src/types/chatstore.ts @@ -76,6 +76,7 @@ export interface ChatStoreMessage { created_at?: string; responsed_at?: string; completed_at?: string; + response_count?: number; role: "system" | "user" | "assistant" | "tool"; content: string | MessageDetail[];