Skip to content

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

@zakcali

Description

@zakcali

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: Gemini API : The recitation problem is annoying google/generative-ai-docs#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

Metadata

Metadata

Labels

component:js sdkIssue/PR related to JavaScript SDKstatus:triagedIssue/PR triaged to the corresponding sub-teamtype:bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions