openAIFunctionTool
inline fun <ARGS, R> openAIFunctionTool(name: String, description: String? = null, strict: Boolean? = null, allowedCallers: List<OpenAIAllowedCallers?> = emptyList(), async: Boolean? = null, deferLoading: Boolean? = null, outputSchema: JsonObject? = null, noinline block: (ARGS) -> R): OpenAIFunctionTool<ARGS, R>
Creates an OpenAIFunctionTool from a lambda.
Return
An OpenAIFunctionTool instance.
Parameters
name
The tool's name.
description
A human-readable description of what the tool does.
strict
Whether to enforce strict schema adherence.
allowedCallers
List of allowed callers, or empty for all.
async
Whether the tool executes asynchronously.
deferLoading
Whether to defer tool loading.
outputSchema
Optional JSON schema for the tool's output.
block
The function to execute when the tool is called.
Type Parameters
ARGS
The type of the tool's input arguments.
R
The return type of the tool's execution.
See also
Samples
// Creating a data class for tool arguments
@Serializable
data class CreateTaskArgs(
@ToolParam(description = "Title of the task to be saved") val taskName: String,
@ToolParam(description = "Description of the task to be saved") val taskDescription: String,
)
// Create a tool using dsl.
val createTaskTool = openAIFunctionTool<CreateTaskArgs, String>(
name = "create_task",
description = "Create a new task",
) { args ->
// Save task...
"Task with name ${args.taskName} successfully created!"
}
// Send request to OpenAI or use...Content copied to clipboard