GoogleCloudPlatform / generative-ai

Sample code and notebooks for Generative AI on Google Cloud, with Gemini on Vertex AI
https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview
Apache License 2.0
6.37k stars 1.66k forks source link

[Bug]: Grounding/Tools seems down #631

Closed haggman closed 2 months ago

haggman commented 2 months ago

File Name

gemini/grounding/intro-grounding-gemini.ipynb

What happened?

On the Cloud Insiders email list, someone reported a bug he was running into while working on a web search grounding example. His issue is over here if you'd like to see. I remembered a working notebook in this repo (the one I'm reporting) which did the same thing, so I thought I'd do some research. Looks like your notebook is throwing the same error as his. I'm guessing there's a change happening in the API, but that's only a guess.

Relevant log output

---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/google/api_core/grpc_helpers.py:65, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
     64 try:
---> 65     return callable_(*args, **kwargs)
     66 except grpc.RpcError as exc:

File /opt/conda/lib/python3.10/site-packages/grpc/_channel.py:1176, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
   1170 (
   1171     state,
   1172     call,
   1173 ) = self._blocking(
   1174     request, timeout, metadata, credentials, wait_for_ready, compression
   1175 )
-> 1176 return _end_unary_response_blocking(state, call, False, None)

File /opt/conda/lib/python3.10/site-packages/grpc/_channel.py:1005, in _end_unary_response_blocking(state, call, with_call, deadline)
   1004 else:
-> 1005     raise _InactiveRpcError(state)

_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:173.194.206.95:443 {created_time:"2024-04-27T15:32:54.340693988+00:00", grpc_status:3, grpc_message:"Request contains an invalid argument."}"
>

The above exception was the direct cause of the following exception:

InvalidArgument                           Traceback (most recent call last)
Cell In[6], line 3
      1 tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
----> 3 response = model.generate_content(PROMPT, tools=[tool])
      5 display(Markdown(response.candidates[0].text))
      7 response

File /opt/conda/lib/python3.10/site-packages/vertexai/generative_models/_generative_models.py:405, in _GenerativeModel.generate_content(self, contents, generation_config, safety_settings, tools, tool_config, stream)
    397     return self._generate_content_streaming(
    398         contents=contents,
    399         generation_config=generation_config,
   (...)
    402         tool_config=tool_config,
    403     )
    404 else:
--> 405     return self._generate_content(
    406         contents=contents,
    407         generation_config=generation_config,
    408         safety_settings=safety_settings,
    409         tools=tools,
    410         tool_config=tool_config,
    411     )

File /opt/conda/lib/python3.10/site-packages/vertexai/generative_models/_generative_models.py:494, in _GenerativeModel._generate_content(self, contents, generation_config, safety_settings, tools, tool_config)
    469 """Generates content.
    470 
    471 Args:
   (...)
    485     A single GenerationResponse object
    486 """
    487 request = self._prepare_request(
    488     contents=contents,
    489     generation_config=generation_config,
   (...)
    492     tool_config=tool_config,
    493 )
--> 494 gapic_response = self._prediction_client.generate_content(request=request)
    495 return self._parse_response(gapic_response)

File /opt/conda/lib/python3.10/site-packages/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py:2102, in PredictionServiceClient.generate_content(self, request, model, contents, retry, timeout, metadata)
   2099 self._validate_universe_domain()
   2101 # Send the request.
-> 2102 response = rpc(
   2103     request,
   2104     retry=retry,
   2105     timeout=timeout,
   2106     metadata=metadata,
   2107 )
   2109 # Done; return the response.
   2110 return response

File /opt/conda/lib/python3.10/site-packages/google/api_core/gapic_v1/method.py:113, in _GapicCallable.__call__(self, timeout, retry, *args, **kwargs)
    110     metadata.extend(self._metadata)
    111     kwargs["metadata"] = metadata
--> 113 return wrapped_func(*args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/google/api_core/grpc_helpers.py:67, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
     65     return callable_(*args, **kwargs)
     66 except grpc.RpcError as exc:
---> 67     raise exceptions.from_grpc_error(exc) from exc

InvalidArgument: 400 Request contains an invalid argument.

Code of Conduct

haggman commented 2 months ago

OH! FYI, the InvalidArgument: 400 Request contains an invalid argument. is also thrown if you use the JSON and curl the service directly.

haggman commented 2 months ago

Bet this is a me issue. I see not that the grounding in Google Search feature is still allow-list only. I just did the form to request access. Will try again in a day or three.

holtskinner commented 2 months ago

Same issue as #536

You need to accept the additional Terms of Service for Grounding with Google Search in Gemini. You can find this in Vertex AI Studio:

C3JyXYQzMtPySSv

And you can access the form directly here:

https://docs.google.com/forms/d/e/1FAIpQLSfj7SJNAqXOe7vB9Re-WtwJedTWjHkBKZ6OHaLoGoXRG93ymg/viewform

I'll update the notebook to include this step.

Originally posted by @holtskinner in https://github.com/GoogleCloudPlatform/generative-ai/issues/536#issuecomment-2051998134