feat: LLamaIndexEmbeddings,同时支持同步异步的embedding调用

This commit is contained in:
martsforever
2025-09-07 00:05:07 +08:00
parent 6d9cafe2eb
commit 536b755bf3
+3 -3
View File
@@ -3,7 +3,7 @@ from langchain_openai import ChatOpenAI
from llama_index.llms.openai_like import OpenAILike
from app.config.ai_configs import ai_configs
from app.utils.CustomEmbeddings import CustomEmbeddings
from app.utils.LLamaIndexEmbeddings import LLamaIndexEmbeddings
def create_llm(platform_code='huoshan-doubao', temperature=0.5):
@@ -45,7 +45,7 @@ def create_embeddings(platform_code="huoshan-embedding-240715"):
platform_code: 平台代码,用于从默认配置中查找对应平台的API信息
返回:
CustomEmbeddings类的实例,用于生成文本嵌入向量
LLamaIndexEmbeddings类的实例,用于生成文本嵌入向量
异常:
当找不到对应平台代码的配置时抛出异常
@@ -58,7 +58,7 @@ def create_embeddings(platform_code="huoshan-embedding-240715"):
raise Exception('Unknown platform code', platform_code)
# 创建并返回自定义嵌入模型实例
return CustomEmbeddings(
return LLamaIndexEmbeddings(
base_url=_ai_config.get('url').replace("/embeddings", ""), # API基础URL
api_key=_ai_config.get('key'), # API密钥
model=_ai_config.get('model') # 嵌入模型名称