generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

TypeError: Headers is not a constructor

Open Matteob98 opened this issue 1 year ago • 2 comments

Description of the bug:

In my project in which I am implementing the google/generative-ai module, I am experiencing the following problem.

TypeError: Headers is not a constructor
at getHeaders (/home/project/project-backend/node_modules/@google/generative-ai/dist/index.js:328:21)
at constructModelRequest (/home/project/project-backend/node_modules/@google/generative-ai/dist/index.js:358:
at makeModelRequest (/home/project/project-backend/node_modules/@google/generative-ai/dist/index.js:364:41)
at generateContent (/home/project/project-backend/node_modules/@google/generative-ai/dist/index.js:815:28)
at GenerativeModel.generateContent (/home/project/project-backend/node_modules/@google/generative-ai/dist/index.js:1296:16)
at GeminiService.createContent (/home/project/project-backend/dist/src/modules/google/services/gemini.service.js:34:40)

This is my code


import {GoogleGenerativeAI} from "@google/generative-ai";

const model = this.geminiAi.getGenerativeModel({ model: geminiContentCreate.model});

geminiAi: GoogleGenerativeAI;

constructor() {
this.geminiAi = new GoogleGenerativeAI(config.geminiApiKey);
}

async createContent(geminiContentCreate: GeminiContentCreateDtov): Promise<any> {

  try {
              const result = await model.generateContent(geminiContentCreate.prompt);
              const response = await result.response;
              const text = response.text();
  
  }  catch (e) {
              console.log(e);
  }
}

Actual vs expected behavior:

No response

Any other information you'd like to share?

I have tried both 0.16.0 and 0.17.0 versions

Matteob98 avatar Aug 21 '24 12:08 Matteob98

Make sure you're using Node.js 18+

wong2 avatar Aug 22 '24 15:08 wong2

Can you confirm that the issue is still present on the mentioned Node version and latest release?

IvanLH avatar Feb 25 '25 19:02 IvanLH