Skip to content

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. #373

@141forever

Description

@141forever

Description of the bug:

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:

Traceback (most recent call last):
File "D:\Study\codes\Gemini_score.py", line 64, in
strr = str(id) + ":" + response.text
File "D:\Study\codes\venv\lib\site-packages\google\generativeai\types\generation_types.py", line 401, in text
raise ValueError(
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.

Any other information you'd like to share?

THIS IS MY CODES:

import pandas as pd
import pdb
import google.generativeai as genai
import os

genai.configure(api_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

model = genai.GenerativeModel('gemini-1.5-pro')

response = model.generate_content(system_prompt)
strr = str(id) + ":" + response.text

system_prompt is a string

Metadata

Metadata

Assignees

No one assigned

    Labels

    component:python sdkIssue/PR related to Python SDKstatus:awaiting user responseAwaiting a response from the authorstatus:staleIssue/PR will be closed automatically if there's no further activitytype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions