ai tool call
tool schema 格式, Claude 的是 input_schema 格式, Ollama 需要 OpenAI 的 parameters 格式

以下是 Claude 版本工具的 OpenAI 格式转换:

Claude 的原始格式

{
  "name": "search_papers",
  "description": "Search for papers on arXiv based on a topic and store their information.",
  "input_schema": {
    "type": "object",
    "properties": {
      "topic": {
        "type": "string",
        "description": "The topic to search for"
      },
      "max_results": {
        "type": "integer",
        "description": "Maximum number of results to retrieve",
        "default": 5
      }
    },
    "required": ["topic"]
  }
}

OpenAI 格式版本

{
  "type": "function",
  "function": {
    "name": "search_papers",
    "description": "Search for papers on arXiv based on a topic and store their information.",
    "parameters": {
      "type": "object",
      "properties": {
        "topic": {
          "type": "string",
          "description": "The topic to search for"
        },
        "max_results": {
          "type": "integer",
          "description": "Maximum number of results to retrieve"
        }
      },
      "required": ["topic"]
    }
  }
}

说明:

  • type: 设为 “function”,指明这是一个函数调用的格式。
  • function:
    • name: 函数的名称,和 Claude 中的 name 相同。
    • description: 函数的描述,功能说明。
    • parameters: 定义了该函数的输入结构:
      • type: object 表示这是一个对象类型的参数。
      • properties: 包含详细字段定义(比如 topic 和 max_results)。
      • required: 指定必需的参数,这里 topic 是必填的。

对比:

  • 在 OpenAI 的格式中,function 字段包裹了工具的具体定义,包括参数、名称和描述,符合 OpenAI functions 的 API 规范。
Logo

欢迎加入DeepSeek 技术社区。在这里,你可以找到志同道合的朋友,共同探索AI技术的奥秘。

更多推荐