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
7.29k stars 1.98k forks source link

[Bug]: _InactiveRPCError (Permission Denied on resource project) when running `gemini_inference(<prompt input>)` #622

Closed rossdanlm closed 6 months ago

rossdanlm commented 6 months ago

File Name

generative-ai/gemini/use-cases/retrieval-augmented-generation/small_to_big_rag/small_to_big_rag.ipynb

What happened?

As a workaround from https://github.com/GoogleCloudPlatform/generative-ai/issues/621, I removed the chat arg and tried to run it with prompt only, but get the following error. Please let me know if I need to provide additional logging or how I can get unblocked, thanks

Screenshot 2024-04-25 at 12 07 32

Relevant log output

{
    "name": "PermissionDenied",
    "message": "403 Permission denied on resource project YOUR-PROJECT-ID. [links {
  description: \"Google developers console\"
  url: \"https://console.developers.google.com\"
}
, reason: \"CONSUMER_INVALID\"
domain: \"googleapis.com\"
metadata {
  key: \"service\"
  value: \"aiplatform.googleapis.com\"
}
metadata {
  key: \"consumer\"
  value: \"projects/YOUR-PROJECT-ID\"
}
]",
    "stack": "---------------------------------------------------------------------------
_InactiveRpcError                         Traceback (most recent call last)
File ~/.pyenv/versions/3.11.6/lib/python3.11/site-packages/google/api_core/grpc_helpers.py:76, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
     75 try:
---> 76     return callable_(*args, **kwargs)
     77 except grpc.RpcError as exc:

File ~/.pyenv/versions/3.11.6/lib/python3.11/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 ~/.pyenv/versions/3.11.6/lib/python3.11/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:
\tstatus = StatusCode.PERMISSION_DENIED
\tdetails = \"Permission denied on resource project YOUR-PROJECT-ID.\"
\tdebug_error_string = \"UNKNOWN:Error received from peer ipv4:142.250.65.202:443 {created_time:\"2024-04-25T12:04:50.733881-04:00\", grpc_status:7, grpc_message:\"Permission denied on resource project YOUR-PROJECT-ID.\"}\"
>

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

PermissionDenied                          Traceback (most recent call last)
Cell In[9], line 1
----> 1 gemini_inference(\"hello world!\")

Cell In[8], line 2, in gemini_inference(prompt)
      1 def gemini_inference(prompt: str) -> str:
----> 2     text_response = model.generate_content(prompt)
      3     return text_response.text

File ~/.pyenv/versions/3.11.6/lib/python3.11/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 ~/.pyenv/versions/3.11.6/lib/python3.11/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 ~/.pyenv/versions/3.11.6/lib/python3.11/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 ~/.pyenv/versions/3.11.6/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py:131, in _GapicCallable.__call__(self, timeout, retry, compression, *args, **kwargs)
    128 if self._compression is not None:
    129     kwargs[\"compression\"] = compression
--> 131 return wrapped_func(*args, **kwargs)

File ~/.pyenv/versions/3.11.6/lib/python3.11/site-packages/google/api_core/grpc_helpers.py:78, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
     76     return callable_(*args, **kwargs)
     77 except grpc.RpcError as exc:
---> 78     raise exceptions.from_grpc_error(exc) from exc

PermissionDenied: 403 Permission denied on resource project YOUR-PROJECT-ID. [links {
  description: \"Google developers console\"
  url: \"https://console.developers.google.com\"
}
, reason: \"CONSUMER_INVALID\"
domain: \"googleapis.com\"
metadata {
  key: \"service\"
  value: \"aiplatform.googleapis.com\"
}
metadata {
  key: \"consumer\"
  value: \"projects/YOUR-PROJECT-ID\"
}
]"
}

Code of Conduct

holtskinner commented 6 months ago

Based on the log output:

 "403 Permission denied on resource project YOUR-PROJECT-ID.

It looks like you didn't input your own Project ID and left the placeholder in.