FunctionDeclaration

public final class FunctionDeclaration


Defines a function that the model can use as a tool.

When generating responses, the model might need external information or require the application to perform an action. FunctionDeclaration 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 = FunctionDeclaration(
name = "getExchangeRate",
description = "Get the exchange rate for currencies between countries.",
parameters = mapOf(
"currencyFrom" to Schema.str("The currency to convert from."),
"currencyTo" to Schema.str("The currency to convert to.")
)
)

See the Use the Gemini API for function calling guide for more information on function calling.

See also
Schema

Summary

Public constructors

FunctionDeclaration(
    @NonNull String name,
    @NonNull String description,
    @NonNull Map<@NonNull String, @NonNull Schema> parameters,
    @NonNull List<@NonNull String> optionalParameters
)

Public constructors

FunctionDeclaration

public FunctionDeclaration(
    @NonNull String name,
    @NonNull String description,
    @NonNull Map<@NonNull String, @NonNull Schema> parameters,
    @NonNull List<@NonNull String> optionalParameters
)
Parameters
@NonNull String name

The name of the function.

@NonNull String description

The description of what the function does and its output. To improve the effectiveness of the model, the description should be clear and detailed.

@NonNull Map<@NonNull String, @NonNull Schema> parameters

The map of parameters names to their Schema the function accepts as arguments.

@NonNull List<@NonNull String> optionalParameters

The list of parameter names that the model can omit when invoking this function.