Skip to content

fix(gemini_client): 优化消息转换逻辑并改进错误提示#1522

Open
xiaoxiao-cvs wants to merge 1 commit intoMai-with-u:devfrom
xiaoxiao-cvs:fix/gemini-client-system-message-handling
Open

fix(gemini_client): 优化消息转换逻辑并改进错误提示#1522
xiaoxiao-cvs wants to merge 1 commit intoMai-with-u:devfrom
xiaoxiao-cvs:fix/gemini-client-system-message-handling

Conversation

@xiaoxiao-cvs
Copy link
Member

    • main 分支 禁止修改,请确认本次提交的分支 不是 main 分支
    • 我确认我阅读了贡献指南
    • 本次更新类型为:BUG修复
    • 本次更新类型为:功能新增
    • 本次更新是否经过测试
  1. 请填写破坏性更新的具体内容(如有): 无
  2. 请简要说明本次更新的内容和目的:

修复 Gemini 客户端 _convert_messages 函数的问题:

  • 将错误信息("你tm...")替换为正常信息(
  • 为被跳过的Tool角色消息添加debug日志提示
  • 过滤 parts 为空的Content对象,避免Gemini API报错
  • 仅含System消息导致 contents 为空时,抛出清晰的ValueError而非让请求到达API后报错

其他信息

image
  • 附加信息: 通过单元测试验证了修复,空 contents 校验、空 parts 过滤和正常对话回归

- 将系统角色消息的错误提示改为更友好的中文描述
- 添加对 Tool 角色消息的调试日志说明暂不支持
- 实现过滤空 parts 的 Content 对象以避免 API 错误 (Mai-with-u#1494)
- 添加转换后内容为空的验证,确保满足 Gemini API 要求
- 保持原有返回值结构不变
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes critical message conversion bugs in the Gemini client that caused API errors when handling system-only messages or messages with empty content. The changes improve error handling and add diagnostic logging to prevent Gemini API errors related to empty contents or parts fields.

Changes:

  • Replaced unprofessional error message with clear, descriptive text
  • Added debug logging for skipped Tool role messages
  • Implemented filtering to remove Content objects with empty parts arrays
  • Added validation to ensure contents list is never empty before API calls
  • Simplified return statement logic for better readability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants