google-gemini / generative-ai-python

The official Python library for the Google Gemini API
https://pypi.org/project/google-generativeai/
Apache License 2.0
1.39k stars 270 forks source link

File uploads are broken (ValueError: Unknown field for File: state) #324

Closed xarcnovn closed 4 months ago

xarcnovn commented 4 months ago

Description of the bug:

This looks similar to this https://github.com/google-gemini/generative-ai-python/issues/292

I used File API to upload images to Gemini and everything was working fine, but now File API returns ValueError: Unknown field for File: state. I did a simple test:

"import google.generativeai as genai

def test():
    genai.upload_file(path='video_screenshot1.png')

test()"

and it returns

"(.venv) karol@Karols-MacBook-Air src % /Users/karol/Desktop/projects/what_to_wear/src/.venv/bin/python /Users/karol/Desktop/projects/what_to_wear/src/test.py
Traceback (most recent call last):
  File "/Users/karol/Desktop/projects/what_to_wear/src/test.py", line 7, in <module>
    test()
  File "/Users/karol/Desktop/projects/what_to_wear/src/test.py", line 5, in test
    genai.upload_file(path='video_screenshot1.png')
  File "/Users/karol/Desktop/projects/what_to_wear/src/.venv/lib/python3.12/site-packages/google/generativeai/files.py", line 52, in upload_file
    response = client.create_file(
               ^^^^^^^^^^^^^^^^^^^
  File "/Users/karol/Desktop/projects/what_to_wear/src/.venv/lib/python3.12/site-packages/google/generativeai/client.py", line 76, in create_file
    return glm.File(
           ^^^^^^^^^
  File "/Users/karol/Desktop/projects/what_to_wear/src/.venv/lib/python3.12/site-packages/proto/message.py", line 576, in __init__
    raise ValueError(
ValueError: Unknown field for File: state"

Please help because it renders my Google AI hackathon project useless (and probably all projects using the upload_file method).

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

mingsheu commented 4 months ago

@xarcnovn can you confirm the version you are using?

pip

$ pip show google.generativeai
Name: google-generativeai
Version: 0.5.2
Summary: Google Generative AI High level API client library and tools.

python

print(genai.__version__)

I was able to replicate the exact error on 0.5.1 but not on 0.5.2 as expected.

xarcnovn commented 4 months ago

I was using the 0.5.1 version. I upgraded to 0.5.2 and it works now. However, it was working a few days ago with v0.5.1 too, I was using it extensively and had never stumbled upon this particular issue. I'm closing the issue then.

olbition commented 3 months ago

I had same error.

pip install --upgrade google-generativeai

Works fine for me.

Version : 0.5.4