Class FunctionDeclaration (1.74.0)

FunctionDeclaration(
    *,
    name: str,
    parameters: typing.Dict[str, typing.Any],
    description: typing.Optional[str] = None,
    response: typing.Optional[typing.Dict[str, typing.Any]] = None
)

A representation of a function declaration.

Usage: Create function declaration and tool:

get_current_weather_func = generative_models.FunctionDeclaration(
    name="get_current_weather",
    description="Get the current weather in a given location",
    parameters={
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA"
            },
            "unit": {
                "type": "string",
                "enum": [
                    "celsius",
                    "fahrenheit",
                ]
            }
        },
        "required": [
            "location"
        ]
    },
    # Optional:
    response={
        "type": "object",
        "properties": {
            "weather": {
                "type": "string",
                "description": "The weather in the city"
            },
        },
    },
)
weather_tool = generative_models.Tool(
    function_declarations=[get_current_weather_func],
)
```
Use tool in `GenerativeModel.generate_content`:
```
model = GenerativeModel("gemini-pro")
print(model.generate_content(
    "What is the weather like in Boston?",
    # You can specify tools when creating a model to avoid having to send them with every request.
    tools=[weather_tool],
))
```
Use tool in chat:
```
model = GenerativeModel(
    "gemini-pro",
    # You can specify tools when creating a model to avoid having to send them with every request.
    tools=[weather_tool],
)
chat = model.start_chat()
print(chat.send_message("What is the weather like in Boston?"))
print(chat.send_message(
    Part.from_function_response(
        name="get_current_weather",
        response={
            "content": {"weather_there": "super nice"},
        }
    ),
))
```

Methods

FunctionDeclaration

FunctionDeclaration(
    *,
    name: str,
    parameters: typing.Dict[str, typing.Any],
    description: typing.Optional[str] = None,
    response: typing.Optional[typing.Dict[str, typing.Any]] = None
)

Constructs a FunctionDeclaration.