An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
fix: keep reasoning in pruneMessages for OpenAI compatibility (#763)
Yoshiki Miurabed773d4ecb0
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.tsindex 960e37fe..29dd4360 100644--- a/lib/streaming/create-chat-stream-response.ts+++ b/lib/streaming/create-chat-stream-response.ts@@ -138,11 +138,13 @@ export async function createChatStreamResponse(// Convert to model messages and apply context window managementlet modelMessages = await convertToModelMessages(messagesToModel)- // Prune messages to remove unnecessary reasoning, tool calls, and empty messages+ // Prune messages to remove unnecessary tool calls and empty messages// This reduces token usage while keeping recent context+ // Note: reasoning is kept ('none') for OpenAI reasoning model compatibility+ // (removing reasoning without its paired tool-call causes API errors)modelMessages = pruneMessages({messages: modelMessages,- reasoning: 'before-last-message', // Keep reasoning in last message for LLM context+ reasoning: 'none', // Keep all reasoning for OpenAI compatibilitytoolCalls: 'before-last-2-messages', // Keep recent tool calls (last 2 messages)emptyMessages: 'remove' // Remove messages that become empty after pruning})