googleapis / nodejs-vertexai

Apache License 2.0
112 stars 40 forks source link

Iam Trying to do a Nodejs generateContentStream but Keep getting the exception posting request #130

Closed Genzan closed 8 months ago

Genzan commented 8 months ago

Hi Iam using the @google-cloud/vertexai using the documentation provided, but Keep getting this error once I call the generateContentStream

Error: [VertexAI.GoogleGenerativeAIError]: exception posting request

I even used the Autogenerated code on https://console.cloud.google.com/vertex-ai/generative/multimodal/create/text, but is the same error again and again, I did the command gcloud auth application-default login

And validate that file exist, What else Iam doing wrong?

const vertex_ai = new VertexAI({project: process.env.PROJECT_ID, location: process.env.LOCATION});

const generativeModel = vertex_ai.preview.getGenerativeModel({ model: model, generation_config: { "max_output_tokens": process.env.MAX_OUTPUT_TOKENS, "temperature": process.env.TEMPERATURE, "top_p": process.env.TOP_P, "top_k": process.env.TOP_K } });

const message = { contents: [{role: 'user', parts: [{inline_data: {mime_type: 'image/jpg', data: dogImage1}}, {text: 'Que raza de Perro es?'}]}], };

try{ const streamingResp = await generativeModel.generateContentStream(message); console.log('streamingResp',streamingResp);

for await (const item of streamingResp.stream) {
  process.stdout.write('stream chunk: ' + item);
}

process.stdout.write('aggregated response: ' + (await streamingResp.response));
console.log('Prediction:');

} catch (error) { console.error('Error:', error.message); }

sararob commented 8 months ago

Hi Genzan,

Are you using gemini-pro-vision as the model in your request? Could you also confirm that the MIME type of your image matches what you've provided in the request? You may want to try passing image/jpeg as the mime_type value (note the added e in jpeg).

sararob commented 8 months ago

Looking into this further it seems like image/jpeg is the only valid MIME type for jpeg images (reference). Let us know if changing that fixes the issue.

yyyu-google commented 8 months ago

closing as no further response from user. feel free re-open if @sararob 's reply doesn't solve the problem

afzaale01 commented 5 months ago

Getting same error. I'm using demo code attached with repo @sararob