Che
July 12, 2023, 4:49am
1
Use OpenAI’s example ,if I want get the weather of Boston, New York,…etc in one conversation, like this [{ “city”,“Boston”, “weatherIs”,“”, }, { “city”,“New York”, “weatherIs”,“”, }, … ]
Is this possible?
I tried to tell OpenAI in prompt to give divided answer ,but its not works.Its always get the weather of first city.
Maybe ask for a city list object?
{“name”:“city list”, “data” : [{ “city”,“Boston”, “weatherIs”,“”, }, { “city”,“New York”, “weatherIs”,“”, }, … ]}
1 Like
You can update the get_weather
function to use array
for locations:
{
name: 'get_weather',
description: 'Get weather from given location',
parameters: {
type: 'object',
properties: {
locations: {
type: 'array',
items: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'The city, place or location, e.g. San Juan, Puerto Rico'
}
}
}
}
},
required: ['locations']
}
}
A sample response is:
{
role: 'assistant',
content: null,
function_call: {
name: 'get_weather',
arguments: '{\n' +
' "locations": [\n' +
' {\n' +
' "name": "Boston"\n' +
' },\n' +
' {\n' +
' "name": "New York"\n' +
' }\n' +
' ]\n' +
'}'
}
}
Then you can return the weather in both cities back in this format:
{
role: "function",
name: "get_weather",
content: JSON.stringify({
locations: [
{name: "Boston", weatherIs: "Sunny"},
{name: "New York", weatherIs: "Cloudy"}
]
})
}
2 Likes
Che
July 12, 2023, 1:22pm
5
Thanks,guys.
I realized the key is json scheme.