generative-ai-js
generative-ai-js copied to clipboard
RECITATION Error causes history contains empty parts[], and kills chat session
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
- 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
- gemini 1.5 pro gives RECITATION error
- 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
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).
I am also getting this error
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?
getting this too