为让模型正确调用工具功能(Function Calling),需将每个 tool 对象按规范格式构造。
{ "type": "function", "function": { ... } }
type
:固定值 "function"
function
:含函数名称、描述和参数等详细配置字段 | 类型 | 是否必填 | 说明 |
---|---|---|---|
name | string | 是 | 函数名称,唯一标识,建议使用小写加下划线 |
description | string | 是 | 函数作用的描述 |
parameters | object | 是 | 函数参数定义,需要符合 JSON Schema 格式 |
parameters
须为符合 JSON Schema 格式的对象:
{ "type": "object", "properties": { "参数名": { "type": "string | number | boolean | object | array", "description": "参数说明" } }, "required": ["必填参数"] }
type
:必须是 "object"
properties
:列出支持的所有参数名及其类型required
:列出必填的参数名{ "type": "function", "function": { "name": "get_weather", "description": "获取指定位置的天气信息", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "城市和国家,例如:北京,中国" } }, "required": ["location"] } } }
parameters
须是合规的 JSON Schema 对象。description
中。