Description
Description of the bug:
I was playing around with tool use and streaming, this was my code:
import google.generativeai as genai
import config
genai.configure(api_key=config.API_KEY)
def set_brightness(value: float) -> None:
"""Controls the brightness of all house lights. `value` is a `float` between 0 (off) and 1 (max)."""
print("Brightness changed:", value)
model = genai.GenerativeModel(
"gemini-1.5-flash-002",
tools=[set_brightness],
)
chat = model.start_chat()
while True:
stream = chat.send_message(input("User: "), stream=True)
print("Model: ", end="", flush=True)
for chunk in stream:
print(chunk.text, end="", flush=True)
print()
I got this peculiar error when I prompted it like this:
❯ python3 main.py
User: hey can you turn off the lights
Model: Traceback (most recent call last):
File "/home/ducc/Projects/sketchbooks/apithing/main.py", line 29, in <module>
print(chunk.text, end="", flush=True)
^^^^^^^^^^
File "/home/ducc/Projects/sketchbooks/apithing/.venv/lib/python3.13/site-packages/google/generativeai/types/generation_types.py", line 536, in text
part_type = protos.Part.pb(part).whichOneof("data")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: whichOneof. Did you mean: 'WhichOneof'?
I am currently using Python 3.13, latest version of the SDK.
This is not an issue on my part as this seems to be a typo in the library.
Actual vs expected behavior:
Actual:
❯ python3 main.py
User: hey can you turn off the lights
Model: Traceback (most recent call last):
File "/home/ducc/Projects/sketchbooks/apithing/main.py", line 29, in <module>
print(chunk.text, end="", flush=True)
^^^^^^^^^^
File "/home/ducc/Projects/sketchbooks/apithing/.venv/lib/python3.13/site-packages/google/generativeai/types/generation_types.py", line 536, in text
part_type = protos.Part.pb(part).whichOneof("data")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: whichOneof. Did you mean: 'WhichOneof'?
Expected (roughly):
❯ python3 main.py
User: hey can you turn off the lights
Brightness changed: 0.0
Model: Done!
Any other information you'd like to share?
Simply change the typo at types/generation_types.py
, line 536, from .whichOneof
to .WhichOneof
.