Handle thinking by reasoning models. Show in train of thought on web client

This commit is contained in:
Debanjum
2025-05-02 06:41:50 -06:00
parent d10dcc83d4
commit 16f3c85dde
6 changed files with 69 additions and 26 deletions

View File

@@ -97,6 +97,17 @@ export function processMessageChunk(
console.log(`status: ${chunk.data}`);
const statusMessage = chunk.data as string;
currentMessage.trainOfThought.push(statusMessage);
} else if (chunk.type === "thought") {
const thoughtChunk = chunk.data as string;
const lastThoughtIndex = currentMessage.trainOfThought.length - 1;
const previousThought =
lastThoughtIndex >= 0 ? currentMessage.trainOfThought[lastThoughtIndex] : "";
// If the last train of thought started with "Thinking: " append the new thought chunk to it
if (previousThought.startsWith("**Thinking:** ")) {
currentMessage.trainOfThought[lastThoughtIndex] += thoughtChunk;
} else {
currentMessage.trainOfThought.push(`**Thinking:** ${thoughtChunk}`);
}
} else if (chunk.type === "references") {
const references = chunk.data as RawReferenceData;