, ,

Function Calling

前面是通过 提示词 的形式,将工具箱带过去。 这种方式有什么问题? 不同的模型,Function Callin…

前面是通过 提示词 的形式,将工具箱带过去。

这种方式有什么问题?

  1. 繁琐:大段大段的提示词,仅仅是为了约束大模型的输出
  2. 不标准:每个开发者的提示词的描述千差万别
  3. 约束力不高:即便使用了语气最重的提示词,大模型的底层原理决定了它总会有不按照要求回复的情况
  • 工具箱的提供
// 工具箱
const tools = [{
    type: "function",
    name: "get_weather",
    description: "Get current temperature for provided coordinates in celsius.",
    parameters: {
        type: "object",
        properties: {
            latitude: { type: "number" },
            longitude: { type: "number" }
        },
        required: ["latitude", "longitude"],
        additionalProperties: false
    },
    strict: true
}];
  • 返回的调用工具请求
[{
    "type": "function_call",
    "id": "fc_12345xyz",
    "call_id": "call_12345xyz",
    "name": "get_weather",
    "arguments": "{\"latitude\":48.8566,\"longitude\":2.3522}"
}]

不同的模型,Function Calling的格式不一致。

deepseek

tools = [{
 "type": "function",
 "function": {
     "name": "get_weather",
     "description": "Get weather of an location",
     "parameters": {
         "type": "object",
         "properties": {
             "location": {
                 "type": "string",
                 "description": "The city and state, e.g. San Francisco, CA",
            }
        },
         "required": ["location"]
    },
}
}]

GPT

const tools = [{
   type: "function",
   name: "get_weather",
   description: "Get current temperature for provided coordinates in celsius.",
   parameters: {
       type: "object",
       properties: {
           latitude: { type: "number" },
           longitude: { type: "number" }
      },
       required: ["latitude", "longitude"],
       additionalProperties: false
  },
   strict: true
}];

claude

"tools": [{
 "name": "get_weather",
 "description": "Get the current weather in a given location",
 "input_schema": {
   "type": "object",
   "properties": {
     "location": {
       "type": "string",
       "description": "The city and state, e.g. San Francisco, CA"
    }
  },
   "required": ["location"]
}
}],

Previous Post

Next Post

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About the Author

每个人都有自己得时区,在自己得时区里,一切都是准时的。

BlockSpare — News, Magazine and Blog Addons for (Gutenberg) Block Editor