generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

RECITATION Error causes history contains empty parts[], and kills chat session

Open zakcali opened this issue 9 months ago • 4 comments

Expected Behavior

after receiving that error,

{
  candidates: [ { finishReason: 'RECITATION', index: 0 } ],
  text: [Function (anonymous)],
  functionCall: [Function (anonymous)],
  functionCalls: [Function (anonymous)]
}

to be able to continue to chatting, model's last element of history must contain an empty text, such as

  {
    role: 'user',
    parts: [ { text: 'meme kanserinde hangi ilaçlar kullanılır?\n' } ]
  },
   {
    parts: [ { text: '' } ], role: 'model'
  }

Actual Behavior

this error kills chat session

{
  candidates: [ { finishReason: 'RECITATION', index: 0 } ],
  text: [Function (anonymous)],
  functionCall: [Function (anonymous)],
  functionCalls: [Function (anonymous)]
}

because now last element of history contains empty parts[] as follows

  {
    role: 'user',
    parts: [ { text: 'meme kanserinde hangi ilaçlar kullanılır?\n' } ]
  },
  { parts: [], role: 'model' }

if I continue to chat , always get that error::

GoogleGenerativeAIError: [400 Bad Request] * GenerateContentRequest.contents[3].parts: contents.parts must not be empty

in that line of source code

const result = await chat.sendMessage(prompt);

Steps to Reproduce the Problem

  1. give a large context prompt so that your text contains texts from trained data. Ask a question about your large context prompt. My large context prompt contains 35k tokens, and I do not want to share here. there may be other ways to get RECITATION error: https://github.com/google/generative-ai-docs/issues/257
  2. gemini 1.5 pro gives RECITATION error
  3. now ask anything

Specifications

  • Version: nodejs (20.12.2 LTS), gemini js api : "@google/generative-ai": "^0.9.0" , model gemini 1.5 pro v1beta
  • Platform: Windows

zakcali avatar May 02 '24 20:05 zakcali

Any updates on this? As it stands at the current moment, using Gemini Pro 1.5 for RAG-base Q/A with chat history is incredibly unreliable.

Simply ask 2-3 questions about a document with some overlap, and you will encounter a RECITATION error almost guranteed.

I.e, using LangChain:

const chatTemplate = ChatPromptTemplate.fromMessages([['system', 'You are a helpful assistant. Answer all questions to the best of your ability.'], new MessagesPlaceholder('history'), new MessagesPlaceholder('input')]);
	const chain = chatTemplate.pipe(pdfModel).pipe(new StringOutputParser());

const chainWithHistory = new RunnableWithMessageHistory({
		runnable: chain,
		getMessageHistory: () => chatHistory,
		inputMessagesKey: 'input',
		historyMessagesKey: 'history',
		config: { configurable: { sessionId: decodedToken.uid } }
	});

	const response = await chainWithHistory.invoke({ input: input });

If you simply ask the model to recite a specific section of a file/PDF twice in a row, you will get a Recitation error GURANTEED (whether you pass the input File in once at the beginning of the conversation, only in the latest message, or as part of every message input is irrelevant).

Kashi-Datum avatar May 27 '24 22:05 Kashi-Datum

I am also getting this error

umair313 avatar Jul 03 '24 09:07 umair313

We are getting this error all the time trying to create a glossary from documents that we are sanctioned and authorized to use for this purpose. How is GEMINI even useful if this is the results we are getting? Is this google copyright protection gone wrong?

gitcagey avatar Jul 17 '24 04:07 gitcagey

getting this too

GeeseGoo avatar Jul 19 '24 01:07 GeeseGoo