fix: 修复阿里百炼项目模型v3调用方式 (#1773)
This commit is contained in:
parent
7afbaba4ce
commit
7c529c281c
@ -6,6 +6,7 @@
|
|||||||
@date:2024/10/16 16:34
|
@date:2024/10/16 16:34
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
|
from functools import reduce
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from langchain_community.embeddings import DashScopeEmbeddings
|
from langchain_community.embeddings import DashScopeEmbeddings
|
||||||
@ -14,6 +15,12 @@ from langchain_community.embeddings.dashscope import embed_with_retry
|
|||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
|
|
||||||
|
|
||||||
|
def proxy_embed_documents(texts: List[str], step_size, embed_documents):
|
||||||
|
value = [embed_documents(texts[start_index:start_index + step_size]) for start_index in
|
||||||
|
range(0, len(texts), step_size)]
|
||||||
|
return reduce(lambda x, y: [*x, *y], value, [])
|
||||||
|
|
||||||
|
|
||||||
class AliyunBaiLianEmbedding(MaxKBBaseModel, DashScopeEmbeddings):
|
class AliyunBaiLianEmbedding(MaxKBBaseModel, DashScopeEmbeddings):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
|
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
|
||||||
@ -23,6 +30,11 @@ class AliyunBaiLianEmbedding(MaxKBBaseModel, DashScopeEmbeddings):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
||||||
|
if self.model == 'text-embedding-v3':
|
||||||
|
return proxy_embed_documents(texts, 6, self._embed_documents)
|
||||||
|
return self._embed_documents(texts)
|
||||||
|
|
||||||
|
def _embed_documents(self, texts: List[str]) -> List[List[float]]:
|
||||||
"""Call out to DashScope's embedding endpoint for embedding search docs.
|
"""Call out to DashScope's embedding endpoint for embedding search docs.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user