Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Last active July 24, 2023 23:52
Show Gist options
  • Save john-adeojo/d5165dfd19078a6ba255951d018eca5e to your computer and use it in GitHub Desktop.
Save john-adeojo/d5165dfd19078a6ba255951d018eca5e to your computer and use it in GitHub Desktop.
import openai
def function_calling_multiple_function(API_KEY, query):
# Step 1: send the conversation and available functions to GPT
functions = [
{
"name": "get_current_news",
"description": "Get the latest news headline for a given topic",
"parameters": {
"type": "object",
"properties": {
"topic": {
"type": "string",
"description": "The news topic required "
}
},
},
"required": ["topic"],
},
{
"name": "get_temperature",
"description": "Get the temperature at a given location and date",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "Return the location cited in the query"
},
"date": {
"type": "string",
"description": "Return the date in in 'YYYY-MM-DD' format."
}
},
},
"required": ["location", "date"],
}
]
openai.api_key = API_KEY
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=[{"role": "system", "content": query}],
functions=functions,
function_call="auto", # auto is default, but we'll be explicit
)
response_message = response["choices"][0]["message"]
return response_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment