修复嵌入服务,使用自定义 ZhipuAI 嵌入实现
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 13m44s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 13m44s
This commit is contained in:
@@ -120,14 +120,31 @@ class ZhipuEmbeddingProvider(BaseServiceProvider[Embeddings]):
|
|||||||
Embeddings: LangChain 兼容的嵌入实例
|
Embeddings: LangChain 兼容的嵌入实例
|
||||||
"""
|
"""
|
||||||
if self._service_instance is None:
|
if self._service_instance is None:
|
||||||
from langchain_zhipu import ZhipuAIEmbeddings
|
self._service_instance = _SimpleZhipuAIEmbeddings(
|
||||||
self._service_instance = ZhipuAIEmbeddings(
|
|
||||||
model=self._model,
|
model=self._model,
|
||||||
api_key=ZHIPUAI_API_KEY
|
api_key=ZHIPUAI_API_KEY
|
||||||
)
|
)
|
||||||
return self._service_instance
|
return self._service_instance
|
||||||
|
|
||||||
|
|
||||||
|
class _SimpleZhipuAIEmbeddings(Embeddings):
|
||||||
|
"""
|
||||||
|
简单的智谱 AI 嵌入实现,直接用 zhipuai 库
|
||||||
|
"""
|
||||||
|
def __init__(self, model: str, api_key: str):
|
||||||
|
from zhipuai import ZhipuAI
|
||||||
|
self.model = model
|
||||||
|
self.client = ZhipuAI(api_key=api_key)
|
||||||
|
|
||||||
|
def embed_documents(self, texts: list[str]) -> list[list[float]]:
|
||||||
|
response = self.client.embeddings.create(model=self.model, input=texts)
|
||||||
|
return [item.embedding for item in response.data]
|
||||||
|
|
||||||
|
def embed_query(self, text: str) -> list[float]:
|
||||||
|
response = self.client.embeddings.create(model=self.model, input=[text])
|
||||||
|
return response.data[0].embedding
|
||||||
|
|
||||||
|
|
||||||
class LocalLlamaCppEmbedder:
|
class LocalLlamaCppEmbedder:
|
||||||
"""
|
"""
|
||||||
通过 OpenAI 兼容 API 封装 llama.cpp 嵌入服务
|
通过 OpenAI 兼容 API 封装 llama.cpp 嵌入服务
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ langgraph==1.1.6
|
|||||||
langgraph-checkpoint-postgres==3.0.5
|
langgraph-checkpoint-postgres==3.0.5
|
||||||
tiktoken>=0.12.0
|
tiktoken>=0.12.0
|
||||||
|
|
||||||
|
# Zhipu AI
|
||||||
|
zhipuai==2.0.1
|
||||||
|
|
||||||
# Vector DB
|
# Vector DB
|
||||||
qdrant-client==1.17.1
|
qdrant-client==1.17.1
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ tenacity==9.1.4
|
|||||||
rich==15.0.0
|
rich==15.0.0
|
||||||
PyYAML==6.0.3
|
PyYAML==6.0.3
|
||||||
numpy>=1.26.2
|
numpy>=1.26.2
|
||||||
pyjwt==2.10.1
|
pyjwt==2.8.0
|
||||||
|
|
||||||
# Document Processing
|
# Document Processing
|
||||||
unstructured==0.22.21
|
unstructured==0.22.21
|
||||||
|
|||||||
Reference in New Issue
Block a user