-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(imageCaption): 根据模型能力判断是否需要标注图片,而不是全部标注。 #3849
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,18 @@ async def _request_img_caption( | |
| f"Cannot get image caption because provider `{provider_id}` is not exist.", | ||
| ) | ||
|
|
||
| def _select_provider(self, event: AstrMessageEvent): | ||
| """选择使用的 LLM 提供商""" | ||
| sel_provider = event.get_extra("selected_provider") | ||
| _ctx = self.ctx | ||
| if sel_provider and isinstance(sel_provider, str): | ||
| provider = _ctx.get_provider_by_id(sel_provider) | ||
| if not provider: | ||
| logger.error(f"未找到指定的提供商: {sel_provider}。") | ||
| return provider | ||
|
|
||
| return _ctx.get_using_provider(umo=event.unified_msg_origin) | ||
|
|
||
| async def process_llm_request(self, event: AstrMessageEvent, req: ProviderRequest): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): 我们发现了以下问题:
Explanation该函数的质量评分低于 25% 的质量阈值。 如何改进? 你可以考虑对这个函数进行重构,使其更短、更易读。
Original comment in Englishissue (code-quality): We've found these issues:
ExplanationThe quality score for this function is below the quality threshold of 25%. How can you solve this? It might be worth refactoring this function to make it shorter and more readable.
|
||
| """在请求 LLM 前注入人格信息、Identifier、时间、回复内容等 System Prompt""" | ||
| cfg: dict = self.ctx.get_config(umo=event.unified_msg_origin)[ | ||
|
|
@@ -165,7 +177,14 @@ async def process_llm_request(self, event: AstrMessageEvent, req: ProviderReques | |
| await self._ensure_persona(req, cfg, event.unified_msg_origin) | ||
|
|
||
| # image caption | ||
| if img_cap_prov_id and req.image_urls: | ||
| if ( | ||
| img_cap_prov_id | ||
| and req.image_urls | ||
| and "image" | ||
| not in self._select_provider(event).provider_config.get( | ||
| "modalities", ["image"] | ||
| ) | ||
| ): | ||
| await self._ensure_img_caption(req, cfg, img_cap_prov_id) | ||
|
|
||
| # quote message processing | ||
|
|
||
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.
issue (bug_risk): 当选定的 provider ID 无效时,
_select_provider返回None而不是回退到默认 provider,这可能会导致下游错误。在
sel_provider分支中,如果get_provider_by_id返回None,你会记录一条错误日志但仍然返回None,这会在process_llm_request中访问.provider_config时引发异常。相应地,你可以在选定 provider 无效时回退到_ctx.get_using_provider(umo=event.unified_msg_origin),或者在这里抛出一个明确的错误并在调用方进行处理。这样可以避免当前这种“静默失败”的模式以及意料之外的None传递到下游。Original comment in English
issue (bug_risk): When a selected provider ID is invalid,
_select_providerreturnsNoneinstead of falling back to the default provider, which can cause downstream errors.In the
sel_providerbranch, ifget_provider_by_idreturnsNoneyou log an error but still returnNone, which will cause an exception inprocess_llm_requestwhen.provider_configis accessed. Instead, either fall back to_ctx.get_using_provider(umo=event.unified_msg_origin)when the selected provider is invalid, or raise an explicit error here and handle it at the call site. This avoids the current silent failure mode and unexpectedNonedownstream.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.
@Dt8333
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.
思考。
这个复制自astrbot\core\pipeline\process_stage\method\agent_sub_stages\internal.py
要改建议两个一起改(