|
@@ -1051,16 +1051,15 @@ class OpenAICompatService:
|
|
|
else:
|
|
else:
|
|
|
# 云端模型处理
|
|
# 云端模型处理
|
|
|
# 根据模型类型选择端点:多模态 embedding vs 文本 embedding
|
|
# 根据模型类型选择端点:多模态 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:
|
|
if is_multimodal:
|
|
|
api_url = "https://dashscope.aliyuncs.com/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding"
|
|
api_url = "https://dashscope.aliyuncs.com/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding"
|
|
|
payload = {
|
|
payload = {
|
|
|
"model": model.model_code,
|
|
"model": model.model_code,
|
|
|
"input": {
|
|
"input": {
|
|
|
- "texts": texts
|
|
|
|
|
- },
|
|
|
|
|
- "parameters": {
|
|
|
|
|
- "text_type": "query"
|
|
|
|
|
|
|
+ "contents": [{"text": t} for t in texts]
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else:
|
|
else:
|
|
@@ -1075,8 +1074,9 @@ class OpenAICompatService:
|
|
|
"Content-Type": "application/json",
|
|
"Content-Type": "application/json",
|
|
|
"Authorization": f"Bearer {effective_api_key}"
|
|
"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:
|
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
|
response = await client.post(api_url, headers=headers, json=payload)
|
|
response = await client.post(api_url, headers=headers, json=payload)
|