google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.46k stars 494 forks source link

Invalid operation: The `response.text` quick accessor requires the response to contain a valid `Part`, but none were returned. Please check the `candidate.safety_ratings` to determine if the response was blocked. #461

Closed YiLuo59 closed 4 days ago

YiLuo59 commented 2 weeks ago

Description of the bug:

My code is as following:

def model_generate(query, model): response = model.generate_content(query, generation_config=genai.types.GenerationConfig( max_output_tokens=3000, temperature=0.7), safety_settings={ HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE, }) return response

response = model_generate(input, model)

Then I got error: Invalid operation: The response.text quick accessor requires the response to contain a valid Part, but none were returned. Please check the candidate.safety_ratings to determine if the response was blocked.

image

How can I deal with that?

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

singhniraj08 commented 1 week ago

@YiLuo59, Thank you reporting this issue. Similar issue is already filed in python SDK repo (#python/373) This repository is for issues related to website(https://ai.google.dev/) like documentation bugs or improvements. Requesting you to close this issue, follow and +1 similar thread for updates. Thank you!