I have the following function:
tools = [
{
"type": "function",
"function": {
"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"],
},
},
}
User Message:
messages = [{"role": "user", "content": "What's the weather like in San Francisco, Tokyo, and Paris?"}]
If I have tool_choice as auto I get multiple tool_calls and the response I am looking for (albeit everyone in San Francisco is burning alive):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
tools=tools,
tool_choice="auto"
#tool_choice={
# "type": "function",
# "function": {"name": "get_current_weather"},
#},
)
{"location": "San Francisco", "temperature": "72", "unit": "celsius"}
{"location": "Tokyo", "temperature": "10", "unit": "celcius"}
{"location": "Paris", "temperature": "22", "unit": "celsius"}
When I am explicate on the function that I want to use, I only get one function call, and only get the weather for San Francisco:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
tools=tools,
#tool_choice="auto"
tool_choice={
"type": "function",
"function": {"name": "get_current_weather"},
},
)
{"location": "San Francisco", "temperature": "72", "unit": "celsius"}
Auto is not an option in my use case. Neither is only one function call for most prompts.
Has anyone experienced this behavior? How did you work around it?