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

Gemini API multi-turn conversations (chat) | Typeerror for text #413

Open
ayush7801 opened this issue May 13, 2024 · 0 comments
Open

Gemini API multi-turn conversations (chat) | Typeerror for text #413

ayush7801 opened this issue May 13, 2024 · 0 comments
Labels
component:documentation Update docs status:triaged Issue/PR triaged to the corresponding sub-team type:bug Something isn't working

Comments

@ayush7801
Copy link

Hi, I am getting this typeerror for text key being undefined even when I am requesting with the same request body as in documentation. I am using NodeJS.

Code given in documentation - docs

const { GoogleGenerativeAI } = require("@google/generative-ai");

// Access your API key as an environment variable (see "Set up your API key" above)
const genAI = new GoogleGenerativeAI(process.env.API_KEY);

async function run() {
  // For text-only input, use the gemini-pro model
  const model = genAI.getGenerativeModel({ model: "gemini-pro"});

  const chat = model.startChat({
    history: [
      {
        role: "user",
        parts: [{ text: "Hello, I have 2 dogs in my house." }],
      },
      {
        role: "model",
        parts: [{ text: "Great to meet you. What would you like to know?" }],
      },
    ],
    generationConfig: {
      maxOutputTokens: 100,
    },
  });

  const msg = "How many paws are in my house?";

  const result = await chat.sendMessage(msg);
  const response = await result.response;
  const text = response.text();
  console.log(text);
}

run();

Response I am getting -
Cannot read properties of undefined (reading 'text') , with response code 500.

Your help is appriciated.

@singhniraj08 singhniraj08 added type:bug Something isn't working status:triaged Issue/PR triaged to the corresponding sub-team component:documentation Update docs labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:documentation Update docs 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

2 participants