What are the types that can be passed as parameters? I can only seem to set the type as a string.
can you set more complex types? i.e Array, two dimensional Array, objects, etc
I’m sure I’m doing something wrong. If I set the type to array I get 400 Bad request
The other day I do remember seeing the JSON schema for OpenAI functions. I think I even bookmarked the web page because it was three degrees of separation from the blog page.
Sadly I cannot find the page nor the link.
However ChatGPT does seem to possess some knowledge of the JSON schema so prompted ChatGPT.
What is the JSON schema for OpenAI function properties for a two dimensional array.
Completion
As of my knowledge cutoff in September 2021, OpenAI does not provide a specific JSON schema for function properties that includes a two-dimensional array. However, you can define the structure of a two-dimensional array within the function properties using a nested array structure. Here’s an example of how you might structure the properties for an OpenAI function with a two-dimensional array using JSON:
In this example, the function has a parameter named “array” which is an array of arrays. The inner arrays represent rows in the two-dimensional array, and each element within the inner arrays represents a value in the two-dimensional array (in this case, numbers). The output of the function is also a two-dimensional array with the same structure.
Please note that the actual schema for OpenAI function properties may differ depending on the specific implementation and requirements of the OpenAI API. It’s always a good idea to refer to the official OpenAI documentation or resources for the most up-to-date and accurate information on function properties.
I have not tried this.
EDIT
IIRC this is what I found the other day, may or may not be correct.
This OpenAI API reference page
Section: Create chat completion
notes
parameters object Optional
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
I found using pydantic made things easier for me and worked well with str, int, lists and dictionaries.
Here is an example where I extract data from a set of user interviews.
...
from pydantic import BaseModel, Field
from typing import Optional, List
# define function structure in pydantic
class Topic(BaseModel):
name: str = Field(..., description="Classification category")
count: int = Field(..., description="Count for the category")
class ExtractInsightsParams(BaseModel):
interviewee_names: List[str] = Field(..., description="The names of the interviewees, e.g. Christoph, person y")
interviewee_count: int = Field(..., description="Number of people interviewed")
interview_topics: List[Topic] = Field(..., description="List of top 10 classification categories with their counts")