-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GenAI - Automatic Function Calling feature
The Automatic Function Calling (AFC) feature automates the function calling handling. AFC reduces manual user steps when using Function Calling. AFC makes it easy to use native functions (e.g. Python) with the Function Calling feature. AFC makes it possible for the user to instruct the SDK to let the model call the user-provided functions automatically. AFC can be enabled when starting a chat. Usage: ```python from vertexai.preview.generative_models import GenerativeModel, FunctionCallingConfig, FunctionDeclaration, Tool # Some function that the model will be able to call def get_current_weather(location: str, unit: str = "centigrade"): """Gets weather in the specified location. Args: location: The location for which to get the weather. unit: Optional. Temperature unit. Can be Centigrade or Fahrenheit. Defaults to Centigrade. Returns: The weather information as a dict. """ # Add actual implementation. return dict( location=location, unit=unit, weather="Super nice, but maybe a bit hot.", ) # AFC feature 1: Automatically creating function declaration and schema from a Python function: get_current_weather_declaration = FunctionDeclaration.from_func(get_current_weather) weather_tool = Tool([get_current_weather_declaration]) fc_model = GenerativeModel("gemini-pro", tools=[weather_tool]) # AFC feature 2: Activating the Automatic Function Calling afc_responder = AutomaticFunctionCallingResponder( # Optional: max_number_of_automatic_function_calls=5, ) chat = model.start_chat(responder=afc_responder) # Using the AFC-enabled chat fc_chat.send_message("What is the weather like in Boston?") # With AFC, send_message returns the final model answer rather than `function_call` that the user has to handle. # Notice how the model slightly changes the function response to incorporate it in the final answer. ``` PiperOrigin-RevId: 620189258
- Loading branch information
Showing
5 changed files
with
376 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.