Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save hustxiayang/5262978670d983f74885d07d75489ad4 to your computer and use it in GitHub Desktop.

Select an option

Save hustxiayang/5262978670d983f74885d07d75489ad4 to your computer and use it in GitHub Desktop.
from vertexai.generative_models._generative_models import (
Content,
#ContentsType,
GenerativeModel,
Part,
Tool,
FunctionDeclaration,
)
model = GenerativeModel("gemini-2.0-flash-001")
parallel_tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city to find the weather for, "
"e.g. 'San Francisco'",
},
"state": {
"type": "string",
"description": "must the two-letter abbreviation for the state "
"that the city is in, e.g. 'CA' which would "
"mean 'California'",
},
"unit": {
"type": "string",
"description": "The unit to fetch the temperature in",
"enum": ["celsius", "fahrenheit"],
},
},
},
},
},
{
"type": "function",
"function": {
"name": "get_current_traffic",
"description": "Get the current traffic conditions for a specific location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g., San Francisco, CA",
},
},
"required": ["location"],
},
},
},
]
tools = to_gcp_tools(parallel_tools)
chat_response = model.generate_content(
contents=[
Content(role="model", parts=[Part.from_text("You are a helpful customer support assistant. Use the supplied tools to assist the user.")]),
Content(role="user", parts=[Part.from_text("What is the weather in Dallas, Texas in Fahrenheit and the traffic of Dallas?")]),
],
tools=tools,
stream=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment