AutoFunctionDeclaration

class AutoFunctionDeclaration<I : Any, O : Any>


Defines a function that the model can use as a tool. Including a function references to enable automatic function calling.

When generating responses, the model might need external information or require the application to perform an action. AutoFunctionDeclaration provides the necessary information for the model to create a FunctionCallPart, which instructs the client to execute the corresponding function. The client then sends the result back to the model as a FunctionResponsePart.

For example

val getExchangeRate = AutoFunctionDeclaration.create(
name = "getExchangeRate",
description = "Get the exchange rate for currencies between countries.",
inputSchema = CurrencyRequest.schema,
outputSchema = CurrencyResponse.schema,
)
{
// make an api request to convert currencies and return the result
}
See also
JsonSchema

Summary

Public companion functions

AutoFunctionDeclaration<I, FunctionResponsePart>
<I : Any> create(
    functionName: String,
    description: String,
    inputSchema: JsonSchema<I>,
    functionReference: (suspend (I) -> FunctionResponsePart)?
)

Creates a strongly typed function declaration with an associated function reference.

AutoFunctionDeclaration<I, O>
<I : Any, O : Any> create(
    functionName: String,
    description: String,
    inputSchema: JsonSchema<I>,
    outputSchema: JsonSchema<O>,
    functionReference: (suspend (I) -> O)?
)

Creates a strongly typed function declaration with an associated function reference.

Public companion functions

create

fun <I : Any> create(
    functionName: String,
    description: String,
    inputSchema: JsonSchema<I>,
    functionReference: (suspend (I) -> FunctionResponsePart)? = null
): AutoFunctionDeclaration<I, FunctionResponsePart>

Creates a strongly typed function declaration with an associated function reference. This version allows an arbitrary JsonObject as output rather than a strict schema.

Parameters
functionName: String

the name of the function (to the model)

description: String

the description of the function

inputSchema: JsonSchema<I>

the object the model must provide to you as input

functionReference: (suspend (I) -> FunctionResponsePart)? = null

the function that will be executed when requested by the model

create

fun <I : Any, O : Any> create(
    functionName: String,
    description: String,
    inputSchema: JsonSchema<I>,
    outputSchema: JsonSchema<O>,
    functionReference: (suspend (I) -> O)? = null
): AutoFunctionDeclaration<I, O>

Creates a strongly typed function declaration with an associated function reference.

Parameters
functionName: String

the name of the function (to the model)

description: String

the description of the function

inputSchema: JsonSchema<I>

the object the model must provide to you as input

outputSchema: JsonSchema<O>

the type that will be return to the model when the function is executed

functionReference: (suspend (I) -> O)? = null

the function that will be executed when requested by the model.

Public properties

description

val descriptionString

functionReference

val functionReference: (suspend (I) -> O)?

inputSchema

val inputSchemaJsonSchema<I>

name

val nameString

outputSchema

val outputSchemaJsonSchema<O>?