fix: flatten assistant content for openai payload#4497
Closed
wangyingxuan383-ai wants to merge 1 commit intoAstrBotDevs:masterfrom
Closed
fix: flatten assistant content for openai payload#4497wangyingxuan383-ai wants to merge 1 commit intoAstrBotDevs:masterfrom
wangyingxuan383-ai wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
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.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- When all non-
thinkparts are text but sometextfields are missing orNone, 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
thinkparts,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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 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 / 运行截图或测试结果
复现步骤(修复前):
修复后:assistant 历史保留,B/C 不再复读。
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: