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

fix: Gemini text chat - prevent sending broken messageContent and history #822

Merged
merged 4 commits into from May 15, 2024

Conversation

parhammmm
Copy link
Contributor

@parhammmm parhammmm commented May 8, 2024

Gemini was completely broken for text chat and was getting confused when prompted with an empty context.

It is still broken for vision. Currently the mimeType is incorrect and inlineData isn't taken into account. Will submit a separate PR to address.

Copy link

changeset-bot bot commented May 8, 2024

🦋 Changeset detected

Latest commit: 2992cc0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
llamaindex Patch
docs Patch
@llamaindex/experimental Patch
@llamaindex/cloudflare-worker-agent-test Patch
@llamaindex/next-agent-test Patch
@llamaindex/nextjs-edge-runtime-test Patch
@llamaindex/waku-query-engine-test Patch
@llamaindex/autotool-01-node-example Patch
@llamaindex/autotool-02-next-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented May 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
llama-index-ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 8, 2024 3:38pm

Copy link
Collaborator

@marcusschiesser marcusschiesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parhammmm looks great - do you have a test case that failed with the old implementation? if so, can you add it to 'examples'?

packages/core/src/Prompt.ts Show resolved Hide resolved
@parhammmm
Copy link
Contributor Author

@parhammmm looks great - do you have a test case that failed with the old implementation? if so, can you add it to 'examples'?

@marcusschiesser

The test case would be the following, I'm not sure if you want the following in the examples as it requires a fake response from the llm? Let me know if that's ok and I'll add it or not

import { Gemini, GEMINI_MODEL } from "llamaindex";

(async () => {
  if (!process.env.GOOGLE_API_KEY) {
    throw new Error("Please set the GOOGLE_API_KEY environment variable.");
  }
  const gemini = new Gemini({
    model: GEMINI_MODEL.GEMINI_PRO,
  });
  const result = await gemini.chat({
    messages: [
      { content: "You want to talk in rhymes.", role: "system" },
      {
        content: [{ type: "text", text: "Who is woodchuck?" }],
        role: "user",
      },
      {
        content: [{ type: "text", text: "Woodchuck is a Bird" }],
        role: "assistant",
      },
      {
        content:
          "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
        role: "user",
      },
    ],
  });
  console.log(result);
})();

There were two issues:

  1. role = assistant was being mapped to Gemini's user, causing the entire history to be merged into one
  2. when MessageContent was of the type MessageContentDetail[] the message sent would be:
[
  {
    text: 'You want to talk in rhymes.\n' +
      '[object Object]\n' +
      '[object Object]\n' +
      'How much wood would a woodchuck chuck if a woodchuck could chuck wood?'
  }
]

@parhammmm
Copy link
Contributor Author

@marcusschiesser I also have the Gemini Vertex implementation ready for PR after this is merged in

@marcusschiesser marcusschiesser merged commit 447105a into run-llama:main May 15, 2024
14 checks passed
@marcusschiesser
Copy link
Collaborator

Thanks a lot @parhammmm - just tested it. Great work!

@marcusschiesser
Copy link
Collaborator

Looking forward to your Vertex implementation

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

Successfully merging this pull request may close these issues.

None yet

2 participants