Last active
July 24, 2023 23:50
-
-
Save john-adeojo/e1fa30768a34a2086f05e160f5123dd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def function_calling_one_function(API_KEY, query): | |
# Step 1: send the conversation and available functions to GPT | |
functions = [ | |
{ | |
"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