MCPcopy
hub / github.com/AstrBotDevs/AstrBot / _ensure_img_caption

Function _ensure_img_caption

astrbot/core/astr_main_agent.py:648–677  ·  view source on GitHub ↗
(
    event: AstrMessageEvent,
    req: ProviderRequest,
    cfg: dict,
    plugin_context: Context,
    image_caption_provider: str,
)

Source from the content-addressed store, hash-verified

646
647
648async def _ensure_img_caption(
649 event: AstrMessageEvent,
650 req: ProviderRequest,
651 cfg: dict,
652 plugin_context: Context,
653 image_caption_provider: str,
654) -> None:
655 try:
656 compressed_urls = []
657 for url in req.image_urls:
658 compressed_url = await _compress_image_for_provider(url, cfg)
659 compressed_urls.append(compressed_url)
660 if _is_generated_compressed_image_path(url, compressed_url):
661 event.track_temporary_local_file(compressed_url)
662 caption = await _request_img_caption(
663 image_caption_provider,
664 cfg,
665 compressed_urls,
666 plugin_context,
667 )
668 if caption:
669 req.extra_user_content_parts.append(
670 TextPart(text=f"<image_caption>{caption}</image_caption>")
671 )
672 req.image_urls = []
673 except Exception as exc: # noqa: BLE001
674 logger.error("处理图片描述失败: %s", exc)
675 req.extra_user_content_parts.append(TextPart(text="[Image Captioning Failed]"))
676 finally:
677 req.image_urls = []
678
679
680def _append_quoted_image_attachment(req: ProviderRequest, image_path: str) -> None:

Callers 1

_decorate_llm_requestFunction · 0.85

Calls 7

TextPartClass · 0.90
_request_img_captionFunction · 0.85
appendMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected