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

response.text quick accessor bug

Open mkdemkov opened this issue 1 year ago • 1 comments

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

mkdemkov avatar May 04 '24 12:05 mkdemkov

@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!

singhniraj08 avatar May 06 '24 05:05 singhniraj08