Skip to content

Conversation

@wangyingxuan383-ai
Copy link

@wangyingxuan383-ai wangyingxuan383-ai commented Jan 16, 2026

修复 openai 兼容提供商在 assistant content 为数组时导致的上下文丢失问题(下游 OpenAI→Gemini 转换会忽略数组内容,导致复读)。

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

  • astrbot/core/provider/sources/openai_source.py_finally_convert_payload 中,
    当 assistant 的 content 为 list 且仅包含 text(剔除 think 后)时,合并为 string;
    若存在非 text 内容,则保留 list(多模态兼容)。

Screenshots or Test Results / 运行截图或测试结果

复现步骤(修复前):

  1. openai_chat_completion 提供商指向 OpenAI 兼容网关(如 CLIProxyAPI)
  2. 连续输入 A/B/C
  3. B 回复重复 A,C 回复重复 A+B

修复后:assistant 历史保留,B/C 不再复读。


Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

错误修复:

  • 修复当助手内容为数组时导致助手上下文丢失的问题:通过将纯文本部分扁平化为单个字符串,同时保留非文本部分,以保持多模态兼容性。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Fix loss of assistant context when assistant content is an array by flattening pure-text parts into a single string while retaining non-text parts for multimodal compatibility.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 16, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些高层次的反馈:

  • 当所有非 think 部分都是文本,但其中一些 text 字段缺失或为 None 时,它们会被静默转换为空字符串;建议显式跳过这些部分或记录日志,以避免内容在不经意间丢失。
  • 如果 content 列表只包含 think 部分,message["content"] 会变成空字符串而不是空列表;请仔细检查下游使用方在这种边界情况下是否期望得到字符串,或者为了保持一致性,考虑保留列表类型。
给 AI 代理的提示词
Please address the comments from this code review:

## Overall Comments
- When all non-`think` parts are text but some `text` fields are missing or `None`, they are silently converted to empty strings; consider explicitly skipping such parts or logging to avoid losing content unexpectedly.
- If the content list contains only `think` parts, `message["content"]` becomes an empty string rather than an empty list; double-check that downstream consumers expect a string in this edge case, or preserve the list type for consistency.

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • When all non-think parts are text but some text fields are missing or None, they are silently converted to empty strings; consider explicitly skipping such parts or logging to avoid losing content unexpectedly.
  • If the content list contains only think parts, message["content"] becomes an empty string rather than an empty list; double-check that downstream consumers expect a string in this edge case, or preserve the list type for consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When all non-`think` parts are text but some `text` fields are missing or `None`, they are silently converted to empty strings; consider explicitly skipping such parts or logging to avoid losing content unexpectedly.
- If the content list contains only `think` parts, `message["content"]` becomes an empty string rather than an empty list; double-check that downstream consumers expect a string in this edge case, or preserve the list type for consistency.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. label Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant