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

Generation failure due to safety settings trigger fails to raise proper exception and instead returns a zero candidate count

Open Bikatr7 opened this issue 2 years ago • 0 comments

Description of the bug:

When a generation fails due to safety settings, it does a silent fail and just returns a response with zero candidate count.

Actual vs expected behavior:

should raise an error.

Any other information you'd like to share?

Can be bypassed by setting safety settings like

safety_settings = [
    {
        "category": "HARM_CATEGORY_DANGEROUS",
        "threshold": "BLOCK_NONE",
    },
    {
        "category": "HARM_CATEGORY_HARASSMENT",
        "threshold": "BLOCK_NONE",
    },
    {
        "category": "HARM_CATEGORY_HATE_SPEECH",
        "threshold": "BLOCK_NONE",
    },
    {
        "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
        "threshold": "BLOCK_NONE",
    },
    {
        "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
        "threshold": "BLOCK_NONE",
    },
]

and passing into request like


    response = await GeminiService.client.generate_content_async(
        contents=translation_instructions + "\n" + translation_prompt,
        generation_config=GeminiService.generation_config,
        safety_settings=GeminiService.safety_settings,
        stream=GeminiService.stream
    )

Bikatr7 avatar Mar 01 '24 18:03 Bikatr7