mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 07:04:45 +00:00
fix(ai): preserve mistral thinking replay
This commit is contained in:
parent
eb9f1183ad
commit
4c175790b1
1 changed files with 10 additions and 5 deletions
|
|
@ -465,17 +465,22 @@ function toChatMessages(messages: Message[], supportsImages: boolean): ChatCompl
|
|||
}
|
||||
|
||||
if (msg.role === "assistant") {
|
||||
const textParts: Array<{ type: "text"; text: string }> = [];
|
||||
const contentParts: ContentChunk[] = [];
|
||||
const toolCalls: Array<{ id: string; type: "function"; function: { name: string; arguments: string } }> = [];
|
||||
|
||||
for (const block of msg.content) {
|
||||
if (block.type === "text") {
|
||||
if (block.text.trim().length > 0) textParts.push({ type: "text", text: sanitizeSurrogates(block.text) });
|
||||
if (block.text.trim().length > 0) {
|
||||
contentParts.push({ type: "text", text: sanitizeSurrogates(block.text) });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (block.type === "thinking") {
|
||||
if (block.thinking.trim().length > 0) {
|
||||
textParts.push({ type: "text", text: sanitizeSurrogates(block.thinking) });
|
||||
contentParts.push({
|
||||
type: "thinking",
|
||||
thinking: [{ type: "text", text: sanitizeSurrogates(block.thinking) }],
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -487,9 +492,9 @@ function toChatMessages(messages: Message[], supportsImages: boolean): ChatCompl
|
|||
}
|
||||
|
||||
const assistantMessage: ChatCompletionStreamRequestMessages = { role: "assistant" };
|
||||
if (textParts.length > 0) assistantMessage.content = textParts;
|
||||
if (contentParts.length > 0) assistantMessage.content = contentParts;
|
||||
if (toolCalls.length > 0) assistantMessage.toolCalls = toolCalls;
|
||||
if (textParts.length > 0 || toolCalls.length > 0) result.push(assistantMessage);
|
||||
if (contentParts.length > 0 || toolCalls.length > 0) result.push(assistantMessage);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue