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: allow multiple user messages in a row for google gemini #246

Conversation

meronogbai
Copy link
Contributor

@meronogbai meronogbai commented Mar 6, 2024

Title:

  • This will allow users to include multiple user messages in a row in gemini-pro.

Description: (optional)

Motivation: (optional)

  • An app I work on relies on multiple user messages and it was breaking for me when I tried to use it with gemini-pro.

How to test?

The following snippet breaks with gemini-pro even though it works with openai. Checkout this branch and everything should work without issues 🫡

async function main() {
  const stream = await openai.chat.completions.create({
    model: "gemini-pro",
    messages: ([
      {
        role: "user",
        content: "Say this is a test",
      },
      { role: "user", content: "now say im happy" },
    ]),
    stream: true,
    max_tokens: 4096,
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || "");
  }
}

main();


// @NOTE: This takes care of the "Please ensure that multiturn requests alternate between user and model."
// error that occurs when we have multiple user messages in a row.
const shouldAppendEmptyModeChat = lastRole === 'user' && role === 'user' && !params.model?.includes('vision');
Copy link
Contributor Author

@meronogbai meronogbai Mar 6, 2024

Choose a reason for hiding this comment

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

Opting out in case of gemini-pro-vision because it doesn't support multiturn chat anyway.

@vrushankportkey
Copy link
Collaborator

Thank you so much for the PR, @meronogbai! This is amazing. Paging @VisargD who can check this

@VisargD
Copy link
Collaborator

VisargD commented Mar 16, 2024

Thanks for the PR @meronogbai . I will review and merge this PR today.

@VisargD
Copy link
Collaborator

VisargD commented Mar 16, 2024

LGTM. Closes #258

@VisargD VisargD merged commit 5c70e12 into Portkey-AI:main Mar 16, 2024
@VisargD VisargD linked an issue Mar 16, 2024 that may be closed by this pull request
@meronogbai meronogbai deleted the fix/multiple-user-images-in-a-row-gemini-pro branch March 16, 2024 18:44
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.

allow multiple user messages in a row for google gemini
3 participants