学习笔记 · Obsidian

Chat 模型:专业 API、路由与本地推理

LangChainPython

快速比较

下表的“支持”仅反映 2026-08-11 LangChain 文档中的集成类能力,不保证任意 model ID 都实现。

类 / 包能力摘要限制与适用场景
ChatAnthropicTools / langchain-anthropic.experimental工具绑定、结构化输出页面明确标记 deprecated;新项目改用 ChatAnthropic.bind_tools / 当前 structured output API
ChatBaseten / langchain-basetentool/schema、图像/音频、stream/async/usage能力由部署的具体模型决定;无视频/logprobs 标记
ChatCerebras / langchain-cerebrastool/schema、stream/async/usage无多模态/logprobs 标记;突发并发要配合 provider 限流
ChatCohere / langchain-cohereChat 与 tool calling页面无完整能力表;上线前自行补齐 stream/schema/usage 契约测试
ChatCrusoe / langchain-crusoetool/schema、stream/async/usage无多模态/logprobs 标记;可用模型列表和参数应在启动时校验
ChatDatabricks / databricks-langchaintool/schema、stream/async/usage,支持自定义/外部 endpoint需 serving endpoint;无多模态/logprobs 标记,自定义 endpoint 契约由部署者承担
ChatDeepSeek / langchain-deepseektool/schema、stream/async/usage无多模态/logprobs 标记;用专用类保留 reasoning 扩展,不用通用 ChatOpenAI 代理
ChatFireworks / langchain-fireworkstool/schema、stream/async/usage/logprobs,reasoning effort无多模态标记;需 pin model/endpoint 和限制 logprobs 返回大小
ChatGroq / langchain-groqtool/schema、图像、stream/async/usage/logprobs视觉取决模型;无音频/视频标记
ChatHuggingFace / langchain-huggingfacetool/schema,图像/音频/视频,usage文档表示 token-level streaming 和 native async 不完整;后端可是 Endpoint 或本地 Pipeline,运维特性不同
ChatLiteLLM / ChatLiteLLMRoutertools/schema、图像/音频、stream/async/usage/logprobs,Vertex grounding路由配置会同时引入多 provider 凭据与异质能力;需锁定 fallback 和成本
ChatMistralAI / langchain-mistralaitool/schema、stream/async/usage无多模态/logprobs 标记
ChatOllama / langchain-ollamatool/schema、图像、stream/async/logprobs,reasoning/custom roles能力表不标 token usage;模型 tag、显存、并发和冷启动由本地运维承担
ChatOpenRouter / langchain-openroutertools/strict schema、reasoning、图像/音频/视频、stream/async/usage/logprobs多 provider 路由可改变数据地域、特性和成本;应配 allowlist 和路由可观测
ChatParallel / langchain-parallel研究模型 structured output、citations、stream/async无 tool calling/多模态/token usage/logprobs;structured output 仅研究模型,错误处理与引用是主要契约
ChatPerplexity / langchain-perplexitysearch metadata/citations、stream、usage,tier 3+ structured output、Agent API 模式无 tool calling/多模态/native async/logprobs;账户层级会改变能力
ChatQwen / langchain-qwqtools/schema、图像/视频、stream/async/usage无音频/logprobs 标记;Qwen 与 QwQ 共包但类和模型定位不同
ChatQwQ / langchain-qwqtools/schema、图像/视频、stream/async/usage同上;不从 reasoning 品牌名假设特定字段形状
ChatSambaNova / langchain-sambanovatools/schema、图像/音频、stream/async/usage无视频/logprobs 标记;多模态依具体模型
ChatTogether / langchain-togethertools/schema、图像/音频/视频、stream/usage/logprobs能力表标 native async 为否;在 async web 服务中需实测 SDK 是否阻塞
ChatUpstage / langchain-upstageSolar Chat、chain文档无完整能力表;不根据同 provider 的 embedding/parser 能力反推 Chat
vLLM via ChatOpenAI / langchain-openaiOpenAI-compatible 本地 Chat endpoint页面是兼容接入,无完整能力表;非标准 reasoning/usage/tool 字段可丢失,应契约测试 server 版本
ChatXAI / langchain-xaitool/schema、web search、reasoning effort、stream/usage/logprobs无多模态/native async 标记;web search 引用与外部内容安全需另行处理

选型建议

  • 需 provider 扩展字段(reasoning、citation、search metadata、safety)时,使用专用包;仅普通文本对话且已做兼容测试时,才用 ChatOpenAI(base_url=...)。
  • 需路由/fallback 时优先专用 router 类,并将每个候选模型纳入同一套工具/schema/安全/成本回归测试。
  • 需数据不出域或稳定单位成本时选本地 Hugging Face/Ollama/vLLM,但要把模型服务当独立生产系统运维,不是开发机进程。
  • 搜索/研究产品应优先保留 citations/search metadata,不把可阅读文本当成无来源事实。

运行时风险

  1. 在 async FastAPI 路径中,文档未标 native async 的 SDK 要经过线程池或隔离 worker,并使用有界并发,防止阻塞 event loop。
  2. 流式失败可能已向用户输出部分结果;不可无条件切换另一 provider 再发一遍,否则语义重复且工具可重复。
  3. 用户可控 model/base URL 会变成 SSRF、费用滥用和数据外发通道;只能从服务端 allowlist 选择。
  4. 使用本地模型时要监控排队、显存/OOM、首 token、tokens/s 和 cancel;限制 context 与 max output 防止单请求占满服务。