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

Newest version breaks quickstart documentation #61

Closed
bakkot opened this issue Mar 14, 2024 · 3 comments
Closed

Newest version breaks quickstart documentation #61

bakkot opened this issue Mar 14, 2024 · 3 comments

Comments

@bakkot
Copy link

bakkot commented Mar 14, 2024

Expected Behavior

The code on this page should work.

Actual Behavior

TypeError: Cannot use 'in' operator to search for 'text' in H
    at validateChatHistory ([...]@google/generative-ai/dist/index.mjs:758:25)

Steps to Reproduce the Problem

Run the code from the sample:

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: "Hello, I have 2 dogs in my house.",
      },
      {
        role: "model",
        parts: "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();

Specifications

  • Version: @google/generative-ai": "^0.3.0
  • Platform: node

Specifically, I believe this was broken by #32. It would be trivial to make that change backwards-compatible by having validateChatHistory branch on whether parts is a string or array (or otherwise error), but either way the documentation should be updated.

@AjBillel
Copy link

@bakkot yep right, it was an issue with the latest version

I try using an older version of gemini, it works for me

<script type="importmap"> { "imports": { "@google/generative-ai": "https://esm.run/@google/generative-ai@0.2.1" } } </script>

@khammami
Copy link

khammami commented Mar 18, 2024

The documentation needs to be updated or as @bakkot said to make it backwards-compatible would be good too.
There's no need to use an older version, just update the JSON of chat history/prompt to match function calling new format.

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,
    },
  });

@alx13
Copy link
Contributor

alx13 commented Mar 18, 2024

Quick start documentation is now updated to reflect changes in PR

@alx13 alx13 closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants