How do i call a Vertex AI Endpoint from Google Cloud Functions written in python

1.3k Views Asked by At

I need to create a wrapper for a Vertex AI endpoint using cloud functions written in python. The client will call the cloud function endpoint, which in turn will call the Vertex AI end point with the JSON request received from the client. The JSON response received from the Vertex AI endpoint call will be modified and sent back to the client. I am new to python and GCP, i got an idea how to make the call using this link Error call Google Vertex AI endpoint from a python backend

I tried the following code but I am getting "Error: could not handle the request"

from google.cloud import aiplatform

aip_endpoint_name = (
f"/projects/\<PROJECT_ID\>/locations/us-central1/endpoints/\<ENDPOINT_ID\>"
)

endpoint = aiplatform.Endpoint(aip_endpoint_name)

instances_list = \[{"parent_code":"IN0028","entity_code":"665038","provider_job_code_descr":"Clk Data Entry"}\]

instances = \[json_format.ParseDict(s, Value()) for s in instances_list\]

results = endpoint.predict(instances=instances)
print(results.predictions)
0

There are 0 best solutions below