Function Calling / Tool Use
统一格式(OpenAI 兼容)
bash
curl https://api.osp.io/v1/chat/completions \
-H "Authorization: Bearer $OSP_A... \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "北京天气怎么样?"}], "tools": [{"type": "function", "function": {"name": "get_weather", "description": "获取城市天气", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}], "tool_choice": "auto"}'响应示例
json
{"choices":[{"message":{"tool_calls":[{"id":"call_abc","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"北京\"}"}}]}}]}传入工具结果(多轮)
第二次请求把 role: tool 的结果传回去即可。
支持的模型
gpt-4o、gpt-4-turbo、claude-sonnet-4、gemini-2.0-flash 均支持。