Advertisement

What is the OpenAI Chat Completion API tools/functions property format?

阅读量:

题意 :OpenAI 聊天完成 API 的工具/函数属性格式是什么

问题背景:

Are there any clear documents regarding the format of OpenAI's Chat Completion API tools or functions' format? I know it's JSON, but there are specific requirements for what properties'names or types are allowed within these objects.

针对 OpenAI 的聊天完成 API 工具/函数对象格式是否存在明确文档?我知道它采用的是 JSON 格式,并且对象内部允许的属性名称及其类型似乎有基本要求

I attempted to investigate all the property types that OpenAI allows within their tools or functions definitions, but unfortunately, their documentation is quite limited (it only provides links to a straightforward example along with an explanation of JSON schema). They clearly outline the specifics for description and name, yet they leave the parameters rather undefined.

我努力弄清楚OpenAI在其工具/函数定义中支持的各种属性类型(文档质量不高且仅提供了一些简要示例链接及JSON schema格式的帮助信息)。他们明确描述了描述项和名称项(但对参数项的说明极为开放),这使得用户需要自行解析以获取完整的信息

Image of tool attribute definition

问题解决:

Exploring the area and trying out different approaches for about an hour or two, I was eventually able to create a template that I have now developed for future reference. Hopefully, this will be helpful for others looking to save time in the future.

通过大约两小时的查找资料、尝试构建与手动调整等过程, 我成功创建了一个可供未来参考的模板. 期待它能帮助他人省时.

复制代码
 {

    
   "description": "This is a template that you can start from to build your tool",
    
   "name": "new_tool",
    
   "parameters": {
    
     "properties": {
    
       "array_property_name": {
    
     "description": "A property that returns an array of items (can be any type mentioned below, including an object)",
    
     "items": {
    
       "type": "string"
    
     },
    
     "type": "array"
    
       },
    
       "boolean_property_name": {
    
     "description": "A property that returns a boolean",
    
     "type": "boolean"
    
       },
    
       "enum_property_name": {
    
     "description": "A property that returns a value from a list of enums (can be any type)",
    
     "enum": [
    
       "option 1",
    
       "option 2",
    
       "option 3"
    
     ],
    
     "type": "string"
    
       },
    
       "number_property_name": {
    
     "description": "A property that returns a number",
    
     "type": "number"
    
       },
    
       "object_property_name": {
    
     "description": "A property that returns an object",
    
     "properties": {
    
       "foo": {
    
         "description": "A property on the object called 'foo' that returns a string",
    
         "type": "string"
    
       },
    
       "bar": {
    
         "description": "A property on the object called 'bar' that returns a number",
    
         "type": "number"
    
       }
    
     }
    
       },
    
       "string_property_name": {
    
     "description": "A property that returns a string",
    
     "type": "string"
    
       }
    
     },
    
     "required": [
    
       "array_property_name",
    
       "number_property_name"
    
     ],
    
     "type": "object"
    
   }
    
 }

全部评论 (0)

还没有任何评论哟~