fix: avoid duplicate quoted image captions#8718
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to prevent duplicate captioning of quoted images. It adds a skip_quote_image_caption flag to _process_quote_message and determines if quote images have already been captioned by checking for the presence of <image_caption> tags in the request's extra user content parts. A corresponding unit test has been added to verify this behavior. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| await _ensure_persona_and_skills(req, cfg, plugin_context, event) | ||
|
|
||
| img_cap_prov_id: str = cfg.get("default_image_caption_provider_id") or "" | ||
| quote_images_already_captioned = False |
There was a problem hiding this comment.
这里的quote_images_already_captioned和下面的else处的应当可以提到if前。
| break | ||
|
|
||
| if image_seg and main_provider_supports_image: | ||
| if image_seg and skip_quote_image_caption: |
There was a problem hiding this comment.
是否可以考虑下image_seg统一判断一下。
目前4个if挨个判断有点...
修复 #8708。
当引用消息里包含图片、且主对话模型不支持图片输入时,构建请求阶段会先把引用图片加入
req.image_urls,随后_ensure_img_caption()会统一生成<image_caption>。之后_process_quote_message()又会重新处理同一张引用图片,并生成[Image Caption in quoted message],导致同一图片被转述两次、也多调用一次图转述模型。这个改动在已经生成
<image_caption>的请求里跳过引用图片的第二次转述,只保留<Quoted Message>里的引用文本和附件上下文。主模型支持图片输入时的现有跳过逻辑保持不变;没有生成全局图片转述时,引用图片转述 fallback 仍然可用。验证:
python -m py_compile astrbot\core\astr_main_agent.py tests\unit\test_astr_main_agent.pypython -m ruff check astrbot\core\astr_main_agent.py tests\unit\test_astr_main_agent.pytests/unit/test_astr_main_agent.py -q→88 passed说明:当前 Python 环境里有另一个 editable checkout 把
AnyCoder/tests注册成了tests包,直接pytest会把 AstrBot 的tests.fixtures解析到错误位置;因此本地验证使用了隔离 runner,手动把本仓tests绑定到当前 worktree,并显式加载pytest_asyncio.plugin。Summary by Sourcery
Prevent duplicate caption generation for quoted images when a global image caption has already been created in main agent requests.
Bug Fixes:
Tests: