首页/AI/大模型部署与运维速查/工具调用:服务端解析与启用
推理参数与优化50 条

工具调用:服务端解析与启用

函数调用让模型按约定输出结构化调用请求;自托管服务需启用对应解析器(如 vLLM 的 --tool-call-parser,解析器与模型族配套),网关再把 tool_calls 交给业务执行。

服务端启用(vLLM 示意)

服务端启用(vLLM 示意)
vllm serve <模型路径> --enable-auto-tool-choice --tool-call-parser hermes
# 解析器名称按模型族与版本文档选择

请求侧

请求侧
tools = [{"type": "function", "function": {
    "name": "get_weather",
    "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}}]
r = client.chat.completions.create(model="<模型名>", messages=[{"role": "user", "content": "上海天气?"}], tools=tools, tool_choice="auto")
print(r.choices[0].message.tool_calls)

易错点

  • 只验证模型会吐 JSON:未启用解析器时调用不会进入 tool_calls 字段,集成阶段才发现链路断点

数据来源与参考

  • vLLM 官方文档:Tool Calling(docs.vllm.ai)
  • OpenAI API 参考:Function calling(platform.openai.com/docs)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌