8.2 函数调用与工具集成
8.2.1 为什么需要原生函数调用?
8.2.2 定义工具: JSON Schema 的力量
基础示例:查询天气
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的当前天气信息。如果用户没有指定城市,询问用户。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称,如'北京'、'New York'"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "温度单位,默认为 celsius"
}
},
"required": ["city"]
}
}
}进阶示例:复杂的订单查询
8.2.3 并行函数调用 ( Parallel Function Calling)
8.2.4 错误处理与鲁棒性设计
1. 参数幻觉 ( Parameter Hallucination)
2. 工具执行失败
3. 结果过长
8.2.5 安全警示:间接提示注入
动手试试
最后更新于
