I found a working solution. I first make a call to gpt to process the user message:
{
"type": "function",
"function": {
"name": "process_user_message",
"description": "Analyzes user message and adds content to it that will help GPT understand how to process it in the next call.",
"parameters": {
"type": "object",
"properties": {
"num_segments":{
"type":"integer",
"description": "Number of cities in the request"
},
},
"required": ["num_cities"]
}
}
},
def process_user_message(self, num_cities=1):
# create a dictionary with user_message and num_cities
data = {
"user_message": self.user_message,
"num_cities": num_cities
}
# convert the dictionary to a JSON string and return it
json_string = json.dumps(data)
print(json_string)
return json.dumps(data)
I then use the num_cities value to loop over chat completions:
for i in range(0,num_cities):
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"},
},
)