Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Headers is not a constructor #230

Open
Matteob98 opened this issue Aug 21, 2024 · 1 comment
Open

TypeError: Headers is not a constructor #230

Matteob98 opened this issue Aug 21, 2024 · 1 comment
Assignees
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@Matteob98
Copy link

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

@wong2
Copy link
Contributor

wong2 commented Aug 22, 2024

Make sure you're using Node.js 18+

@singhniraj08 singhniraj08 added type:bug Something isn't working status:triaged Issue/PR triaged to the corresponding sub-team component:js sdk Issue/PR related to JavaScript SDK labels Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:js sdk Issue/PR related to JavaScript SDK status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants