functions:
“functions”: [
{
“parameters”: {
“type”: “object”,
“properties”: {
“region”: {
“type”: “string”
}
},
“required”: [
“region”
]
},
“name”: “get_weather”,
“description”: “Get weather”
},
{
“parameters”: {
“type”: “object”,
“properties”: {
“region”: {
“type”: “string”
}
},
“required”: [
“region”
]
},
“name”: “get_coordinate”,
“description”: “Get coordinates”
},
{
“parameters”: {
“type”: “object”,
“properties”: {
“region”: {
“type”: “string”
}
},
“required”: [
“region”
]
},
“name”: “get_population”,
“description”: “Get population”
}
]
First messages input:
[{
“role”: “user”,
“content”: “Coordinates and weather in Beijing”
}]
First response:
{
“role”: “assistant”,
“content”: null,
“function_call”: {
“name”: “get_coordinate”,
“arguments”: “{\n"region”: “Beijing”\n}"
}
}
Second messages input:
[{
“role”: “user”,
“content”: “Coordinates and weather in Beijing”
},
{
“role”: “assistant”,
“content”: null,
“function_call”: {
“name”: “get_coordinate”,
“arguments”: “{\n"region”: “Beijing”\n}"
}
},
{
“role”: “function”,
“name”: “get_coordinate”,
“content”: “{“longitude”:“115°25’ to 117°30’”,“latitude”:“39°26’ to 41°03’”}”
}]
Second response:
{
“role”: “assistant”,
“content”: null,
“function_call”: {
“name”: “get_weather”,
“arguments”: “{\n"region”: “Beijing”\n}"
}
}
Third messages input:
[
{
“role”: “user”,
“content”: “Coordinates and weather in Beijing”
},
{
“role”: “assistant”,
“content”: null,
“function_call”: {
“name”: “get_coordinate”,
“arguments”: “{\n"region”: “Beijing”\n}"
}
},
{
“role”: “function”,
“name”: “get_coordinate”,
“content”: “{“longitude”:“115°25’ to 117°30’”,“latitude”:“39°26’ to 41°03’”}”
},
{
“role”: “assistant”,
“content”: null,
“function_call”: {
“name”: “get_weather”,
“arguments”: “{\n"region”: “Beijing”\n}"
}
},
{
“role”: “function”,
“name”: “get_weather”,
“content”: “{“weather”:“Heavy rain”}”
}
]
Third response:
{
“role”: “assistant”,
“content”: “The coordinates of Beijing are longitude 115°25’ to 117°30’, latitude 39°26’ to 41°03’. The current weather is heavy rain.”
}
During the interaction, to avoid making the user wait when answering their question, we pass the parameter “stream”: true when calling the GPT API. GPT then streams the response to us, and we relay this stream to the frontend. However, when retrieving the function name based on the user’s question, we do not need to use the streaming method. In this process, “stream”: false should be set.
We are currently unable to obtain a SIGNAL indicating that there is no matching function available. When there is no matching function, GPT provides an answer to the question. If we wait at this step and send the answer to the user, the response time is uncertain, which is not user-friendly. Therefore, we would like to use the streaming method to provide the final result to the user, but without using the streaming method when retrieving the function name.