Closed hoantran-it closed 7 months ago
install 0.4.0
npm install @google-cloud/vertexai@0.4.0
Use the following code
const {VertexAI, HarmCategory, HarmBlockThreshold} = require('@google-cloud/vertexai');
const project = 'your project';
const location = 'us-central1'; // or your specified location
const vertex_ai = new VertexAI({ project: project, location: location });
// this is the GA namespace in version 0.4.0
// you can still keep using the preview namespace by
// const generativeModel = vertex_ai.preview.getGenerativeModel({...})
const generativeModel = vertex_ai.getGenerativeModel({
model: "gemini-pro",
safety_settings: [{ category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE }],
generation_config: { max_output_tokens: 256 },
});
async function test() {
const request = {
contents: [{ role: 'user', parts: [{ text: 'How are you doing today?' }] }],
};
const resp = await generativeModel.generateContent(request);
console.log('aggregated response: ', JSON.stringify(resp.response));
}
test();
No matter you use GA namespace or preview namespace, you should get response like the following
aggregated response: {"candidates":[{"content":{"role":"model","parts":[{"text":"As an AI chatbot, I do not have personal feelings or the capacity to experience emotions like humans. I am designed to provide information and assist users to the best of my abilities."}]},"finishReason":"STOP","safetyRatings":[{"category":"HARM_CATEGORY_HATE_SPEECH","probability":"NEGLIGIBLE","probabilityScore":0.04689926,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.031261913},{"category":"HARM_CATEGORY_DANGEROUS_CONTENT","probability":"NEGLIGIBLE","probabilityScore":0.032100707,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.015603535},{"category":"HARM_CATEGORY_HARASSMENT","probability":"NEGLIGIBLE","probabilityScore":0.06221698,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.041930523},{"category":"HARM_CATEGORY_SEXUALLY_EXPLICIT","probability":"NEGLIGIBLE","probabilityScore":0.10248422,"severity":"HARM_SEVERITY_NEGLIGIBLE","severityScore":0.0715912}]}],"usageMetadata":{"promptTokenCount":6,"candidatesTokenCount":36,"totalTokenCount":42}}
@yyyu-google we're seeing the same issue for @google/generative-ai
version 0.1.3
, any guidance?
Recently, I encounter this issue when calling vertex AI
TypeError: response.body.pipeThrough is not a function
The code here
It worked before until Thursday, the issue happen, could you help to advise, thank you!