| File was renamed from aigc-director/aigc-claw/backend/tool/vlm_client.py |
| | |
| | | import logging |
| | | import os |
| | | from typing import List, Optional |
| | | from config import Config |
| | | |
| | | try: |
| | | from tool.vlm_dashscope import QwenVLClient |
| | | from tool.vlm_gemini import GeminiVLClient |
| | | from tool.vlm_gpt import GPTVLClient |
| | | from models.vlm_dashscope import QwenVLClient |
| | | from models.vlm_gemini import GeminiVLClient |
| | | from models.vlm_gpt import GPTVLClient |
| | | except ImportError: |
| | | from vlm_dashscope import QwenVLClient |
| | | from vlm_gemini import GeminiVLClient |
| | | from vlm_gpt import GPTVLClient |
| | | |
| | | logger = logging.getLogger(__name__) |
| | | |
| | | |
| | | class VLM: |
| | | def __init__(self, |
| | |
| | | model: str = "qwen3.6-plus", |
| | | session_id: Optional[str] = None) -> str: |
| | | if Config.PRINT_MODEL_INPUT: |
| | | print("---- VLM REQUEST ----") |
| | | print(f"Prompt: {prompt}") |
| | | lines = [ |
| | | "---- VLM REQUEST ----", |
| | | f"Prompt: {prompt}", |
| | | ] |
| | | if image_paths: |
| | | print(f"Images: {len(image_paths)}") |
| | | lines.append(f"Images: {len(image_paths)}") |
| | | for p in image_paths: |
| | | if p.startswith("data:"): |
| | | print(f" - [Base64图片]") |
| | | else: |
| | | print(f" - {p}") |
| | | print(f"Model: {model}") |
| | | lines.append(" - [Base64图片]" if p.startswith("data:") else f" - {p}") |
| | | lines.append(f"Model: {model}") |
| | | if session_id: |
| | | print(f"Session ID: {session_id}") |
| | | print("-" * 30) |
| | | lines.append(f"Session ID: {session_id}") |
| | | lines.append("-" * 30) |
| | | logger.info("\n%s", "\n".join(lines)) |
| | | |
| | | # Determine backend provider |
| | | model_lower = model.lower() |
| | |
| | | abs_path = os.path.abspath(temp_path) |
| | | file_urls.append(f"file://{abs_path}") |
| | | except Exception as e: |
| | | print(f"Error processing base64 image: {e}") |
| | | logger.exception("Failed to process base64 image") |
| | | raise ValueError(f"无法解析 base64 图片: {e}") |
| | | elif p.startswith("http") or p.startswith("file://"): |
| | | file_urls.append(p) |
| | | else: |
| | | abs_path = os.path.abspath(p) |
| | | file_urls.append(f"file://{abs_path}") |
| | | return self.dashscope_client.chat(text=prompt, images=file_urls, model=model, stream=False) |
| | | return self.dashscope_client.chat(text=prompt, images=file_urls, model=model, stream=False) |