如你所知,Function Calling是OpenAI 最先推出的⼀种⼯具使⽤机制,它采⽤了 OpenAPI 的标准来描述⼯具信息。其核⼼⽬的有两个:

  • 为开发者提供清晰统⼀的⼯具调⽤格式。
  • 为模型训练提供结构化数据,从⽽提升模型在调⽤⼯具时的表现。

举个例⼦:

tools = [{
    "type": "function",
    "name": "get_weather",
    "description": "Get current temperature for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City and country e.g. Bogotá, Colombia"
            }
        },
        "required": ["location"],
        "additionalProperties": False
    }
}]

上⾯这段其实就是⽤ JSON 格式来写的函数“说明书”。它不仅描述了函数的名字和作⽤,还列出了参数及其类型、是否必填等信息。之所以写成⼀个列表,是因为模型可能需要从多个函数中进⾏选择。

值得注意的是,这些“说明书”本质上会被嵌⼊到模型的上下⽂中,会消耗⼀定的context taken。

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐