google / google/generative-ai-docs

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

Open
#413 2 comments 1 reaction 0 assignees View on GitHub
component:documentation status:triaged type:bug
Dominant language
Jupyter Notebook
Stars
2.3k
Forks
735
PR merge metrics
No merged PRs in 30d

Description

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](https://ai.google.dev/gemini-api/docs/get-started/node#multi-turn-conversations-chat)
```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.