Hi,
I am fairly new to coding and have struggled to find a way to get this working. I am trying to get this code to call both functions, but so far have only been able to return one. Would anyone be able to point out where I am going wrong?
In essence, I have two functons, get_current_weather & get_current_traffic. If ask for the weather and traffic in any given location, it will always only return the first function.
Thanks in advance.
Code extract:
def get_current_weather(location, unit=“fahrenheit”):
def get_current_traffic(location):
available_functions = {
“get_current_weather”: get_current_weather,
“get_current_traffic”: get_current_traffic,
}
tools = [
{
“name”: “get_current_weather”,
“description”: “Get the current weather in a given location”,
“parameters”: {
“type”: “object”,
“properties”: {
“location”: {
“type”: “string”,
“description”: “The city and state, e.g. San Francisco, CA”,
},
“unit”: {“type”: “string”, “enum”: [“celsius”, “fahrenheit”]},
},
“required”: [“location”],
},
},
{
"name": "get_current_traffic",
"description": "Get the current traffic in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
},
"required": ["location"],
},
},
]
response = client.chat.completions.create(
model=“gpt-4-1106-preview”,
messages=[{“role”: “user”, “content”:“what is the weather in san francisco, also could you give me the traffic?”}],
temperature=0,
functions = tools,
function_call = “auto”,
)
response_message = response.choices.function_call
print(response_message)