I have C# application where I use the ChatCompletion API to create a Chat.
I make use of the tools to call my c# methods.
On of the tools is the GetMails
function.
tools=[
{
"type": "function",
"function": {
"name": "GetMails",
"description": "The function searches for user mails.
Therefore the function must know if the aim is a summary or just to return an application program attachment that the user can open and view separately.
The required parameters are 'ContentFilter' and 'ForSummary', all the other parameters are optional.
The parameter 'ForSummary' is required and should be set to true only if the user explicitly asks for a summary of mails. Otherwise, it should be false.",
"parameters": {
"type": "object",
"properties": {
"ContentFilter": {
"type": "string",
"description": "Is a required parameter that is used as mail filter and can't be null or empty. It defines a filter for the content of the email body or mail subject."
},
"ForSummary": {
"type": "string",
"description": "Is a required parameter that is only true if the user explicitly asks for a summary of mails. Otherwise its false"
}
},
"required": ["ContentFilter", "ForSummary"]
}
}
}
]
)
The function implementation just returns a string like
3 mails found. The mails can be displayed by clicking on them.
My code works as following: i have a chatHistory object where i store all the relevant messages for the chatcompletion.
Now when i ask a question "show my mails to the topic 'easter'"
I send the chatHistory to the chatcompletion api and i get the anwer back that i should execute the GetMails
function.
So i do that and append the message to the chatHistory.
Then I send it again to the chatcompletion api.
Unfortunately GetMails
is requested over and over again what leads to a inifnite loop.
[
{
"role": "user",
"content": "show my mails to the topic 'easter'"
},
{
"role": "function",
"content": "3 mails found. The mails can be displayed by clicking on them.",
"toolCallId": "call_XPlBzWJUibX7XevY51nY8duI",
"name": "GetMails"
},
{
"role": "function",
"content": "3 mails found. The mails can be displayed by clicking on them.",
"toolCallId": "call_QawYrjqZ87rSDkwXk56rMWLL",
"name": "GetMails"
}
//..GetMails loop...
]
What I expect the chatHistory to look like is more like so:
[
{
"role": "user",
"content": "show my mails to the topic 'easter'"
},
{
"role": "function",
"content": "3 mails found. The mails can be displayed by clicking on them.",
"toolCallId": "call_XPlBzWJUibX7XevY51nY8duI",
"name": "GetMails"
},
{
"role": "assistant",
"content": "3 emails were found matching tag ostern. A mouse click opens the emails"
}
//..END...
]
What am I doing wrong?