feat: 统一管理模型服务配置信息
This commit is contained in:
@@ -1 +1,6 @@
|
||||
LLM_KEY_LOCAL=123 # 本地模型key
|
||||
LLM_KEY_HUOSHAN=dc7979dc-af60-4700-9f71-91f576b1c947 # 火山引擎模型服务平台key
|
||||
LLM_KEY_BAILIAN=sk-248f811295914adcad837add0a5971d0 # 阿里云百炼模型服务平台key
|
||||
LLM_KEY_DEEPSEEK=sk-a89d0ff9421a43fca5f0xxxxxxxxxxxx # Deepseek模型服务平台key
|
||||
|
||||
SERVER_PORT = 7004 # 服务启动端口
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
from app.config.env import env
|
||||
|
||||
ai_configs = {
|
||||
# /*---------------------------------------local-------------------------------------------*/
|
||||
"local": {
|
||||
"model": "deepseek-r1-distill-qwen-7b",
|
||||
"url": "http://127.0.0.1:1234/v1/chat/completions",
|
||||
"key": env.llm_key_local
|
||||
},
|
||||
"local_glm": {
|
||||
"model": "glm-4-9b-0414",
|
||||
"url": "http://127.0.0.1:1234/v1/chat/completions",
|
||||
"key": env.llm_key_local
|
||||
},
|
||||
"local_embedding": {
|
||||
"model": "text-embedding-text2vec-large-chinese",
|
||||
"url": "http://127.0.0.1:1234/v1/embeddings",
|
||||
"key": env.llm_key_local
|
||||
},
|
||||
# /*---------------------------------------deepseek-------------------------------------------*/
|
||||
'deepseek-v3': {
|
||||
'model': 'deepseek-chat',
|
||||
'url': 'https://api.deepseek.com/chat/completions',
|
||||
'key': env.llm_key_deepseek,
|
||||
},
|
||||
'deepseek-r1': {
|
||||
'model': 'deepseek-reasoner',
|
||||
'url': 'https://api.deepseek.com/chat/completions',
|
||||
'key': env.llm_key_deepseek,
|
||||
},
|
||||
# /*---------------------------------------huoshan-------------------------------------------*/
|
||||
'huoshan-deepseek-v3': {
|
||||
'model': 'deepseek-v3-250324',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
'huoshan-deepseek-r1': {
|
||||
'model': 'deepseek-r1-distill-qwen-7b-250120',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
'huoshan-doubao': {
|
||||
'model': 'doubao-1-5-lite-32k-250115',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
'huoshan-think-pro': {
|
||||
'model': 'doubao-1-5-thinking-pro-250415',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
'huoshan-doubao-seed': {
|
||||
'model': 'doubao-seed-1-6-250615',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
'doubao-vision-lite': {
|
||||
'model': 'doubao-1.5-vision-lite-250315',
|
||||
'url': 'https://ark.cn-beijing.volces.com/api/v3/chat/completions',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
|
||||
'huoshan-embedding-240715': {
|
||||
"model": 'doubao-embedding-text-240715',
|
||||
"url": 'https://ark.cn-beijing.volces.com/api/v3/embeddings',
|
||||
'key': env.llm_key_huoshan,
|
||||
},
|
||||
# /*---------------------------------------bailian-------------------------------------------*/
|
||||
'bailian-qwen-turbo': {
|
||||
'model': 'qwen-turbo',
|
||||
'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
|
||||
'key': env.llm_key_bailian,
|
||||
},
|
||||
'bailian-qwen3-max': {
|
||||
'model': 'qwen3-max',
|
||||
'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions',
|
||||
'key': env.llm_key_bailian,
|
||||
},
|
||||
'bailian-embedding': {
|
||||
'model': 'text-embedding-v4',
|
||||
'url': 'https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings',
|
||||
'key': env.llm_key_bailian,
|
||||
},
|
||||
}
|
||||
@@ -3,6 +3,11 @@ from pydantic import Field
|
||||
|
||||
|
||||
class EnvSettings(BaseSettings):
|
||||
llm_key_local: str = Field(..., env="LLM_KEY_LOCAL")
|
||||
llm_key_huoshan: str = Field(..., env="LLM_KEY_HUOSHAN")
|
||||
llm_key_bailian: str = Field(..., env="LLM_KEY_BAILIAN")
|
||||
llm_key_deepseek: str = Field(..., env="LLM_KEY_DEEPSEEK")
|
||||
|
||||
server_port: int = Field(..., env="SERVER_PORT")
|
||||
|
||||
class Config:
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
from langchain.chat_models import init_chat_model
|
||||
|
||||
from app.config.ai_configs import ai_configs
|
||||
|
||||
|
||||
def create_llm(
|
||||
platform_code='huoshan-doubao',
|
||||
temperature=0.5,
|
||||
disable_streaming=False,
|
||||
):
|
||||
_ai_config = ai_configs.get(platform_code)
|
||||
|
||||
if _ai_config is None:
|
||||
raise Exception('Unknown platform code', platform_code)
|
||||
|
||||
return init_chat_model(
|
||||
# 必须填 openai(兼容协议)
|
||||
model_provider="openai",
|
||||
# 你的模型名
|
||||
model=_ai_config.get('model'),
|
||||
# 你的自定义 API URL
|
||||
base_url=_ai_config.get('url').replace("chat/completions", ""),
|
||||
# 本地模型随便填
|
||||
api_key=_ai_config.get('key'),
|
||||
# 随机性
|
||||
temperature=temperature,
|
||||
# 禁用流式响应
|
||||
disable_streaming=disable_streaming,
|
||||
)
|
||||
@@ -17,6 +17,7 @@ from starlette.staticfiles import StaticFiles
|
||||
|
||||
from app.config.env import env
|
||||
from app.utils.get_local_ips import get_local_ips
|
||||
from app.utils.llm_utils import create_llm
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -91,17 +92,18 @@ async def redirect_root_to_docs():
|
||||
|
||||
@app.get("/chat")
|
||||
async def chat():
|
||||
model = init_chat_model(
|
||||
model="qwen2.5-vl-7b-instruct", # 你的模型名
|
||||
model_provider="openai", # 必须填 openai(兼容协议)
|
||||
base_url="http://127.0.0.1:1234/v1", # 你的自定义 API URL
|
||||
api_key="1234", # 本地模型随便填
|
||||
temperature=0.7,
|
||||
)
|
||||
output = model.invoke("你好").content
|
||||
model_qwen = create_llm(platform_code='bailian-qwen-turbo')
|
||||
model_qwen_output = model_qwen.invoke("你好,你是谁").content
|
||||
print(f"model_qwen output: {model_qwen_output}")
|
||||
|
||||
print(f"output:{output}")
|
||||
return output
|
||||
model_doubao = create_llm(platform_code='huoshan-doubao')
|
||||
model_doubao_output = model_doubao.invoke("你好,你是谁").content
|
||||
print(f"model_doubao output: {model_doubao_output}")
|
||||
|
||||
return {
|
||||
"model_qwen_output": model_qwen_output,
|
||||
"model_doubao_output": model_doubao_output
|
||||
}
|
||||
|
||||
|
||||
# Edit this to add the chain you want to add
|
||||
|
||||
Reference in New Issue
Block a user