Dichiarazione di funzione di classe (1.50.0)

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

Una rappresentazione della dichiarazione di una funzione.

Utilizzo: crea la dichiarazione della funzione e lo strumento:

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"
        ]
    },
)
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"},
        }
    ),
))
```

Metodi

FunctionDeclaration

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

Crea una FunctionDeclaration.