fix: 当LTM provider未设置时,回退到全局图片转述模型配置#7719
Open
Blueteemo wants to merge 4 commits intoAstrBotDevs:masterfrom
Open
fix: 当LTM provider未设置时,回退到全局图片转述模型配置#7719Blueteemo wants to merge 4 commits intoAstrBotDevs:masterfrom
Blueteemo wants to merge 4 commits intoAstrBotDevs:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
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 aKeyErrorifprovider_settingsis missing from the configuration. - The condition
if not image_caption_provider_idnow mixesNone, empty string, and other falsy values; if only unset/empty cases should fall back to the default, consider normalizing or explicitly checking forNone/""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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Bug Fixes: