Skip to content

fix: allow multiple user messages in a row for google gemini#246

Merged
VisargD merged 2 commits intoPortkey-AI:mainfrom
meronogbai:fix/multiple-user-images-in-a-row-gemini-pro
Mar 16, 2024
Merged

fix: allow multiple user messages in a row for google gemini#246
VisargD merged 2 commits intoPortkey-AI:mainfrom
meronogbai:fix/multiple-user-images-in-a-row-gemini-pro

Conversation

@meronogbai
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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

@vrushankportkey vrushankportkey requested a review from VisargD March 6, 2024 08:15
@VisargD
Copy link
Copy Markdown
Collaborator

VisargD commented Mar 16, 2024

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

@VisargD
Copy link
Copy Markdown
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