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

Give more-actionable error messages for `.text` accessor.

Open MarkDaoust opened this issue 11 months ago • 0 comments

Description of the bug:

""" Mark Daoust Yeah, sometimes the api returns nothing one way or another.

response.text Isn't meant to be robust to that. Are there candidates or were they blocked? or did the model just return a content with an empty list of parts? or a part that didn't have text in it?

You, Mon 11:11 AM, Edited This is a known problem, and as the API improves it should happen less, but I don't have a solution short of something like:

def get_text(prompt):
    errors = []
    for i in range(5):
      try:
          return  model.generate_content(prompt).text
      except Exception as e:
          errors.append(e)
    rasie Exception(errors)

""" """ Josh Gordon, Mon 11:37 AM Interesting. Thanks for the context and idea. The retry in the loop may not be ideal (billing, more calls), but maybe including another sentence in the ValueError that's returned, telling the user they can retry? """

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

MarkDaoust avatar Mar 08 '24 18:03 MarkDaoust