GoogleCloudPlatform / generative-ai

Sample code and notebooks for Generative AI on Google Cloud, with Gemini on Vertex AI
https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview
Apache License 2.0
8.28k stars 2.33k forks source link

[Bug]: Mime-type not working on upload #1390

Closed jay2jp closed 2 weeks ago

jay2jp commented 3 weeks ago

File Name

generativeai/files.py

What happened?

Mime-type assignment is not working properly

Gemini stopped working due to the file upload in the python sdk being broken.

this is how i use the file upload

def upload_to_gemini(path, mime_type=None):
    """Uploads the given file to Gemini."""
    file = genai.upload_file(path, mime_type=mime_type)
    print(f"[UPLOAD] File uploaded as: {file.uri}")
    return file

when i upload a file like so audio_file = upload_to_gemini(temp_path, "audio/wav")

it uploads correctly but the mime type is not set

AUDIO FILE: genai.File({ 'name': 'files/30txz5yr4lnt', 'display_name': 'tmp8nqzekug.wav', 'mime_type': '', 'sha256_hash': '', 'size_bytes': '0', 'state': 'ACTIVE', 'create_time': '2024-11-11T23:28:05.021763Z', 'expiration_time': '2024-11-13T23:28:05.001887117Z', 'update_time': '2024-11-11T23:28:05.021763Z'})

as you can see the mime type is not set

resulting in this issue: 400 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

This has happened on my local machine as well as google cloud run functions.

Relevant log output

TRACEBACK: Traceback (most recent call last):
  File "/Users/User/OWL/main.py", line 668, in analyze_single_call
    response = chat.send_message([
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/generativeai/generative_models.py", line 578, in send_message
    response = self.model.generate_content(
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/generativeai/generative_models.py", line 331, in generate_content
    response = self._client.generate_content(
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 830, in generate_content
    response = rpc(
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
    _retry_error_helper(
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
    result = target()
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
  File "/Users/User/OWL/venv/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 78, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 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

Code of Conduct

adboio commented 3 weeks ago

related to https://github.com/google-gemini/generative-ai-python/issues/628

holtskinner commented 2 weeks ago

Doesn't seem that this issue is related to this repository. It's related to the Gemini API, not Gemini API in Vertex AI. Refer to #628 for the fix.