I created a assistant which must call a function in order to retrieve data from a film via the IMDB API. The function needs two parameters: the movie name and the year the movie was released. When I give the assistant a movie name, it calls the function without asking me its year. How to correct this?
{
"name" : "get_data_movie",
"description": "retrieve information from a movie",
"parameters" : {
"type" : "object",
"properties": {
"title": {
"type": "string",
"description": "The name of the movie"
},
"year" : {
"type" : "string",
"description": "year of movie release",
"format": "year"
}
},
"required" : ["title", "year"]
}
}
The quick answer is that by adding the following prompt as part of functionâs âdescriptionâ, I have gotten the system to always submit all parameters:
ALWAYS respond with values for all parameters in this tool.
The longer answer is that the system itself can help you fix this in the future. Whenever the system makes these mistakes I have found that sending a prompt like the following start giving me solutions, even if it takes a few iterations to get right.
You called the get_data_movie function by only submitting the movieâs title, but not the year it was released. How can I change the function description to avoid this mistake in the future?
agree with @sdelgado - you can simply RETURN the error message in words from your get_data_movie() function as well something like {âerrorâ:âNo year provided try again with both year and titleâ}
This will result in another tool_call.
Also in the function description you can be more descriptive - âfind movie information based on title and year. Both title and year are mandatoryâ
@jlvanhulstâs idea of adding an error message in the return is great! OpenAIâs model is hopefully smart enough to retry with the right parameters. @graine.de.zele, if you would like to add a âbest-practiceâ tag to this thread, I think it would be a useful reference for people in the future.
@cdonvd0s , @jlvanhulst, sdelgado Thank you for your responses, but unfortunately, I have already tried all of that without success:
The idea of adding an error message in the return does not work because the assistant chooses the year itself. Itâs a strange behavior because if I ask for information about a movie that has had several versions, it itself sends a year as a parameter.
I also tried modifying the description that you advised me: âyear of movie release as given by the userâ But this has no impact, the assistant continues to provide the year itself.
I tried insisting in different ways to make the assistant understand that it must obtain both parameters from the client to call the function, but it only asks for the name of the movie and always makes up the year.
Description for the assistant :
Your goal is to provide information about movies. Your information must come only from the âget_data_movieâ function. This function needs two mandatory parameters: the name of the movie and the year of the movie. IMPORTANT: You must always obtain these two pieces of data from the user to call the âget_data_movieâ function. You must not choose the year of the movie yourself.
{
"name": "get_data_movie",
"parameters": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The name of the movie"
},
"year": {
"type": "string",
"description": "year of movie release as given by the user",
"format": "year"
}
},
"required": [
"title",
"year"
]
},
"description": "Recover movie data"
}
I am surprised you donât get an error for the âformatâ : âyearâ because I donât think that is correct.
What I am also wondering - are you actually returning an âerror mesageâ - need to provide year when it calls the function with the year?
Well the function format is checked for errors these days - and things like âtypeâ are certainly checked. One thing I would change in the function desccription is 'retrieve movie data by providing title and year, both are mandatory.
And what I meant is - IF gpt calls the function without the year - what do you RETURN - it should be something like {âDescriptionâ: âError you must provide the year of the movie as wellâ} - that will tell it to ask for the year and try again.
I put the same prompt as you and the assistant does not ask me the year. Yet we have the same assistant with the same descriptions and the same function. I do not understand anything anymoreâŚ
GPT never calls the function without the year since it is it which invents the year. It is therefore impossible to generate an error. To generate an error GPT would have to call the function without providing the year but it provided it to the function without asking the user
I just did a trial run for you, with gpt-4 turbo with this prompt:
:You are a movie database - you provide information about movies by looking up data with the get_data_movie function. You cannot rely on any other information for the input of this function. The user has to provide both title and year before you can submit information to get_data_mvoie. Do not âinventâ the year if the user did not provide it"
I made the changes you recommended but unfortunately it didnât change anything. GPT still refuses to ask me the year, he prefers to choose it himselfâŚ
In my screenshot you can see that GPT chose to send the year 1995 without me giving it this information.
I donât understand why @cdonvd0s behaves differently from mine
{
"name": "get_data_movie",
"description": "Recover movie data",
"parameters": {
"type": "object",
"properties": {
"title": {
"type": "string",
"description": "The name of the movie"
},
"year": {
"type": "string",
"description": "year of movie release as given by the user"
}
},
"required": [
"title",
"year"
]
}
}
Itâs good, it works!!! I did all my tests on the same thread, I think I need to run a new thread to be sure that GPT takes the modifications into account. Thank you very much for taking the time to help me!