(
provider_id: str,
cfg: dict,
image_urls: list[str],
plugin_context: Context,
)
| 618 | |
| 619 | |
| 620 | async def _request_img_caption( |
| 621 | provider_id: str, |
| 622 | cfg: dict, |
| 623 | image_urls: list[str], |
| 624 | plugin_context: Context, |
| 625 | ) -> str: |
| 626 | prov = plugin_context.get_provider_by_id(provider_id) |
| 627 | if prov is None: |
| 628 | raise ValueError( |
| 629 | f"Cannot get image caption because provider `{provider_id}` is not exist.", |
| 630 | ) |
| 631 | if not isinstance(prov, Provider): |
| 632 | raise ValueError( |
| 633 | f"Cannot get image caption because provider `{provider_id}` is not a valid Provider, it is {type(prov)}.", |
| 634 | ) |
| 635 | |
| 636 | img_cap_prompt = cfg.get( |
| 637 | "image_caption_prompt", |
| 638 | "Please describe the image.", |
| 639 | ) |
| 640 | logger.debug("Processing image caption with provider: %s", provider_id) |
| 641 | llm_resp = await prov.text_chat( |
| 642 | prompt=img_cap_prompt, |
| 643 | image_urls=image_urls, |
| 644 | ) |
| 645 | return llm_resp.completion_text |
| 646 | |
| 647 | |
| 648 | async def _ensure_img_caption( |
no test coverage detected