# Summary https://hf7l9aiqzx.feishu.cn/wiki/GBb3wU1jni5p4NkOzeNcZxDonzc # Cues # Notes > LLM 调用概览 - 生产主流程统一经 `get_chat_open_ai_by_biz` 构建 `ChatOpenAI`,集中注入 `base_url`(默认为 $http://llm.api.corp.qunar.com/v1$)、`model`、拼接后的专用 `Authorization header`、`streaming` 与 `token` 上限,并在内存做限流与实例缓存,依赖 `langchain-openai==0.3.18` 与 `openai==1.82.0` (`app/qconfig/ai_account_config.py:43`, `app/qconfig/ai_account_config.py:81`, `requirements.txt:37`, `requirements.txt:54`). - 常规问答节点直接调用 `llm.invoke`,将 `apply_prompt_template` 产出的 `SystemMessage`+历史 `Human/AIMessage` 发送给模型,用于意图识别、回复生成等 (`prompts/template.py:35`, `graph/nodes.py:252`, `store/route_store.py:102`, `app/services/trip/hotel_service.py:104`). - 结构化/JSON 模式在相同 LLM 上叠加 `.with_structured_output(...)` 和必要的 `response_format` 约束,以 `Pydantic schema` 或纯 `json_object` 形式要求模型返回结构化字段 (`graph/nodes.py:155`, `graph/nodes.py:202`). - `LangGraph` 工具流按需把同一 LLM 注入 `ReAct Agent`,模型与工具往返的消息同样走 `ChatOpenAI`,只是由 `LangGraph` 负责追加 `tool` 调用与 `observation` (`graph/nodes_by_trip_consult_sector.py:280`). - `mvpdemo` 目录为演示用途,直接在各节点里以 `OpenRouter base_url` 实例化 `ChatOpenAI(streaming=True)` 并通过 `astream` 取得块状输出,未复用生产封装 (`mvpdemo/nodes/thinker.py:19`, `mvpdemo/nodes/travel_planner.py:18`, `mvpdemo/nodes/hotel_consultant.py:18`). HTTP 请求细节 - 所有同步 `invoke` 调用最终被 `langchain-openai` 转成对 ${base_url}/responses$ 的 `POST`,请求体包含 `model`、按角色展开的 `input` 数组,以及在配置里启用的 `max_tokens`→`max_output_tokens`、`temperature`、`top_p`、`frequency_penalty`、`presence_penalty` (`app/qconfig/ai_account_config.py:47`, `app/qconfig/ai_account_config.py:58`). - 结构化输出时额外携带 `response_format` 字段:`Pydantic schema` 会被编译成 `OpenAI Responses API` 支持的 `json_schema`,`bind(response_format={"type":"json_object"})` 则直接声明简易 JSON 模式 (`graph/nodes.py:202`). - 当配置里保持 `streaming=True`(生产与 Demo 均如此)时,请求改为 `SSE` 流式响应;`LangGraph` 通过事件回调消费 `on_chat_model_stream`,Demo 则直接迭代 `llm.astream` (`app/qconfig/ai_account_config.py:57`, `app/services/workflow_service.py:143`, `mvpdemo/nodes/thinker.py:53`). 后续建议 - 若希望进一步统一调用栈,可考虑让 Demo 也复用 `get_chat_open_ai_by_biz` 或抽象一个 `LLMClientFactory`,减少配置分散。 - 结合现有 `streaming` 默认开启的情况,建议在配置中心显式记录每个 `biz` 的温度、`top_p` 等落地值,便于排查最终请求体。