add response count to ChatStoreMessage and update message creation

This commit is contained in:
2025-02-08 14:25:12 +08:00
parent 8cd43bec72
commit c03dbef798
2 changed files with 12 additions and 4 deletions

View File

@@ -45,7 +45,8 @@ import { ImageGenDrawer } from "@/components/ImageGenDrawer";
const createMessageFromCurrentBuffer = ( const createMessageFromCurrentBuffer = (
chunkMessages: string[], chunkMessages: string[],
reasoningChunks: string[], reasoningChunks: string[],
tools: ToolCall[] tools: ToolCall[],
response_count: number
): ChatStoreMessage => { ): ChatStoreMessage => {
return { return {
role: "assistant", role: "assistant",
@@ -62,6 +63,7 @@ const createMessageFromCurrentBuffer = (
logprobs: null, logprobs: null,
response_model_name: null, response_model_name: null,
usage: null, usage: null,
response_count,
}; };
}; };
@@ -184,7 +186,10 @@ export default function ChatBOX() {
allChunkMessage.join("") + allChunkMessage.join("") +
allChunkTool.map((tool) => { allChunkTool.map((tool) => {
return `Tool Call ID: ${tool.id}\nType: ${tool.type}\nFunction: ${tool.function.name}\nArguments: ${tool.function.arguments}`; return `Tool Call ID: ${tool.id}\nType: ${tool.type}\nFunction: ${tool.function.name}\nArguments: ${tool.function.arguments}`;
}) }) +
"\n" +
responseTokenCount +
" response count"
); );
} }
} catch (e: any) { } catch (e: any) {
@@ -194,7 +199,8 @@ export default function ChatBOX() {
const partialMsg = createMessageFromCurrentBuffer( const partialMsg = createMessageFromCurrentBuffer(
allChunkMessage, allChunkMessage,
allReasoningContentChunk, allReasoningContentChunk,
allChunkTool allChunkTool,
responseTokenCount
); );
chatStore.history.push(partialMsg); chatStore.history.push(partialMsg);
setChatStore({ ...chatStore }); setChatStore({ ...chatStore });
@@ -255,6 +261,7 @@ export default function ChatBOX() {
logprobs, logprobs,
response_model_name, response_model_name,
usage, usage,
response_count: responseTokenCount,
}; };
if (allChunkTool.length > 0) newMsg.tool_calls = allChunkTool; if (allChunkTool.length > 0) newMsg.tool_calls = allChunkTool;
@@ -286,7 +293,7 @@ export default function ChatBOX() {
token: data.usage?.completion_tokens_details token: data.usage?.completion_tokens_details
? data.usage.completion_tokens - ? data.usage.completion_tokens -
data.usage.completion_tokens_details.reasoning_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, example: false,
audio: null, audio: null,
logprobs: data.choices[0]?.logprobs, logprobs: data.choices[0]?.logprobs,

View File

@@ -76,6 +76,7 @@ export interface ChatStoreMessage {
created_at?: string; created_at?: string;
responsed_at?: string; responsed_at?: string;
completed_at?: string; completed_at?: string;
response_count?: number;
role: "system" | "user" | "assistant" | "tool"; role: "system" | "user" | "assistant" | "tool";
content: string | MessageDetail[]; content: string | MessageDetail[];