Skip to content

Instantly share code, notes, and snippets.

@svpino
Created June 16, 2023 13:19
Show Gist options
  • Save svpino/e6748c5f40875beb542a65150e1d4a5e to your computer and use it in GitHub Desktop.
Save svpino/e6748c5f40875beb542a65150e1d4a5e to your computer and use it in GitHub Desktop.
OpenAI's API undocumented function calling python
import openai
openai.api_key = "YOUR KEY GOES HERE"
def get_completion(messages):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=messages,
functions=[{
"name": "fake",
"description": "This is a fake function.",
"parameters": { "type": "object", "properties": {} },
}],
temperature=0,
)
return response
messages = [
{
"role": "system",
"content": (
"I'll give you a list of numbers. Compute their average. "
"Call a python function to do this."
),
},
{"role": "user", "content": "7 28 1 4 2 98 15"},
]
response = get_completion(messages)
exec(response["choices"][0]["message"].function_call.arguments)
compute_average(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment