You can call the API and tell the AI the functions it should answer in any programming language that can send the request.
Consider though that you also need the backend to be able to fulfill the function that you have described when you receive a function_call
response.
It certainly would be helpful to have other language guides, but it seems that is left for us to discover and document, along with other things that might seem like basics.
Here is a python API call for the openai module that includes a function definition for the AI, which I’ve written in a more “example” style.
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=123,
messages=[
{
"role": "system",
"content": 'You are Bob the friendly AI.'
},
{
"role": "user",
"content": 'Hello Bob.'
}
],
functions=[
{
"name": "my_function_name",
"description": "Description of function",
"parameters": {
"type": "object",
"properties": {
"my_property1": {
"type": "string",
"description": "description of function property 1: string"
},
"my_property2": {
"type": "string",
"enum": ["enum_yes", "enum_no"],
"description": "description of function property 2: string w enum"
},
},
"required": ["my_property1"],
},
}
],
function_call="auto",
)
To replicate its function using arrays and JSON mashers in other languages, you can examine the bytestream produced:
b'{"model": "gpt-3.5-turbo", "max_tokens": 123, "messages": [{"role": "system", "content": "You are Bob the friendly AI."}, {"role": "user", "content": "Hello Bob."}], "functions": [{"name": "my_function_name", "description": "Description of function", "parameters": {"type": "object", "properties": {"my_property1": {"type": "string", "description": "description of function property 1: string"}, "my_property2": {"type": "string", "enum": ["enum_yes", "enum_no"], "description": "description of function property 2: string w enum"}}, "required": ["my_property1"]}}], "function_call": "auto"}'
which when formatted as pretty JSON lets us see that python list and dictionary structures are very like schema-compliant JSON:
{
"model": "gpt-3.5-turbo",
"max_tokens": 123,
"messages": [
{
"role": "system",
"content": "You are Bob the friendly AI."
},
{
"role": "user",
"content": "Hello Bob."
}
],
"functions": [
{
"name": "my_function_name",
"description": "Description of function",
"parameters": {
"type": "object",
"properties": {
"my_property1": {
"type": "string",
"description": "Description of function property 1: string"
},
"my_property2": {
"type": "string",
"enum": ["enum_yes", "enum_no"],
"description": "Description of function property 2: string with enum"
}
},
"required": ["my_property1"]
}
}
],
"function_call": "auto"
}
I’ll let you find my speling mistaks.