Skip to content

sendMessageStream with history failing to fetch due to 'empty text parameter' #286

@kn0wn

Description

@kn0wn

Description of the bug:

Hi!

I've got quite a basic setup for this error, I'm using Vue.

[400] Unable to submit request because it has an empty text parameter. Add a value to the parameter and try again.

Setup is as follows;

const model = getGenerativeModel(vertexAI, {
  model: "gemini-1.5-flash",
});

const chat = reactive(
  model.startChat({
    history: [
      {
        role: "user",
        parts: [{ text: "Hi, What is your current dataset?" }],
      },
      {
        role: "model",
        parts: [
          {
            text: `My product data set is: ${JSON.stringify(products.value)}`,
          },
        ],
      },
    ],
  })
);

async function sendMessage() {
  const result = await chat.sendMessageStream(question.value);

  for await (const chunk of result.stream) {
    const chunkText = chunk.text();
    generatedText.value += chunkText;
  }
}

I'm then just calling sendMessage with an updated question.value. When I look at the history, I can see that the model has an empty text part which could be the issue, but I'm not entirely sure!

Actual vs expected behavior:

Error output instead of an updated generatedText

Any other information you'd like to share?

Possible history culprit

[
    {
        "text": "I"
    },
    {
        "text": "'m sorry, I don't have information about that - but I can"
    },
    {
        "text": " help you with other questions. \n"
    },
    {
        "text": ""
    }
]

Edit: I noticed that I have ${JSON.stringify(products.value)} in the example, but even without it I'm still getting the same error, let me know if you need a minimal repro.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions