update
This commit is contained in:
parent
dc2d64421d
commit
86abc18c6f
|
|
@ -119,8 +119,6 @@ async def chat_completion(
|
||||||
f"knowledge_graph_id: {request.knowledge_graph_id}, "
|
f"knowledge_graph_id: {request.knowledge_graph_id}, "
|
||||||
f"llm_provider: {request.llm_provider}, llm_model: {request.llm_model}, ip={client_ip}"
|
f"llm_provider: {request.llm_provider}, llm_model: {request.llm_model}, ip={client_ip}"
|
||||||
)
|
)
|
||||||
request.llm_model = "qwen3.7-plus"
|
|
||||||
request.llm_provider = "tongyi"
|
|
||||||
# ============ 内容审核前置处理 ============
|
# ============ 内容审核前置处理 ============
|
||||||
# 在 AI 处理前对用户消息进行内容审核
|
# 在 AI 处理前对用户消息进行内容审核
|
||||||
try:
|
try:
|
||||||
|
|
@ -156,7 +154,6 @@ async def chat_completion(
|
||||||
f"labels: {[label.label for label in moderation_result.labels]}"
|
f"labels: {[label.label for label in moderation_result.labels]}"
|
||||||
)
|
)
|
||||||
# 使用统一的错误响应格式(与图片审核一致)
|
# 使用统一的错误响应格式(与图片审核一致)
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
content={
|
content={
|
||||||
|
|
@ -185,7 +182,6 @@ async def chat_completion(
|
||||||
f"request_id: {moderation_request_id}"
|
f"request_id: {moderation_request_id}"
|
||||||
)
|
)
|
||||||
# 使用统一的错误响应格式(与图片审核一致)
|
# 使用统一的错误响应格式(与图片审核一致)
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
content={
|
content={
|
||||||
|
|
@ -260,7 +256,7 @@ async def chat_completion(
|
||||||
enable_thinking=user_is_reasoner,
|
enable_thinking=user_is_reasoner,
|
||||||
logical_llm_id=llm_model_key,
|
logical_llm_id=llm_model_key,
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.info(
|
||||||
"chat_completion 模型: provider={} req_llm_model={} api_model={} user_is_reasoner={}",
|
"chat_completion 模型: provider={} req_llm_model={} api_model={} user_is_reasoner={}",
|
||||||
llm_provider,
|
llm_provider,
|
||||||
llm_model_key,
|
llm_model_key,
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,13 @@ class Settings(BaseSettings):
|
||||||
embedding_model: str = "text-embedding-v4" # 通义千问 Embedding 模型
|
embedding_model: str = "text-embedding-v4" # 通义千问 Embedding 模型
|
||||||
embedding_dimension: int = 1536 # Embedding 维度
|
embedding_dimension: int = 1536 # Embedding 维度
|
||||||
|
|
||||||
|
# 辅助任务模型(意图判断、摘要生成等),默认与主聊天模型一致
|
||||||
|
# 可在 .env 中通过 UTILITY_LLM_MODEL 覆盖(如 qwen-plus-latest、qwen3-max)
|
||||||
|
utility_llm_model: str = Field(
|
||||||
|
default="qwen3-max",
|
||||||
|
validation_alias=AliasChoices("UTILITY_LLM_MODEL", "utility_llm_model"),
|
||||||
|
)
|
||||||
|
|
||||||
# Neo4j 图数据库配置
|
# Neo4j 图数据库配置
|
||||||
neo4j_uri: str = "bolt://127.0.0.1:7687"
|
neo4j_uri: str = "bolt://127.0.0.1:7687"
|
||||||
neo4j_user: str = "neo4j"
|
neo4j_user: str = "neo4j"
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,6 @@ def build_chat_model(
|
||||||
p = normalize_provider(provider)
|
p = normalize_provider(provider)
|
||||||
if p == "tongyi":
|
if p == "tongyi":
|
||||||
api_key = (os.getenv("DASHSCOPE_API_KEY") or "").strip()
|
api_key = (os.getenv("DASHSCOPE_API_KEY") or "").strip()
|
||||||
print("-----------------------------------api_key: ", api_key)
|
|
||||||
if not api_key:
|
if not api_key:
|
||||||
raise ValueError("缺少 DASHSCOPE_API_KEY")
|
raise ValueError("缺少 DASHSCOPE_API_KEY")
|
||||||
base_url = llm_env.tongyi_openai_compatible_base_url().strip().rstrip("/")
|
base_url = llm_env.tongyi_openai_compatible_base_url().strip().rstrip("/")
|
||||||
|
|
@ -284,7 +283,6 @@ def build_chat_model(
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"未知提供方: {provider}")
|
raise ValueError(f"未知提供方: {provider}")
|
||||||
|
|
||||||
print("-----------------------------------走到这里了-----------------------------------",extra_kwargs)
|
|
||||||
return ChatOpenAI(
|
return ChatOpenAI(
|
||||||
model=api_model,
|
model=api_model,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from typing import List, Dict, Optional
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from langchain_core.prompts import PromptTemplate
|
from langchain_core.prompts import PromptTemplate
|
||||||
|
|
||||||
|
from core.config import get_settings
|
||||||
from core.llm_catalog import build_chat_model
|
from core.llm_catalog import build_chat_model
|
||||||
from logger.logging import get_logger
|
from logger.logging import get_logger
|
||||||
|
|
||||||
|
|
@ -121,7 +122,7 @@ class RagIntentService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.model = build_chat_model(
|
self.model = build_chat_model(
|
||||||
provider="tongyi",
|
provider="tongyi",
|
||||||
api_model="qwen-plus-latest",
|
api_model=get_settings().utility_llm_model,
|
||||||
streaming=False,
|
streaming=False,
|
||||||
temperature=0.1, # 降低温度,让判断更稳定
|
temperature=0.1, # 降低温度,让判断更稳定
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -80,11 +80,12 @@ class SummaryService:
|
||||||
|
|
||||||
async with cls._lock:
|
async with cls._lock:
|
||||||
if cls._llm_cache is None:
|
if cls._llm_cache is None:
|
||||||
|
from core.llm_catalog import _DEFAULT_MODEL_BY_PROVIDER
|
||||||
cls._llm_cache = build_chat_model(
|
cls._llm_cache = build_chat_model(
|
||||||
provider="tongyi",
|
provider="tongyi",
|
||||||
api_model="qwen-plus-latest",
|
api_model=_DEFAULT_MODEL_BY_PROVIDER["tongyi"],
|
||||||
streaming=False,
|
streaming=False,
|
||||||
temperature=0.3, # 适度提高灵活性,更好地总结全文
|
temperature=0.3,
|
||||||
)
|
)
|
||||||
return cls._llm_cache
|
return cls._llm_cache
|
||||||
|
|
||||||
|
|
@ -194,9 +195,10 @@ sheet_summary: 对所有sheet表的描述进行总结,不超过20字;
|
||||||
|
|
||||||
async with cls._lock:
|
async with cls._lock:
|
||||||
if cls._llm_cache is None:
|
if cls._llm_cache is None:
|
||||||
|
from core.llm_catalog import _DEFAULT_MODEL_BY_PROVIDER
|
||||||
cls._llm_cache = build_chat_model(
|
cls._llm_cache = build_chat_model(
|
||||||
provider="tongyi",
|
provider="tongyi",
|
||||||
api_model="qwen-plus-latest",
|
api_model=_DEFAULT_MODEL_BY_PROVIDER["tongyi"],
|
||||||
streaming=False,
|
streaming=False,
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
model_kwargs={"response_format": {"type": "json_object"}},
|
model_kwargs={"response_format": {"type": "json_object"}},
|
||||||
|
|
@ -283,9 +285,10 @@ csv_description: 对csv表格的内容进行描述,不超过20字;
|
||||||
|
|
||||||
async with cls._lock:
|
async with cls._lock:
|
||||||
if cls._llm_cache is None:
|
if cls._llm_cache is None:
|
||||||
|
from core.llm_catalog import _DEFAULT_MODEL_BY_PROVIDER
|
||||||
cls._llm_cache = build_chat_model(
|
cls._llm_cache = build_chat_model(
|
||||||
provider="tongyi",
|
provider="tongyi",
|
||||||
api_model="qwen-plus-latest",
|
api_model=_DEFAULT_MODEL_BY_PROVIDER["tongyi"],
|
||||||
streaming=False,
|
streaming=False,
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
model_kwargs={"response_format": {"type": "json_object"}},
|
model_kwargs={"response_format": {"type": "json_object"}},
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,7 @@ def text_to_image(
|
||||||
f"开始生成图片(OpenAI 兼容 images/generations),model={model_image}, n={n_req}, size={size_norm}"
|
f"开始生成图片(OpenAI 兼容 images/generations),model={model_image}, n={n_req}, size={size_norm}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
response = client.images.generate(
|
response = client.images.generate(
|
||||||
model=model_image,
|
model=model_image,
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
|
|
@ -196,6 +197,10 @@ def text_to_image(
|
||||||
n=n_req,
|
n=n_req,
|
||||||
extra_body=extra_body,
|
extra_body=extra_body,
|
||||||
)
|
)
|
||||||
|
except Exception as api_err:
|
||||||
|
err_str = str(api_err)
|
||||||
|
logger.error(f"文生图 API 调用失败: {err_str}")
|
||||||
|
return f"图片生成失败:{err_str}"
|
||||||
|
|
||||||
image_urls: list[str] = []
|
image_urls: list[str] = []
|
||||||
for item in response.data or []:
|
for item in response.data or []:
|
||||||
|
|
@ -475,6 +480,7 @@ def text_to_poster(
|
||||||
"negative_prompt": negative,
|
"negative_prompt": negative,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
response = client.images.generate(
|
response = client.images.generate(
|
||||||
model=model_image,
|
model=model_image,
|
||||||
prompt=prompt,
|
prompt=prompt,
|
||||||
|
|
@ -482,6 +488,10 @@ def text_to_poster(
|
||||||
n=1,
|
n=1,
|
||||||
extra_body=extra_body,
|
extra_body=extra_body,
|
||||||
)
|
)
|
||||||
|
except Exception as api_err:
|
||||||
|
err_str = str(api_err)
|
||||||
|
logger.error(f"海报生成 API 调用失败: {err_str}")
|
||||||
|
return f"海报生成失败:{err_str}"
|
||||||
|
|
||||||
image_urls: list[str] = []
|
image_urls: list[str] = []
|
||||||
for item in response.data or []:
|
for item in response.data or []:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue