Przeglądaj źródła

fix: 修复多模态 embedding API payload 格式

- input.texts → input.contents(符合 DashScope API 规范)
- 模型类型检测:vl/vision/multimodal 走多模态端点
- dimension 参数:多模态放 parameters 里,文本放根级别

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
mengboxin137-blip 8 godzin temu
rodzic
commit
010dfdb1b7
1 zmienionych plików z 7 dodań i 7 usunięć
  1. 7 7
      backend/app/services/openai_compat_service.py

+ 7 - 7
backend/app/services/openai_compat_service.py

@@ -1051,16 +1051,15 @@ class OpenAICompatService:
             else:
                 # 云端模型处理
                 # 根据模型类型选择端点:多模态 embedding vs 文本 embedding
-                is_multimodal = "multimodal" in model.model_code.lower()
+                # 多模态模型:名称含 vl/vision/multimodal
+                code_lower = model.model_code.lower()
+                is_multimodal = any(kw in code_lower for kw in ("vl", "vision", "multimodal"))
                 if is_multimodal:
                     api_url = "https://dashscope.aliyuncs.com/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding"
                     payload = {
                         "model": model.model_code,
                         "input": {
-                            "texts": texts
-                        },
-                        "parameters": {
-                            "text_type": "query"
+                            "contents": [{"text": t} for t in texts]
                         }
                     }
                 else:
@@ -1075,8 +1074,9 @@ class OpenAICompatService:
                     "Content-Type": "application/json",
                     "Authorization": f"Bearer {effective_api_key}"
                 }
-                if request.dimensions:
-                    payload["parameters"]["dimension"] = request.dimensions
+                # 多模态 embedding 的 dimension 放在 parameters 里
+                if is_multimodal and request.dimensions:
+                    payload.setdefault("parameters", {})["dimension"] = request.dimensions
 
                 async with httpx.AsyncClient(timeout=30.0) as client:
                     response = await client.post(api_url, headers=headers, json=payload)