google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.34k stars 264 forks source link

response.text quick accessor bug #318

Open mkdemkov opened 4 months ago

mkdemkov commented 4 months ago

Description of the bug:

Here is the code snippet that sometimes falls with the ValueError exception despite the fact that I disabled all the safety settings:

genai.configure(api_key=self.api_key) model = genai.GenerativeModel( model_name="gemini-pro",

generation_config=self.generation_config,

        safety_settings=self.safety_settings
    )

    try:
        response = await model.generate_content_async(self.history)
        print(response.text)

ValueError: The response.text quick accessor only works when the response contains a valid Part, but none was returned. Check the candidate.safety_ratings to see if the response was blocked.

Actual vs expected behavior:

Actual: raises an exception Expected: some text response like "Sorry, I can't answer your question due to ..."

Any other information you'd like to share?

No response

singhniraj08 commented 4 months ago

@mkdemkov, Similar feature request #282 is already in progress. Requesting you to close this issue and please follow and +1 similar thread for updates. Thank you!