callable Function
Makes a CallableFunction from a function that takes no parameters.
fun currentTime(): String = ...
val getTime = callableFunction("current_time", handler = ::currentTime)Parameters
what the model refers to this function by.
what the function does, so the model knows when to ask for it.
the function to run when the model asks for it.
Makes a CallableFunction from a function that takes one parameter.
fun getWeather(city: String): String = ...
val weather = callableFunction("get_weather", paramName = "city", handler = ::getWeather)Parameters
what the model refers to this function by.
what the function does, so the model knows when to ask for it.
the name the model sends the argument under. Required, because a function's own parameter names cannot be read back at runtime.
the function to run when the model asks for it.
Makes a CallableFunction from a function that takes two parameters.
fun getForecast(city: String, days: Int): String = ...
val forecast =
callableFunction("get_forecast", paramNames = listOf("city", "days"), handler = ::getForecast)Parameters
what the model refers to this function by.
what the function does, so the model knows when to ask for it.
the names the model sends the arguments under, in the order the function declares them.
the function to run when the model asks for it.
Makes a CallableFunction from a function that takes three parameters.
For a function with more parameters than this, take a single @Serializable class holding them instead.
fun route(from: String, to: String, metric: Boolean): String = ...
val plan =
callableFunction(
"plan_route",
paramNames = listOf("from", "to", "metric"),
handler = ::route,
)Parameters
what the model refers to this function by.
what the function does, so the model knows when to ask for it.
the names the model sends the arguments under, in the order the function declares them.
the function to run when the model asks for it.
Makes a CallableFunction from a function that takes one @Serializable class of parameters.
The class's fields are the parameters, so no names are needed. Use Describe to document them.
@Serializable
data class PlanTripArgs(
@Describe("Departure city.") val origin: String,
@Describe("Number of nights to stay.") val nights: Int = 2,
)
val planTrip = callableFunction("plan_trip") { args: PlanTripArgs ->
"Trip from ${args.origin} for ${args.nights} nights"
}Parameters
what the model refers to this function by.
what the function does, so the model knows when to ask for it.
the function to run when the model asks for it.