-
-
Notifications
You must be signed in to change notification settings - Fork 941
fix(LTM): 修复配置中LTM-自动理解图片功能无法关闭的问题 #3115
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
fix(LTM): 修复配置中LTM-自动理解图片功能无法关闭的问题 #3115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好 - 我已审阅了你的更改,它们看起来很棒!
AI 代理提示
请解决此代码审查中的评论:
## 独立评论
### 评论 1
<location> `packages/astrbot/long_term_memory.py:113` </location>
<code_context>
async def handle_message(self, event: AstrMessageEvent):
"""仅支持群聊"""
- if event.get_message_type() == MessageType.GROUP_MESSAGE:
+ if (event.get_message_type() == MessageType.GROUP_MESSAGE) or True:
datetime_str = datetime.datetime.now().strftime("%H:%M:%S")
</code_context>
<issue_to_address>
**问题 (bug_risk):** 该条件始终评估为 True,使得消息处理器变为无条件。
'or True' 子句导致此代码块对所有消息类型运行。如果这是为了调试,请明确标记或在合并前删除。否则,可能会导致意外处理。
</issue_to_address>
### 评论 2
<location> `packages/astrbot/long_term_memory.py:32` </location>
<code_context>
def cfg(self, event: AstrMessageEvent):
cfg = self.context.get_config(umo=event.unified_msg_origin)
try:
max_cnt = int(cfg["provider_ltm_settings"]["group_message_max_cnt"])
except BaseException as e:
logger.error(e)
max_cnt = 300
image_caption = (
True
if cfg["provider_settings"]["default_image_caption_provider_id"]
and cfg["provider_ltm_settings"]["image_caption"]
else False
)
image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"]
image_caption_provider_id = cfg["provider_settings"][
"default_image_caption_provider_id"
]
active_reply = cfg["provider_ltm_settings"]["active_reply"]
enable_active_reply = active_reply.get("enable", False)
ar_method = active_reply["method"]
ar_possibility = active_reply["possibility_reply"]
ar_prompt = active_reply.get("prompt", "")
ar_whitelist = active_reply.get("whitelist", [])
ret = {
"max_cnt": max_cnt,
"image_caption": image_caption,
"image_caption_prompt": image_caption_prompt,
"image_caption_provider_id": image_caption_provider_id,
"enable_active_reply": enable_active_reply,
"ar_method": ar_method,
"ar_possibility": ar_possibility,
"ar_prompt": ar_prompt,
"ar_whitelist": ar_whitelist,
}
return ret
</code_context>
<issue_to_address>
**问题 (code-quality):** 我们发现了以下问题:
- 简化布尔 if 表达式 ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- 内联立即返回的变量 ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/inline-immediately-returned-variable/))
</issue_to_address>
### 评论 3
<location> `packages/astrbot/long_term_memory.py:111` </location>
<code_context>
async def handle_message(self, event: AstrMessageEvent):
"""仅支持群聊"""
if (event.get_message_type() == MessageType.GROUP_MESSAGE) or True:
datetime_str = datetime.datetime.now().strftime("%H:%M:%S")
final_message = f"[{event.message_obj.sender.nickname}/{datetime_str}]: "
cfg = self.cfg(event);
for comp in event.get_messages():
if isinstance(comp, Plain):
final_message += f" {comp.text}"
elif isinstance(comp, Image):
if cfg["image_caption"]:
try:
caption = await self.get_image_caption(
comp.url if comp.url else comp.file,
cfg["image_caption_provider_id"],
cfg["image_caption_prompt"],
)
final_message += f" [Image: {caption}]"
except Exception as e:
logger.error(f"获取图片描述失败: {e}")
else:
final_message += " [Image]"
logger.debug(f"ltm | {event.unified_msg_origin} | {final_message}")
self.session_chats[event.unified_msg_origin].append(final_message)
if len(self.session_chats[event.unified_msg_origin]) > cfg["max_cnt"]:
self.session_chats[event.unified_msg_origin].pop(0)
</code_context>
<issue_to_address>
**问题 (code-quality):** 我们发现了以下问题:
- 添加守卫子句 ([`last-if-guard`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/last-if-guard/))
- 移除或传播冗余布尔表达式 ([`remove-redundant-boolean`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/remove-redundant-boolean/))
</issue_to_address>帮助我变得更有用!请对每条评论点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `packages/astrbot/long_term_memory.py:113` </location>
<code_context>
async def handle_message(self, event: AstrMessageEvent):
"""仅支持群聊"""
- if event.get_message_type() == MessageType.GROUP_MESSAGE:
+ if (event.get_message_type() == MessageType.GROUP_MESSAGE) or True:
datetime_str = datetime.datetime.now().strftime("%H:%M:%S")
</code_context>
<issue_to_address>
**issue (bug_risk):** The condition always evaluates to True, making the message handler unconditional.
The 'or True' clause causes this block to run for every message type. If this is for debugging, please mark it clearly or remove before merging. Otherwise, it may result in unintended processing.
</issue_to_address>
### Comment 2
<location> `packages/astrbot/long_term_memory.py:32` </location>
<code_context>
def cfg(self, event: AstrMessageEvent):
cfg = self.context.get_config(umo=event.unified_msg_origin)
try:
max_cnt = int(cfg["provider_ltm_settings"]["group_message_max_cnt"])
except BaseException as e:
logger.error(e)
max_cnt = 300
image_caption = (
True
if cfg["provider_settings"]["default_image_caption_provider_id"]
and cfg["provider_ltm_settings"]["image_caption"]
else False
)
image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"]
image_caption_provider_id = cfg["provider_settings"][
"default_image_caption_provider_id"
]
active_reply = cfg["provider_ltm_settings"]["active_reply"]
enable_active_reply = active_reply.get("enable", False)
ar_method = active_reply["method"]
ar_possibility = active_reply["possibility_reply"]
ar_prompt = active_reply.get("prompt", "")
ar_whitelist = active_reply.get("whitelist", [])
ret = {
"max_cnt": max_cnt,
"image_caption": image_caption,
"image_caption_prompt": image_caption_prompt,
"image_caption_provider_id": image_caption_provider_id,
"enable_active_reply": enable_active_reply,
"ar_method": ar_method,
"ar_possibility": ar_possibility,
"ar_prompt": ar_prompt,
"ar_whitelist": ar_whitelist,
}
return ret
</code_context>
<issue_to_address>
**issue (code-quality):** We've found these issues:
- Simplify boolean if expression ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/inline-immediately-returned-variable/))
</issue_to_address>
### Comment 3
<location> `packages/astrbot/long_term_memory.py:111` </location>
<code_context>
async def handle_message(self, event: AstrMessageEvent):
"""仅支持群聊"""
if (event.get_message_type() == MessageType.GROUP_MESSAGE) or True:
datetime_str = datetime.datetime.now().strftime("%H:%M:%S")
final_message = f"[{event.message_obj.sender.nickname}/{datetime_str}]: "
cfg = self.cfg(event)
for comp in event.get_messages():
if isinstance(comp, Plain):
final_message += f" {comp.text}"
elif isinstance(comp, Image):
if cfg["image_caption"]:
try:
caption = await self.get_image_caption(
comp.url if comp.url else comp.file,
cfg["image_caption_provider_id"],
cfg["image_caption_prompt"],
)
final_message += f" [Image: {caption}]"
except Exception as e:
logger.error(f"获取图片描述失败: {e}")
else:
final_message += " [Image]"
logger.debug(f"ltm | {event.unified_msg_origin} | {final_message}")
self.session_chats[event.unified_msg_origin].append(final_message)
if len(self.session_chats[event.unified_msg_origin]) > cfg["max_cnt"]:
self.session_chats[event.unified_msg_origin].pop(0)
</code_context>
<issue_to_address>
**issue (code-quality):** We've found these issues:
- Add guard clause ([`last-if-guard`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/last-if-guard/))
- Removes or propagates redundant boolean expressions ([`remove-redundant-boolean`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/remove-redundant-boolean/))
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
使能配置项目,合并8d4c176中的判断逻辑,实现在禁用开关或无提示词时自动禁用。 (Force push because of mistake commit) AstrBotDevs#3112
d300b4f to
fc96721
Compare
|
#3106 中代码未格式化导致格式检查不通过。 |
|
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗨 - 我已经审阅了你的更改,它们看起来很棒!
AI 代理提示
请解决此代码审查中的注释:
## 单独评论
### 评论 1
<location> `packages/astrbot/long_term_memory.py:32` </location>
<code_context>
def cfg(self, event: AstrMessageEvent):
cfg = self.context.get_config(umo=event.unified_msg_origin)
try:
max_cnt = int(cfg["provider_ltm_settings"]["group_message_max_cnt"])
except BaseException as e:
logger.error(e)
max_cnt = 300
image_caption = (
True
if cfg["provider_settings"]["default_image_caption_provider_id"]
and cfg["provider_ltm_settings"]["image_caption"]
else False
)
image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"]
image_caption_provider_id = cfg["provider_settings"][
"default_image_caption_provider_id"
]
active_reply = cfg["provider_ltm_settings"]["active_reply"]
enable_active_reply = active_reply.get("enable", False)
ar_method = active_reply["method"]
ar_possibility = active_reply["possibility_reply"]
ar_prompt = active_reply.get("prompt", "")
ar_whitelist = active_reply.get("whitelist", [])
ret = {
"max_cnt": max_cnt,
"image_caption": image_caption,
"image_caption_prompt": image_caption_prompt,
"image_caption_provider_id": image_caption_provider_id,
"enable_active_reply": enable_active_reply,
"ar_method": ar_method,
"ar_possibility": ar_possibility,
"ar_prompt": ar_prompt,
"ar_whitelist": ar_whitelist,
}
return ret
</code_context>
<issue_to_address>
**issue (code-quality):** 我们发现了这些问题:
- 简化布尔 if 表达式 ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- 内联立即返回的变量 ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/inline-immediately-returned-variable/))
</issue_to_address>请帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将利用这些反馈来改进你的评论。
Original comment in English
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `packages/astrbot/long_term_memory.py:32` </location>
<code_context>
def cfg(self, event: AstrMessageEvent):
cfg = self.context.get_config(umo=event.unified_msg_origin)
try:
max_cnt = int(cfg["provider_ltm_settings"]["group_message_max_cnt"])
except BaseException as e:
logger.error(e)
max_cnt = 300
image_caption = (
True
if cfg["provider_settings"]["default_image_caption_provider_id"]
and cfg["provider_ltm_settings"]["image_caption"]
else False
)
image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"]
image_caption_provider_id = cfg["provider_settings"][
"default_image_caption_provider_id"
]
active_reply = cfg["provider_ltm_settings"]["active_reply"]
enable_active_reply = active_reply.get("enable", False)
ar_method = active_reply["method"]
ar_possibility = active_reply["possibility_reply"]
ar_prompt = active_reply.get("prompt", "")
ar_whitelist = active_reply.get("whitelist", [])
ret = {
"max_cnt": max_cnt,
"image_caption": image_caption,
"image_caption_prompt": image_caption_prompt,
"image_caption_provider_id": image_caption_provider_id,
"enable_active_reply": enable_active_reply,
"ar_method": ar_method,
"ar_possibility": ar_possibility,
"ar_prompt": ar_prompt,
"ar_whitelist": ar_whitelist,
}
return ret
</code_context>
<issue_to_address>
**issue (code-quality):** We've found these issues:
- Simplify boolean if expression ([`boolean-if-exp-identity`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/boolean-if-exp-identity/))
- Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/inline-immediately-returned-variable/))
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
项目加了pre-commit,提交前自动格式化, |
格式化 astrbot/dashboard/routes/update.py
a0f8f3a 完成了这项工作。
|
a0f8f3a 中格式化了代码。撤销此提交中的格式化部分。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr很简短,清晰
|
这个 bug 我已经在 8afefad 已经修复,抱歉之前没看到这个 PR。 |
|
乐 |
fixes #3112
Motivation / 动机
修复配置中LTM-自动理解图片功能无法关闭,在实际使用中一直启用的问题。
Modifications / 改动点
使能配置项目,合并8d4c176中的判断逻辑,实现在禁用开关或无提示词时自动禁用。
Verification Steps / 验证步骤
开启LTM,关闭自动理解图片。
在群聊中发送图片。
观察LTM是否不再调用LLM。
Screenshots or Test Results / 运行截图或测试结果
Compatibility & Breaking Changes / 兼容性与破坏性变更
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Sourcery 总结
修复 LTM 自动图像理解功能,以尊重用户的禁用设置,并确保它仅在提供了相应的提示和标志时才激活。
错误修复:
image_caption配置标志和提示的存在。改进:
handle_message条件,以一致地应用更新后的配置逻辑。Original summary in English
Sourcery 总结
修复长期记忆中的自动图片理解功能,使其正确遵守用户禁用设置,并且仅在提供者和提示都已配置时才激活。
Bug 修复:
image_caption标志来允许禁用自动图片理解增强功能:
handle_message条件逻辑,以一致地应用更新后的image_caption配置Original summary in English
Summary by Sourcery
Fix the automatic image understanding feature in long-term memory to correctly respect user disable settings and only activate when both the provider and prompt are configured.
Bug Fixes:
Enhancements: