googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.81k stars 1.31k forks source link

mime_type attribute not being set #11113

Closed imbishal7 closed 3 weeks ago

imbishal7 commented 3 weeks ago

google.generativeai

google.generativeai.upload_file()

Linux

google-generativeai 0.8.3

Code and Dependencies

import google.generativeai as genai

def GetModel(api_key = api_key):
  genai.configure(api_key=api_key)
  generation_config = {
    "temperature": 1,
    "top_p": 0.9, 
    "top_k": 40,
    "response_mime_type": "text/plain",
  }
  model = genai.GenerativeModel(
    model_name="gemini-1.5-pro-002",
    generation_config=generation_config,
  )
  return model

model = GetModel()
uploaded_file = genai.upload_file('lesson_plan.pdf', mime_type = 'application/pdf')

print(os.listdir())
print()
print(uploaded_file)

response = model.generate_content([uploaded_file, 'make json from it'])

Output:

['.config', 'lesson_plan.pdf', '.ipynb_checkpoints', 'sample_data']

genai.File({
    'name': 'files/uq1fz7xs56uu',
    'display_name': 'lesson_plan.pdf',
    'mime_type': '',
    'sha256_hash': '',
    'size_bytes': '0',
    'state': 'ACTIVE',
    'uri': 'https://generativelanguage.googleapis.com/v1beta/files/uq1fz7xs56uu',
    'create_time': '2024-11-12T02:43:24.161331Z',
    'expiration_time': '2024-11-14T02:43:24.146100404Z',
    'update_time': '2024-11-12T02:43:24.161331Z'})

WARNING:tornado.access:400 POST /v1beta/models/gemini-1.5-pro-latest:generateContent?%24alt=json%3Benum-encoding%3Dint (127.0.0.1) 663.24ms
---------------------------------------------------------------------------
BadRequest                                Traceback (most recent call last)
[<ipython-input-74-86e6254a318f>](https://localhost:8080/#) in <cell line: 1>()
----> 1 response = model.generate_content([uploaded_file, 'make json from it'])

9 frames
[/usr/local/lib/python3.10/dist-packages/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py](https://localhost:8080/#) in __call__(self, request, retry, timeout, metadata)
    845             # subclass.
    846             if response.status_code >= 400:
--> 847                 raise core_exceptions.from_http_response(response)
    848 
    849             # Return the response

BadRequest: 400 POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?%24alt=json%3Benum-encoding%3Dint: Unable to submit request because it has an empty mimeType parameter in fileData. Add a value to the parameter and try again. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini
The mime_type attribute is empty even when specified or not specified. ```text module google.generativeai python 3.10.15 ```

Expected behavior

mime_type attribute to be set.

Actual behavior

mime_type attribute is empty.

Additional context

It was working fine until yesterday. I do not what happened in a day without any updates.

codyoss commented 3 weeks ago

I think you might be looking for https://github.com/google-gemini/generative-ai-python. Closing as this repo is for our Go client SDKs.