Hello Community,
I want to share my insights in how to call multiple functions within one function API call.
This is the function API schema I use:
{
"name": "multi_Func",
"description": "Call two functions in one call",
"parameters": {
"type": "object",
"properties": {
"get_Weather": {
"name": "get_Weather",
"description": "Get the weather for the location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
}
},
"required": ["location"],
}
},
"get_Events": {
"name": "get_Events",
"description": "Get events for the location at specified date",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"date": {
"type": "string",
"description": "The date of the event, e.g. 2021-01-01."
}
},
"required": ["location", "date"],
}
}
}, "required": ["get_Weather", "get_Events"],
}
}
- Scenario 1: User asks: âGet the events for San Francisco at 25th May 2023.â Response:
'function_call': {'name': 'multi_Func', 'arguments': '{\n "get_Weather": null,\n "get_Events": {\n "location": "San Francisco",\n "date": "2023-05-25"\n }\n}'}}, 'finish_reason': 'function_call'}
You see, that the function call to get_Weather
is null. Scenario 2: User asks: âGet the weather for San Franciso.â Response:
'function_call': {'name': 'multi_Func', 'arguments': '{\n "get_Weather": {\n "location": "San Francisco"\n },\n "get_Events": null\n}'}}
Here the get_Events
is null Scenario 3: User asks: âGet the weather for San Francisco and the events for May 25th 2023.â Response:
'function_call': {'name': 'multi_Func', 'arguments': '{\n "get_Weather": {\n "location": "San Francisco"\n },\n "get_Events": {\n "date": "2023-05-25",\n "location": "San Francisco"\n }\n}'}}
You get both functions called.
It is not calling the function_call
twice, but it emulates it.