mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
fix(aiCore): omit empty content in assistant messages with tool_calls (#11818)
* fix(aiCore): omit empty content in assistant messages with tool_calls When an assistant message contains tool_calls but no text content, the content field was being set to undefined or empty string. This caused API errors on strict OpenAI-compatible endpoints like CherryIn: "messages: text content blocks must be non-empty" The fix conditionally includes the content field only when there is actual text content, which conforms to the OpenAI API specification. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(aiCore): omit empty assistant message in new aiCore StreamEventManager When building recursive params after tool execution, only add the assistant message when textBuffer has content. This avoids sending empty/invalid assistant messages to strict OpenAI-compatible APIs like CherryIn, which causes "text content blocks must be non-empty" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * revert: remove legacy OpenAIApiClient fix (legacy is deprecated) The legacy aiCore code is no longer used. Only the fix in the new aiCore architecture (StreamEventManager.ts) is needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6df60a69c3
commit
711f805a5b
@ -135,10 +135,8 @@ export class StreamEventManager {
|
||||
// 构建新的对话消息
|
||||
const newMessages: ModelMessage[] = [
|
||||
...(context.originalParams.messages || []),
|
||||
{
|
||||
role: 'assistant',
|
||||
content: textBuffer
|
||||
},
|
||||
// 只有当 textBuffer 有内容时才添加 assistant 消息,避免空消息导致 API 错误
|
||||
...(textBuffer ? [{ role: 'assistant' as const, content: textBuffer }] : []),
|
||||
{
|
||||
role: 'user',
|
||||
content: toolResultsText
|
||||
|
||||
Loading…
Reference in New Issue
Block a user