Perhaps this is obvious to some, but I was working with function call capability to get the latitude and longitude from a mailing address using the Nomanitim API.
Initially, I used the following to define my function which I named get_coordinates:
completion = openai.ChatCompletion.create(
model="gpt-4-0613",
messages=[{"role": "user", "content": my_prompt}],
functions=[
{
"name": "get_coordinates",
"description": "Get the latitude and longitude of a mailing address",
"parameters": {
"type": "object",
"properties": {
"address": {
"type": "string",
"description": "The mailing address to be located",
},
},
"required": ["address"],
},
}
],
function_call="auto",
) code here
This worked well, for prompts where only a single address was part of the prompt. For example,
“Find the location of 123 Main Street, Anytown, Ontario Canada”, but if I used prompt, “Find the location for the following addresses: 123 Main Street, Anytown, Ontario Canada, 456 Second Street, Anytown, Ontario” , only the first address would be pulled as an argument, the second was ignored.
My solution was as follows:
completion = openai.ChatCompletion.create(
model="gpt-4-0613",
messages=[{"role": "user", "content": my_prompt}],
functions=[
{
"name": "get_coordinates",
"description": "Get the latitude and longitude of multiple mailing addresses",
"parameters": {
"type": "object",
"properties": {
"addresses": {
"type": "array",
"description": "The mailing addresses to be located",
"items": {
"type": "string"
}
}
},
"required": ["addresses"]
}
}
],
function_call="auto",
)
By changing the definition from a string to an array of strings, I could now put any number of addresses in my prompt and extract them to do my function calls.