Hi there, I’m using the Function-Calling feature to make applications, and I wonder if I can define the schema of function’s return value. As I go through the official doc and haven’t found the way to define it, but I can successfully request the API with function schema has a returns
field:
{
"name": "...",
"description": "...",
"parameters": {...},
"returns": {
"type": "object",
"properties": {...}
}
}
So I’d like to know whether such a schema with returns
can effect the next response, or is there any method we can tell the GPT about the return schema of a function?
Hi and welcome to the forum!
The model will return a json string that contains the parameters you set in your function definition, it will not call the function or interact with your code in any way. It is up to you to handle the model returning a function stop reason and to then act on it.
What I think they are actually asking, and I’m also wondering, is if there is any benefit of including a returns field. Considering it adds more context for the model it might might help it choose the correct action to take (calling a certain function or not). I’m thinking it could also improve the next completion if the assistant response (with the function args) is added to the messages together with the corresponding function msg is included in the next list of messages.
messages_1 = [
{
"role": "user",
"content": "A user message requiring a response from a function",
}
]
functions_1 = {
"name": "example_function",
"description": "...",
"parameters": {...},
"returns": {
"type": "string",
"description": "A description of the function's return value that adds more context for the model."
}
}
messages_2 = [
{
"role": "user",
"content": "A user message requiring a response from a function",
},
{
"role": "assistant",
"content": "",
"function_call": {
"name": "example_function",
"arguments": "a input as specified in the parameters field",
}
},
{
"role": "function",
"name": "example_function",
"content": "a function response as specified in the returns field",
}
]
Anyway I’m wondering if anyone has tried it and what their results were.