Skip to content

fix: 忽略 Gemini “返回内容为空”的错误消息,将 OpenAI 和 Gemini 的此类消息以 info 级别输出在控制台上。 #2324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MCjiaozi
Copy link
Contributor

@MCjiaozi MCjiaozi commented Aug 5, 2025

此 PR 与 #2279 同类

Motivation

#2279 仅解决了 OpenAI 提供商的此类问题,此 PR 解决 Gemini 的空消息返回问题。
未对其他供应商做出相应更改是因为尚未测试其他供应商的模型。

Modifications

  • raise Exception("API 返回的内容为空。")改为logger.debug("API 可能返回了空消息。"),避免输出到消息平台
  • 添加了logger.debug作为控制台提示。

Check

  • 😊 我的 Commit Message 符合良好的规范
  • 👀 我的更改经过良好的测试
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。
  • 😮 我的更改没有引入恶意代码

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 @MCjiaozi - 我已经审阅了你的更改 - 以下是一些反馈:

  • 空响应处理逻辑在不同提供者之间重复;考虑将其提取到共享的帮助函数中以避免冗余。
  • 与其记录空的 result_parts 并继续执行,你可能希望提前返回一个空的 MessageChain 以提高清晰度。
  • 考虑使用较低的日志级别 (debug) 或使空响应日志可配置,因为信息日志可能会使生产输出变得混乱。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Empty response handling logic is duplicated across providers; consider extracting it into a shared helper to avoid redundancy.
- Rather than logging an empty `result_parts` and falling through, you may want to early-return an empty `MessageChain` for clarity.
- Consider using a lower log level (debug) or making the empty-response logs configurable, as info logs might clutter production output.

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.
Original comment in English

Hey @MCjiaozi - I've reviewed your changes - here's some feedback:

  • Empty response handling logic is duplicated across providers; consider extracting it into a shared helper to avoid redundancy.
  • Rather than logging an empty result_parts and falling through, you may want to early-return an empty MessageChain for clarity.
  • Consider using a lower log level (debug) or making the empty-response logs configurable, as info logs might clutter production output.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Empty response handling logic is duplicated across providers; consider extracting it into a shared helper to avoid redundancy.
- Rather than logging an empty `result_parts` and falling through, you may want to early-return an empty `MessageChain` for clarity.
- Consider using a lower log level (debug) or making the empty-response logs configurable, as info logs might clutter production output.

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.

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.

1 participant