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

400 Bad Request if sending messages with empty content (contents.parts must not be empty). #691

Open
splitpierre opened this issue Jan 13, 2025 · 2 comments

Comments

@splitpierre
Copy link

splitpierre commented Jan 13, 2025

ERROR [Error: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:streamGenerateContent?alt=sse: [400 Bad Request] * GenerateContentRequest.contents[41].parts: contents.parts must not be empty.

While implementing chat with history, be careful in cases where some Message property "content" comes empty, it will cause this error. Apparently this is only happening with ChatGoogleGenerativeAI, I'm using several others and didn't had this issue.
For now i made sure to filter those empty entries out, but still, i think this should be handled either by Google or by this repo.

Thanks!

@lkuligin
Copy link
Collaborator

could you add more details on how do you get a message with empty content, please? what's your use case?

@splitpierre
Copy link
Author

splitpierre commented Jan 18, 2025

Sure thing @lkuligin !
This is what I`m talking about, I understand this is not an intended use case (for me), might happen, accidentally or intentionally, it might, in my case it was an accident during tests, which a message landed empty (Eg.: new HumanMessage({ content: "" })) on my history.
But this case errors only with ChatGoogleGenerativeAI, other chat wrappers wont error.

The sample

async generateGeminiTest(request: ChatRequest) {
    const geminiClient = new ChatGoogleGenerativeAI({
      modelName: request.model,
      temperature: request.temperature,
    });

    const someAIMessage = "You are a helpful assistant.";

    return geminiClient.invoke([
      new AIMessage({ content: someAIMessage }),
      new HumanMessage({ content: "" }),
      new HumanMessage({ content: request.prompt }),
    ]);
  }

The error:

[GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse: [400 Bad Request] * GenerateContentRequest.contents[1].parts: contents.parts must not be empty.

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

2 participants