It's about how you pass the endpoint to VertexAI node.js API. We need to provide it to the model parameter like this: projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID
It's because how VertexAI node.js API deals with provided parameters. In post_request.js, this is how the final endpoint is generated: let vertexEndpoint = https://${vertexBaseEndpoint}/${apiVersion}/${resourcePath}:${resourceMethod}
Now, resourcePath is generated using the model parameter we pass to .getGenerativeModel method. We generally pass model names such as gemini-1.0-pro. In this case, it appends a prefix to it to create resourcePath which is the full path to Google's original model. When we want to use our fine-tuned models deployed to an endpoint in our Google Cloud project, we need to pass the endpoint(not the model) to the model parameter, as described above. In this case, Vertex node.js Api, checks to see if model parameter starts with 'projects/' and doesn't append any prefix.
Code:
Copyconst vertexAI = new VertexAI({project: GOOGLE_PROJECT_ID, location: 'us-central1', googleAuthOptions: {keyFile: KEY_FILE_PATH}});
const generativeModel = vertexAI.getGenerativeModel({
model: 'projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID',
});
try {
const resp = await generativeModel.generateContent(prompt);
const contentResponse = await resp.response;
if(!contentResponse || !contentResponse.candidates || contentResponse.candidates.length == 0 || !contentResponse.candidates[0].content
|| !contentResponse.candidates[0].content.parts || contentResponse.candidates[0].content.parts.length == 0) {
throw Error("ERROR: NO RESPONSE RETURNED FROM GOOGLE GENAI")
} else {
return contentResponse.candidates[0].content.parts[0].text;
}
} catch(e) {
console.error(e)
throw Error(e)
}
Answer from cuneyttyler on Stack Overflow
» npm install @google-cloud/aiplatform
Videos
» npm install @ai-sdk/google-vertex
» npm install @google-cloud/vertexai