FunctionCall

data class FunctionCall(var name: String, var arguments: String, var output: String? = null)

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.

Constructors

Link copied to clipboard
constructor(name: String, arguments: String, output: String? = null)

Functions

Link copied to clipboard
fun tryParseArguments(tools: List<Tool>? = null): Map<String, JsonNode>

Attempts to parse the arguments passed to the function.

Properties

Link copied to clipboard

The raw json representation of the arguments

Link copied to clipboard

The name of the function which was called

Link copied to clipboard

The result of the function call if it has been set, only used for Assistants. You should not set this.