-
Notifications
You must be signed in to change notification settings - Fork 306
Closed
Labels
component:gemini apiIssue related to gemini apiIssue related to gemini apip1status:triagedIssue/PR triaged to the corresponding sub-teamIssue/PR triaged to the corresponding sub-teamtype:bugSomething isn't workingSomething isn't working
Description
Description of the bug:
When responseMimeType: 'application/json', a request is failing with error:
[GoogleGenerativeAI Error]: Candidate was blocked due to RECITATION.
However, without responseMimeType, the same prompt works (returns a markdown with json).
The exact same instructions and prompt work on the AI Studio, even with output in JSON on.
// The error happens even if safety settings are set to block none.
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
]
const model = this.genAI.getGenerativeModel({
model: 'gemini-1.5-flash-latest',
systemInstruction: instructions,
safetySettings,
})
const generationConfig = {
temperature: 0,
topP: 0.95,
topK: 64,
maxOutputTokens: 8192,
responseMimeType: 'application/json', // fails only if this option is sent.
}
const chatSession = model.startChat({
generationConfig,
})
const result = await chatSession.sendMessage(prompt)
const text = result.response.text() // throws [GoogleGenerativeAI Error]: Candidate was blocked due to RECITATION.
Actual vs expected behavior:
Actual: Throws [GoogleGenerativeAI Error]: Candidate was blocked due to RECITATION
Expected: Return the same result as in the AI Studio.
Any other information you'd like to share?
No response
bakaburg1, Nelathan, danissimov, AshishAcharya083, kevinrss01 and 2 morenasirus, kevinrss01 and sdcbdashed, kevinrss01 and gohjiayi
Metadata
Metadata
Assignees
Labels
component:gemini apiIssue related to gemini apiIssue related to gemini apip1status:triagedIssue/PR triaged to the corresponding sub-teamIssue/PR triaged to the corresponding sub-teamtype:bugSomething isn't workingSomething isn't working