fix(gemini_client): 优化消息转换逻辑并改进错误提示#1522
Conversation
- 将系统角色消息的错误提示改为更友好的中文描述 - 添加对 Tool 角色消息的调试日志说明暂不支持 - 实现过滤空 parts 的 Content 对象以避免 API 错误 (Mai-with-u#1494) - 添加转换后内容为空的验证,确保满足 Gemini API 要求 - 保持原有返回值结构不变
There was a problem hiding this comment.
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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
main分支 禁止修改,请确认本次提交的分支 不是main分支修复 Gemini 客户端
_convert_messages函数的问题:parts为空的Content对象,避免Gemini API报错contents为空时,抛出清晰的ValueError而非让请求到达API后报错其他信息