feat:新增投顾agent和nl2sqlagent
This commit is contained in:
+30
-7
@@ -198,18 +198,41 @@ class LLMClient:
|
||||
LLM_EMBED_DIMENSIONS),MRL 模型(qwen3-embedding 等)会截断并重新归一化到目标维度。
|
||||
"""
|
||||
backend = self.primary
|
||||
if not backend.embed_model:
|
||||
embed_model = (
|
||||
getattr(self.cfg, "api_embed_model", "")
|
||||
if backend.name == "api"
|
||||
else backend.embed_model
|
||||
) or backend.embed_model
|
||||
if not embed_model:
|
||||
raise LLMFailError(f"backend={backend.name} 未配置 embed 模型")
|
||||
url = f"{backend.base_url}/embeddings"
|
||||
payload = {
|
||||
"model": backend.embed_model,
|
||||
"input": texts,
|
||||
# "dimensions": self.cfg.embed_dimensions,
|
||||
}
|
||||
is_dashscope_compatible = "/compatible-mode/" in backend.base_url.lower()
|
||||
if is_dashscope_compatible:
|
||||
base_url = backend.base_url.rstrip("/")
|
||||
marker = "/compatible-mode/v1"
|
||||
if base_url.lower().endswith(marker):
|
||||
base_url = base_url[: -len(marker)]
|
||||
url = f"{base_url}/api/v1/services/embeddings/multimodal-embedding/multimodal-embedding"
|
||||
payload = {
|
||||
"model": embed_model,
|
||||
"input": {"contents": [{"text": value} for value in texts]},
|
||||
}
|
||||
else:
|
||||
url = f"{backend.base_url}/embeddings"
|
||||
payload = {
|
||||
"model": embed_model,
|
||||
"input": texts,
|
||||
# "dimensions": self.cfg.embed_dimensions,
|
||||
}
|
||||
async with backend.client(self.cfg.timeout) as client:
|
||||
r = await client.post(url, headers=backend.headers, json=payload)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
if is_dashscope_compatible:
|
||||
embeddings = data["output"]["embeddings"]
|
||||
return [
|
||||
item["embedding"]
|
||||
for item in sorted(embeddings, key=lambda item: item["index"])
|
||||
]
|
||||
return [item["embedding"] for item in data["data"]]
|
||||
|
||||
async def embed_one(self, text: str) -> list[float]:
|
||||
|
||||
Reference in New Issue
Block a user