题意:OpenAI 聊天完成 API 的工具/函数属性格式是什么
问题背景:
Is there any clear documentation on the format of OpenAI's Chat Completion API tools/functions object format? I understand it's JSON, but there appear to be underlying requirements of what property names/types are allowed inside of the objects.
关于 OpenAI 的聊天完成 API 工具/函数对象格式是否有明确的文档?我知道它是 JSON 格式,但似乎对对象内部允许的属性名称/类型有一些基本要求
I tried figuring out what all property types OpenAI allowed in their tools/functions definition, but their documentation isn't great (they just have links to a simple example and an explanation of JSON schema 💩). They define description
and name
, but leave parameters
pretty much open to interpretation.
我试图弄清楚 OpenAI 在其工具/函数定义中允许的所有属性类型,但他们的文档并不太好(他们只提供了简单示例的链接和 JSON schema 的解释 💩)。他们定义了 description 和 name,但对 parameters 的解释几乎完全开放,留给用户自行理解
Image of tools property definition
问题解决:
After an hour or two of searching around, experimenting, and cobbling something together, I think I finally created a template that I could reference in the future. Hopefully this saves someone else some 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"}
}