Capture model name only after first token (streaming) or completed request (#16405)

* feat: Capture model name only after first token (streaming) or completed request (non-streaming)

* chore: update webui build output

* chore: update webui build output
This commit is contained in:
Aleksander Grygier
2025-10-03 11:30:39 +02:00
committed by GitHub
parent e308efda8e
commit 77233277c9
2 changed files with 55 additions and 20 deletions

Binary file not shown.

View File

@@ -307,8 +307,30 @@ class ChatStore {
onError?: (error: Error) => void onError?: (error: Error) => void
): Promise<void> { ): Promise<void> {
let streamedContent = ''; let streamedContent = '';
let streamedReasoningContent = ''; let streamedReasoningContent = '';
let modelCaptured = false;
const captureModelIfNeeded = (updateDbImmediately = true): string | undefined => {
if (!modelCaptured) {
const currentModelName = serverStore.modelName;
if (currentModelName) {
if (updateDbImmediately) {
DatabaseStore.updateMessage(assistantMessage.id, { model: currentModelName }).catch(
console.error
);
}
const messageIndex = this.findMessageIndex(assistantMessage.id);
this.updateMessageAtIndex(messageIndex, { model: currentModelName });
modelCaptured = true;
return currentModelName;
}
}
return undefined;
};
slotsService.startStreaming(); slotsService.startStreaming();
@@ -319,6 +341,8 @@ class ChatStore {
streamedContent += chunk; streamedContent += chunk;
this.currentResponse = streamedContent; this.currentResponse = streamedContent;
captureModelIfNeeded();
const partialThinking = extractPartialThinking(streamedContent); const partialThinking = extractPartialThinking(streamedContent);
const messageIndex = this.findMessageIndex(assistantMessage.id); const messageIndex = this.findMessageIndex(assistantMessage.id);
this.updateMessageAtIndex(messageIndex, { this.updateMessageAtIndex(messageIndex, {
@@ -328,7 +352,11 @@ class ChatStore {
onReasoningChunk: (reasoningChunk: string) => { onReasoningChunk: (reasoningChunk: string) => {
streamedReasoningContent += reasoningChunk; streamedReasoningContent += reasoningChunk;
captureModelIfNeeded();
const messageIndex = this.findMessageIndex(assistantMessage.id); const messageIndex = this.findMessageIndex(assistantMessage.id);
this.updateMessageAtIndex(messageIndex, { thinking: streamedReasoningContent }); this.updateMessageAtIndex(messageIndex, { thinking: streamedReasoningContent });
}, },
@@ -339,17 +367,36 @@ class ChatStore {
) => { ) => {
slotsService.stopStreaming(); slotsService.stopStreaming();
await DatabaseStore.updateMessage(assistantMessage.id, { const updateData: {
content: string;
thinking: string;
timings?: ChatMessageTimings;
model?: string;
} = {
content: finalContent || streamedContent, content: finalContent || streamedContent,
thinking: reasoningContent || streamedReasoningContent, thinking: reasoningContent || streamedReasoningContent,
timings: timings timings: timings
}); };
const capturedModel = captureModelIfNeeded(false);
if (capturedModel) {
updateData.model = capturedModel;
}
await DatabaseStore.updateMessage(assistantMessage.id, updateData);
const messageIndex = this.findMessageIndex(assistantMessage.id); const messageIndex = this.findMessageIndex(assistantMessage.id);
this.updateMessageAtIndex(messageIndex, { const localUpdateData: { timings?: ChatMessageTimings; model?: string } = {
timings: timings timings: timings
}); };
if (updateData.model) {
localUpdateData.model = updateData.model;
}
this.updateMessageAtIndex(messageIndex, localUpdateData);
await DatabaseStore.updateCurrentNode(this.activeConversation!.id, assistantMessage.id); await DatabaseStore.updateCurrentNode(this.activeConversation!.id, assistantMessage.id);
this.activeConversation!.currNode = assistantMessage.id; this.activeConversation!.currNode = assistantMessage.id;
@@ -478,9 +525,6 @@ class ChatStore {
private async createAssistantMessage(parentId?: string): Promise<DatabaseMessage | null> { private async createAssistantMessage(parentId?: string): Promise<DatabaseMessage | null> {
if (!this.activeConversation) return null; if (!this.activeConversation) return null;
// Capture the current model name when creating the assistant message
const currentModelName = serverStore.modelName;
return await DatabaseStore.createMessageBranch( return await DatabaseStore.createMessageBranch(
{ {
convId: this.activeConversation.id, convId: this.activeConversation.id,
@@ -489,8 +533,7 @@ class ChatStore {
content: '', content: '',
timestamp: Date.now(), timestamp: Date.now(),
thinking: '', thinking: '',
children: [], children: []
model: currentModelName || undefined
}, },
parentId || null parentId || null
); );
@@ -1287,9 +1330,6 @@ class ChatStore {
this.isLoading = true; this.isLoading = true;
this.currentResponse = ''; this.currentResponse = '';
// Capture the current model name when creating the assistant message
const currentModelName = serverStore.modelName;
const newAssistantMessage = await DatabaseStore.createMessageBranch( const newAssistantMessage = await DatabaseStore.createMessageBranch(
{ {
convId: this.activeConversation.id, convId: this.activeConversation.id,
@@ -1298,8 +1338,7 @@ class ChatStore {
role: 'assistant', role: 'assistant',
content: '', content: '',
thinking: '', thinking: '',
children: [], children: []
model: currentModelName || undefined
}, },
parentMessage.id parentMessage.id
); );
@@ -1346,9 +1385,6 @@ class ChatStore {
false false
) as DatabaseMessage[]; ) as DatabaseMessage[];
// Capture the current model name when creating the assistant message
const currentModelName = serverStore.modelName;
// Create new assistant message branch // Create new assistant message branch
const assistantMessage = await DatabaseStore.createMessageBranch( const assistantMessage = await DatabaseStore.createMessageBranch(
{ {
@@ -1358,8 +1394,7 @@ class ChatStore {
role: 'assistant', role: 'assistant',
content: '', content: '',
thinking: '', thinking: '',
children: [], children: []
model: currentModelName || undefined
}, },
userMessageId userMessageId
); );