这篇主要整理一下openai和国内(dashscope、gitee等)模型平台的function calling的格式区别。
仅总结可调用工具列表的定义方式,即:“如何定义工具列表”。
OpenAI
tools = [
{
"type": "function",
"name": "get_horoscope",
"description": "Get today's horoscope for an astrological sign.",
"parameters": {
"type": "object",
"properties": {
"sign": {
"type": "string",
"description": "An astrological sign like Taurus or Aquarius",
},
},
"required": ["sign"],
},
},
]
DashScope
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。",
}
},
"required": ["location"],
},
},
},
]
Gitee AI
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "通过城市名和日期获取地点的天气情况,包括温度、天气状况等信息",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "用户想要查询天气的城市名称",
},
"date": {
"type": "string",
"description": "想要查询的日期,如'今天'、'明天'或具体日期'2023-10-01'",
}
},
"required": ["city", "date"],
},
}
}
]
Function Calling 工具定义格式对比
| 平台 | 工具定义结构 | 关键字段层级 | 特点说明 |
|---|---|---|---|
| OpenAI | {"type": "function", "name": "...", "description": "...", "parameters": {...}} |
name、description、parameters 直接位于最外层 |
无 "function" 嵌套层。 |
| DashScope | {"type": "function", "function": {"name": "...", "description": "...", "parameters": {...}}} |
多一层 "function" 包裹内部定义 |
函数信息嵌套在 "function" 字段中。 |
| Gitee AI | 同DashScope | 同DashScope | 同DashScope |
✅ 总结:OpenAI与DashScope/Gitee AI的Function Calling形式的主要区别在于:是否包裹
"function"层。
