I am trying to use the PredictionServiceClient from aiplatform package. But I am getting this error:
google.api_core.exceptions.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: "consumer"
value: "projects/YOUR_PROJECT_ID"
}
metadata {
key: "service"
value: "aiplatform.googleapis.com"
}
]
Code snippet:
project_id = "positive-tempo-405405"model_id = "textembedding-gecko@latest" # or another model IDlocation = "us-central1"instance_id = 'YOUR_INSTANCE_ID'database_id = 'YOUR_DATABASE_ID'
def create_vector_represenation(text): # Initialize the client text_to_text_client = vertex_ai.gapic.PredictionServiceClient(client_options={"api_endpoint": "us-central1-aiplatform.googleapis.com"})
# Get Vector Representation # Create the endpoint for the model endpoint = f"projects/{project_id}/locations/{location}/models/{model_id}" # Create the request payload instances = [{"content": text}] # Make the prediction request response = text_to_text_client.predict(endpoint=endpoint, instances=instances) # The response contains the embeddings in the `predictions` field vector_representation = response.predictions[0]["embeddings"]["values"] st.write('vector_representation: ', vector_representation)
return vector_representation
I checked the followings:
I have added the required policies:
{
"bindings": [
{
"members": [
"serviceAccount:[email protected]",
"user:***@gmail.com"
],
"role": "roles/aiplatform.admin"
},
{
"members": [
"serviceAccount:[email protected]"
],
"role": "roles/compute.serviceAgent"
},
{
"members": [
"serviceAccount:service-630332944972@dataflow-service-producer-prod.iam.gserviceaccount.com"
],
"role": "roles/dataflow.serviceAgent"
},
{
"members": [
"serviceAccount:[email protected]",
"serviceAccount:[email protected]"
],
"role": "roles/editor"
},
{
"members": [
"serviceAccount:[email protected]",
"user:***@gmail.com"
],
"role": "roles/ml.admin"
},
{
"members": [
"serviceAccount:[email protected]",
"user:***@gmail.com"
],
"role": "roles/ml.developer"
},
{
"members": [
"serviceAccount:[email protected]"
],
"role": "roles/notebooks.serviceAgent"
},
{
"members": [
"user:***@gmail.com"
],
"role": "roles/owner"
}
],
"etag": "BwYKdso-i10=",
"version": 1
}
Set the path of application_default_credentials.json to GOOGLE_APPLICATION_CREDENTIALS
environment variable.
Have provided the correct project ID:
Project info
-------------
Project name: RAG-Vertex-AI-Chatbot
Project number: 630332944972
Project ID: positive-tempo-405405
Not sure what I am missing here. How to mitigate this issue?