fix(llm): flatten content array for OpenAI-compatible providers (#1222)
* fix(llm): flatten content array for OpenAI-compatible providers * fix(llm): improve type safety in sanitizeMessages * fix(stage-ui): add notice comment for message content flattening compatibility Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: Neko <neko@ayaka.moe> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
gemini-code-assist[bot]
Neko
parent
65faf3fe18
commit
0089040f2d
@@ -34,6 +34,16 @@ function sanitizeMessages(messages: unknown[]): Message[] {
|
||||
content: `User encountered error: ${String(m.content ?? '')}`,
|
||||
} as Message
|
||||
}
|
||||
// NOTICE: This block is critical for backward compatibility with LLM providers (e.g., DeepSeek)
|
||||
// that expect message content to be a string, not an array of content parts.
|
||||
// Failure to flatten array content (when no image_url is present) can lead to
|
||||
// deserialization errors like "invalid type: sequence, expected a string".
|
||||
if (m && Array.isArray(m.content)) {
|
||||
const contentParts = m.content as { type?: string, text?: string }[]
|
||||
if (!contentParts.some(p => p?.type === 'image_url')) {
|
||||
return { ...m, content: contentParts.map(p => p?.text ?? '').join('') } as Message
|
||||
}
|
||||
}
|
||||
return m as Message
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user