Function Call
Represents a function call by either a chat completion, or an Assistant.
When a function call is made, you MUST respond with the result of the function. This means that you should parse the arguments, call some function (an API call, getting current weather, getting a stock price, modifying a database, etc.), and sending the result of that function back.
For chat completions (OpenAI.createChatCompletion), you should send the result of the function as a com.cjcrafter.openai.chat.ChatMessage with the corresponding ToolCall.id as the function id.
For Assistants, you should use com.cjcrafter.openai.threads.runs.RunHandler.submitToolOutputs with the corresponding ToolCall.id as the tool call id. For Assistants, it is important to submit tool outputs within a timely manner, usually within 10 minutes of starting a com.cjcrafter.openai.threads.runs.Run. Otherwise, the com.cjcrafter.openai.threads.runs.Run will expire, and you will not be able to submit your tool call.
ChatGPT may hallucinate, or make up, function calls. To handle hallucinations, we have provided tryParseArguments.