Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: AttributeError: 'Candidate' object has no attribute 'grounding_metadata' in intro-grounding-gemini.ipynb #692

Open
1 task done
MrCsabaToth opened this issue May 16, 2024 · 3 comments

Comments

@MrCsabaToth
Copy link

MrCsabaToth commented May 16, 2024

File Name

intro-grounding-gemini.ipynb

What happened?

For some reason the step

tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())

response = model.generate_content(PROMPT, tools=[tool])

print_grounding_response(response)

resulted in this.

Holt Skinner asked me to file this bug. I was executing the lab in a Workbench instance, not Colab. The %pip install --upgrade --user --quiet google-cloud-aiplatform didn't seem to upgrade, it outputted:

%pip install --upgrade --user --quiet google-cloud-aiplatform
  WARNING: The script tb-gcp-uploader is installed in '/home/jupyter/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Note: you may need to restart the kernel to use updated packages.

pip freeze | grep ai:

aiofiles==22.1.0
aiohttp @ file:///home/conda/feedstock_root/build_artifacts/aiohttp_1710511536979/work
aiohttp-cors==0.7.0
aiosignal @ file:///home/conda/feedstock_root/build_artifacts/aiosignal_1667935791922/work
aiosqlite==0.20.0
explainable-ai-sdk==1.3.3
google-cloud-aiplatform==1.51.0
google-cloud-recommendations-ai==0.7.1
traitlets @ file:///home/conda/feedstock_root/build_artifacts/traitlets_1675110562325/work

Relevant log output

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[25], line 5
      1 tool = Tool.from_google_search_retrieval(grounding.GoogleSearchRetrieval())
      3 response = model.generate_content(PROMPT, tools=[tool])
----> 5 print_grounding_response(response)

Cell In[24], line 5, in print_grounding_response(response)
      3 print(response.candidates[0])
      4 print(str(dir(response.candidates[0])))
----> 5 grounding_metadata = response.candidates[0].grounding_metadata
      7 # Citation indices are in byte units
      8 ENCODING = "utf-8"

AttributeError: 'Candidate' object has no attribute 'grounding_metadata'

Output of print(response.candidates[0]):

content {
  role: "model"
  parts {
    text: "The next solar eclipse in the US will be an annular solar eclipse on October 14, 2023. This eclipse will cross the US from Oregon to Texas. \n\nAfter that, the next solar eclipse will be a total solar eclipse on April 8, 2024. This eclipse will sweep across North America from Mazatl\303\241n to Newfoundland. \n\nThe next total solar eclipse visible in the contiguous US after 2024 will be on August 23, 2044. \n"
  }
}
finish_reason: STOP
safety_ratings {
  category: HARM_CATEGORY_HATE_SPEECH
  probability: NEGLIGIBLE
  probability_score: 0.05654813349246979
  severity: HARM_SEVERITY_NEGLIGIBLE
  severity_score: 0.043042849749326706
}
safety_ratings {
  category: HARM_CATEGORY_DANGEROUS_CONTENT
  probability: NEGLIGIBLE
  probability_score: 0.21667379140853882
  severity: HARM_SEVERITY_NEGLIGIBLE
  severity_score: 0.16940586268901825
}
safety_ratings {
  category: HARM_CATEGORY_HARASSMENT
  probability: NEGLIGIBLE
  probability_score: 0.1710611879825592
  severity: HARM_SEVERITY_NEGLIGIBLE
  severity_score: 0.05399883911013603
}
safety_ratings {
  category: HARM_CATEGORY_SEXUALLY_EXPLICIT
  probability: NEGLIGIBLE
  probability_score: 0.11338310688734055
  severity: HARM_SEVERITY_NEGLIGIBLE
  severity_score: 0.0699218362569809
}
grounding_metadata {
  web_search_queries: "When is the next solar eclipse in the US?"
}

Output of print(str(dir(response.candidates[0]))):

['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_from_gapic', '_raw_candidate', 'citation_metadata', 'content', 'finish_message', 'finish_reason', 'from_dict', 'function_calls', 'index', 'safety_ratings', 'text', 'to_dict']

Code of Conduct

  • I agree to follow this project's Code of Conduct
@VJlaxmi
Copy link
Contributor

VJlaxmi commented May 21, 2024

Hello Team,

I can take up this issue.

@holtskinner
Copy link
Collaborator

I think there was a change to the API service in how it outputs this field.

@MrCsabaToth
Copy link
Author

What was weird to me is that the print showed that field the error complains about, however the dir didn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants