Typo in OpenAI API Documentation

I found a typo in OpenAI API Documentation. It’s actually in Example Code for Function Calling in openai. Here Link to section. It won’t cause any kind of runtime issues.

In line 54, variable is named as fuction_to_call instead of function_to_call .

Another Doubt to ask while asking this question, Is there any way to change Programming Language in Example Code? I can’t find any ways to it.

Thanks in advance

2 Likes

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.

There is indeed!

They removed the “fun” from function-calling.

1 Like

giphy

1 Like