Open expresspotato opened 1 month ago
I also get the same error for using example grounding using Google search with the example provided in this, already using vertexai version 1.51.0
import vertexai
from vertexai.generative_models import grounding
from vertexai.generative_models import GenerationConfig, GenerativeModel, Tool
# TODO(developer): Update and un-comment below line
project_id = "PROJECT ID"
vertexai.init(project=project_id, location="us-central1")
model = GenerativeModel(model_name="gemini-1.0-pro-002")
# Use Google Search for grounding
tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
prompt = "When is the next total solar eclipse in US?"
response = model.generate_content(
prompt,
tools=[tool],
generation_config=GenerationConfig(
temperature=0.0,
),
)
print(response)
error return:
_InactiveRpcError Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py](https://localhost:8080/#) in error_remapped_callable(*args, **kwargs)
71 try:
---> 72 return callable_(*args, **kwargs)
73 except grpc.RpcError as exc:
7 frames
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.INVALID_ARGUMENT
details = "Request contains an invalid argument."
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.251.163.95:443 {grpc_message:"Request contains an invalid argument.", grpc_status:3, created_time:"2024-05-11T14:06:26.807301202+00:00"}"
>
The above exception was the direct cause of the following exception:
InvalidArgument Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py](https://localhost:8080/#) in error_remapped_callable(*args, **kwargs)
72 return callable_(*args, **kwargs)
73 except grpc.RpcError as exc:
---> 74 raise exceptions.from_grpc_error(exc) from exc
75
76 return error_remapped_callable
InvalidArgument: 400 Request contains an invalid argument.
I also get the same error for using example grounding using Google search with the example provided in this, already using vertexai version 1.51.0
import vertexai from vertexai.generative_models import grounding from vertexai.generative_models import GenerationConfig, GenerativeModel, Tool # TODO(developer): Update and un-comment below line project_id = "PROJECT ID" vertexai.init(project=project_id, location="us-central1") model = GenerativeModel(model_name="gemini-1.0-pro-002") # Use Google Search for grounding tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval()) prompt = "When is the next total solar eclipse in US?" response = model.generate_content( prompt, tools=[tool], generation_config=GenerationConfig( temperature=0.0, ), ) print(response)
error return:
_InactiveRpcError Traceback (most recent call last) [/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py](https://localhost:8080/#) in error_remapped_callable(*args, **kwargs) 71 try: ---> 72 return callable_(*args, **kwargs) 73 except grpc.RpcError as exc: 7 frames _InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.INVALID_ARGUMENT details = "Request contains an invalid argument." debug_error_string = "UNKNOWN:Error received from peer ipv4:142.251.163.95:443 {grpc_message:"Request contains an invalid argument.", grpc_status:3, created_time:"2024-05-11T14:06:26.807301202+00:00"}" > The above exception was the direct cause of the following exception: InvalidArgument Traceback (most recent call last) [/usr/local/lib/python3.10/dist-packages/google/api_core/grpc_helpers.py](https://localhost:8080/#) in error_remapped_callable(*args, **kwargs) 72 return callable_(*args, **kwargs) 73 except grpc.RpcError as exc: ---> 74 raise exceptions.from_grpc_error(exc) from exc 75 76 return error_remapped_callable InvalidArgument: 400 Request contains an invalid argument.
Your code seems valid, but I suspect you've not agreed to the terms for grounding. See here: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-gemini
@expresspotato Can you please try putting all function declarations in a single Tool?
P.S. AFAIK, some of the most recent models might support multiple tools.
Sorry to hear about your troubles here. We've (Google DevRel) also heard reports from users who want to use different types of tools (e.g., grounding/retrieval tools along with FunctionDeclarations).
There is a related issue in the generative-ai
repo at https://github.com/GoogleCloudPlatform/generative-ai/issues/636, and they've opened an issue in the public issue tracker for Vertex AI here: https://issuetracker.google.com/issues/340729475. Feel free to add more details and/or +1 the latter issue in the public tracker to increase the signal to the product teams. Thanks!
Environment details
Steps to reproduce
Tool
objectCode example
Stack trace
Tried both tools on their own and the response is fine.