Update environment configuration to switch OpenAI model from gpt-5.4 to gpt-4o-mini. Introduce _effective_llm_route_from_request function in api_server.py to determine the effective LLM routing based on service keys and model compatibility. Update chat event handling to include LLM routing information in response data. Enhance logging for better traceability of API interactions.
This commit is contained in:
@@ -275,6 +275,36 @@ def _conversation_nl_dict(reply: str) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _effective_llm_route_from_request(request: NLChatRequest) -> Dict[str, Any]:
|
||||
"""
|
||||
计算“本次请求实际使用的 LLM 路由信息”(用于前端联调回显)。
|
||||
注意:此处仅回显路由结果,不包含密钥等敏感信息。
|
||||
"""
|
||||
model = _normalize_model_label(request.model)
|
||||
sc = _infer_service_code(request.service_code, model)
|
||||
|
||||
sc2 = sc
|
||||
if sc2 == "deepseek" and not _has_deepseek_key():
|
||||
if _has_openai_key():
|
||||
sc2 = "openai"
|
||||
if sc2 == "openai" and not _has_openai_key():
|
||||
if _has_deepseek_key():
|
||||
sc2 = "deepseek"
|
||||
|
||||
# 与 _maybe_override_orch_llm 保持一致:网关不兼容时丢弃 model 覆盖,让下游走默认模型
|
||||
effective_model = model
|
||||
if effective_model is not None:
|
||||
if (sc2 or "").strip().lower() == "openai" and "deepseek" in effective_model.strip().lower():
|
||||
effective_model = None
|
||||
elif (sc2 or "").strip().lower() == "deepseek" and effective_model.strip().lower().startswith("gpt"):
|
||||
effective_model = None
|
||||
|
||||
return {
|
||||
"service_code": sc2,
|
||||
"model": effective_model,
|
||||
}
|
||||
|
||||
|
||||
def _normalize_lang_code(code: Optional[str]) -> str:
|
||||
raw = (code or "auto").strip()
|
||||
if not raw:
|
||||
@@ -670,6 +700,7 @@ async def _chat_stream_events(request: NLChatRequest) -> AsyncIterator[bytes]:
|
||||
async for pkt in _sse_stream_text_chunks("chat", reply):
|
||||
yield pkt
|
||||
data_dict = _conversation_nl_dict(reply)
|
||||
data_dict["llm"] = _effective_llm_route_from_request(request)
|
||||
yield _sse_data({"code": 200, "msg": "success", "data": data_dict})
|
||||
await _append_session_if_needed(request, text, data_dict)
|
||||
return
|
||||
@@ -760,6 +791,7 @@ async def _chat_stream_events(request: NLChatRequest) -> AsyncIterator[bytes]:
|
||||
pass
|
||||
|
||||
data_dict = _nl_dict_from_generation(result)
|
||||
data_dict["llm"] = _effective_llm_route_from_request(request)
|
||||
msg = "success" if result.valid else "partial"
|
||||
yield _sse_data({"code": 200, "msg": msg, "data": data_dict})
|
||||
await _append_session_if_needed(request, text, data_dict)
|
||||
@@ -846,6 +878,7 @@ async def nl_chat(request: NLChatRequest):
|
||||
reply = _localized_conversation_reply(lang)
|
||||
logger.info("[API/chat] 对话意图: conversation(跳过 Text2SQL)")
|
||||
data_dict = _conversation_nl_dict(reply)
|
||||
data_dict["llm"] = _effective_llm_route_from_request(request)
|
||||
await _append_session_if_needed(request, text, data_dict)
|
||||
return {"code": 200, "msg": "success", "data": data_dict}
|
||||
|
||||
@@ -866,6 +899,7 @@ async def nl_chat(request: NLChatRequest):
|
||||
pass
|
||||
|
||||
data_dict = _nl_dict_from_generation(result)
|
||||
data_dict["llm"] = _effective_llm_route_from_request(request)
|
||||
response_data = NLChatSuccessData.model_validate(data_dict)
|
||||
msg = "success" if result.valid else "partial"
|
||||
if result.valid:
|
||||
|
||||
Reference in New Issue
Block a user