I'm trying to use the vertex-ai sdk on my Firebase Function, but keep getting the below error (a very vague message as this does not tell me what the issue is - there is no stack trace, this is the only error I receive in the Logs Explorer on GCP):
GoogleGenerativeAIError: [VertexAI.GoogleGenerativeAIError]: exception posting request to model at /workspace/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:49:15 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async generateContent (/workspace/node_modules/@google-cloud/vertexai/build/src/functions/generate_content.js:39:22) at async /workspace/lib/api/prompt.js:22:21
The code that I'm trying to run (a simple test):
const {onRequest} = require("firebase-functions/v2/https"); const {setGlobalOptions} = require("firebase-functions/v2"); import { VertexAI } from '@google-cloud/vertexai'; setGlobalOptions({ region: "australia-southeast1" }); exports.promptTest = onRequest({cors: true}, async (request, response) => { const vertex_ai = new VertexAI({project: 'my-project-id', location: 'australia-southeast1'}); const model = 'gemini-1.5-pro-preview-0409'; const generativeModel = vertex_ai.preview.getGenerativeModel({ model: model }); const prompt = `Give me an idea for a camping trip`; const req = { contents: [{role: 'user', parts: [{text: prompt}]}], }; const content = await generativeModel.generateContent(req); const result = content.response.candidates.at(0).content.parts.at(0).text; response.send(result); });
I have enabled all the Vertex AI API components on my GCP account and have tested using the cloud CLI (it worked as expected).
API_ENDPOINT="australia-southeast1-aiplatform.googleapis.com" PROJECT_ID="my-project-id" LOCATION_ID="australia-southeast1" MODEL_ID="gemini-1.5-pro-preview-0409" curl \ -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://${API_ENDPOINT}/v1/projects/${PROJECT_ID}/locations/${LOCATION_ID}/publishers/google/models/${MODEL_ID}:streamGenerateContent" -d '@request.json'
When I try catch my code, I get the following error:
jsonPayload: { name: "GoogleGenerativeAIError" stack_trace: { } }
I hope somebody can assist me.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |