Skip to content

fix: 当LTM provider未设置时,回退到全局图片转述模型配置#7719

Open
Blueteemo wants to merge 4 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7711-image-caption-fallback
Open

fix: 当LTM provider未设置时,回退到全局图片转述模型配置#7719
Blueteemo wants to merge 4 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7711-image-caption-fallback

Conversation

@Blueteemo
Copy link
Copy Markdown
Contributor

@Blueteemo Blueteemo commented Apr 22, 2026

Summary by Sourcery

Bug Fixes:

  • Ensure image captioning uses the default provider when no explicit image_caption_provider_id is set, avoiding failures due to missing provider configuration.

@auto-assign auto-assign Bot requested review from Fridemn and LIghtJUNction April 22, 2026 03:34
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Apr 22, 2026
Copy link
Copy Markdown
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 - I've found 1 issue, and left some high level feedback:

  • When reading self.ctx.astrbot_config["provider_settings"], consider using .get("provider_settings", {}) to avoid a KeyError if provider_settings is missing from the configuration.
  • The condition if not image_caption_provider_id now mixes None, empty string, and other falsy values; if only unset/empty cases should fall back to the default, consider normalizing or explicitly checking for None/"" to avoid surprising behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When reading `self.ctx.astrbot_config["provider_settings"]`, consider using `.get("provider_settings", {})` to avoid a `KeyError` if `provider_settings` is missing from the configuration.
- The condition `if not image_caption_provider_id` now mixes `None`, empty string, and other falsy values; if only unset/empty cases should fall back to the default, consider normalizing or explicitly checking for `None`/`""` to avoid surprising behavior.

## Individual Comments

### Comment 1
<location path="astrbot/builtin_stars/astrbot/long_term_memory.py" line_range="72-73" />
<code_context>
         image_caption_provider_id: str,
         image_caption_prompt: str,
     ) -> str:
+        if not image_caption_provider_id:
+            image_caption_provider_id = self.ctx.astrbot_config["provider_settings"].get(
+                "default_image_caption_provider_id"
+            )
</code_context>
<issue_to_address>
**issue:** Guard against missing `provider_settings` key when reading from `astrbot_config`.

Directly indexing `self.ctx.astrbot_config["provider_settings"]` will raise a `KeyError` if that section is absent in partially initialized or customized configs. Use a safe default, e.g. `self.ctx.astrbot_config.get("provider_settings", {})`, before calling `.get("default_image_caption_provider_id")`.
</issue_to_address>

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.

Comment thread astrbot/builtin_stars/astrbot/long_term_memory.py Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fallback mechanism to retrieve a default image caption provider ID from the configuration when it is not explicitly provided. However, the implementation contains a critical AttributeError as it attempts to access undefined attributes self.ctx and self.astrbot_config instead of using self.context.get_config(). Furthermore, the new logic is currently unreachable due to existing constraints in the cfg() method, and feedback suggests refactoring the code for better reuse and adding unit tests to verify the behavior.

Comment thread astrbot/builtin_stars/astrbot/long_term_memory.py Outdated
@Blueteemo Blueteemo changed the title fix: fallback to default_image_caption_provider_id when LTM provider not set fix: 图片转述模型回退到全局配置当LTM provider未设置时 Apr 22, 2026
@Blueteemo Blueteemo changed the title fix: 图片转述模型回退到全局配置当LTM provider未设置时 fix: 当LTM provider未设置时,回退到全局图片转述模型配置 Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant