googleapis / googleapis/python-genai

Extending video is not working while using proxy

Abierto
#1,981 3 comentarios 0 reacciones 1 asignado Reclamado por @Venkaiahbabuneelam Ver en GitHub
priority: p2 type: bug
Lenguaje dominante
Python
Estrellas
4k
Forks
1k
Merge medio
2 d 11 h
PR fusionados (30 d)
40

Descripción

#### Environment details

- Programming language: Python
- OS: Windows
- Language runtime version: Python3.12
- Package version: google-genai==1.57.0 and it's dependencies

#### Steps to reproduce
just run the code
``` python
import os
import time

import httpx
import requests
from dotenv import load_dotenv
from google import genai
from google.genai import types
from google.genai.types import Video

if __name__ == '__main__':
load_dotenv()
api_key = os.getenv("GENAI_API_KEY")
proxy = os.getenv("GRPC_PROXY")
genai_client = genai.Client(
api_key=api_key,
http_options=types.HttpOptions(
httpx_client=httpx.Client(proxy=proxy)
)
)

# Generate a video via Veo
source = types.GenerateVideosSource(
prompt="Upbeat and adorable background music throughout the video. A close-up shot focusing on the face of a cute lynx-point Ragdoll cat, with its big, bright blue eyes staring at the camera curiously, then tilting its head adorably toward the lens."
)
config = types.GenerateVideosConfig(
duration_seconds=4,
aspect_ratio="16:9",
resolution="720p",
negative_prompt="nsfw",
)

operation: types.GenerateVideosOperation = genai_client.models.generate_videos(
model="veo-3.1-fast-generate-preview",
source=source,
config=config
)
while not operation.done:
print("Waiting for video generation to complete...")
time.sleep(10)
operation = genai_client.operations.get(operation)

generated_video = operation.response.generated_videos[0] if operation.response.generated_videos else None
# download the video directly via proxy and save
if generated_video:
video = generated_video.video
download_url = video.uri
actual_download_url = f'{download_url}&key={api_key}'
rsp = requests.get(actual_download_url, proxies={
'http': proxy,
'https': proxy
})
video_bytes = rsp.content
video = Video(uri=download_url, video_bytes=video_bytes)
video.save("cat-gen.mp4")

# extend the video
# re-create the config
config = types.GenerateVideosConfig(
duration_seconds=4,
aspect_ratio="16:9",
resolution="720p",
negative_prompt="nsfw",
)

# request for extend (will crash here)
operation: types.GenerateVideosOperation = genai_client.models.generate_videos(
model="veo-3.1-fast-generate-preview",
video=operation.response.generated_videos[0].video,
prompt="Upbeat and adorable background music throughout the video. A close-up shot focusing on the face of a cute lynx-point Ragdoll cat, with its big, bright blue eyes staring at the camera curiously, then tilting its head adorably toward the lens. and eyes blinking.",
config=config
)

while not operation.done:
print("Waiting for video generation to complete...")
time.sleep(10)
operation = genai_client.operations.get(operation)

generated_video = operation.response.generated_videos[0] if operation.response.generated_videos else None

# download the video directly via proxy and save
if generated_video:
video = generated_video.video
download_url = video.uri
actual_download_url = f'{download_url}&key={api_key}'
rsp = requests.get(actual_download_url, proxies={
'http': proxy,
'https': proxy
})
video_bytes = rsp.content
video = Video(uri=download_url, video_bytes=video_bytes)
video.save("cat-gen-extend.mp4")

```

Here is the .env look like:
```python
# this is my proxy location, which work well in video generation
GRPC_PROXY='http://user:password@192.168.24.100:6666'
# gemini api token
GENAI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxx
```

the first generation is downloaded successfully, but there is an error while trying to extend the video passing the first object via genai client.
```
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.4\plugins\python-ce\helpers\pydev\pydevd.py", line 1534, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.4\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\test\test_gen.py", line 69, in
operation: types.GenerateVideosOperation = genai_client.models.generate_videos(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\models.py", line 5725, in generate_videos
return self._generate_videos(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\models.py", line 5082, in _generate_videos
response = self._api_client.request(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\_api_client.py", line 1375, in request
response = self._request(http_request, http_options, stream=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\_api_client.py", line 1211, in _request
return self._retry(self._request_once, http_request, stream) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\tenacity\__init__.py", line 477, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\tenacity\__init__.py", line 378, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\tenacity\__init__.py", line 420, in exc_check
raise retry_exc.reraise()
^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\tenacity\__init__.py", line 187, in reraise
raise self.last_attempt.result()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\william\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\william\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\_base.py", line 401, in __get_result
raise self._exception
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\tenacity\__init__.py", line 480, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\_api_client.py", line 1188, in _request_once
errors.APIError.raise_for_response(response)
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\errors.py", line 121, in raise_for_response
cls.raise_error(response.status_code, response_json, response)
File "C:\code\repository-python\dify-official-plugins\tools\gemini_video\venv\Lib\site-packages\google\genai\errors.py", line 146, in raise_error
raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Your use case is currently not supported. Please refer to Gemini API documentation for current model offering.', 'status': 'INVALID_ARGUMENT'}}
```

I’m using direct download via the requests library because of issue #1946, and I haven’t been able to resolve this problem yet.

According to the official documentation, I used the Video instance returned from the first generation as the video parameter (matching the approach in the [official code example](https://ai.google.dev/gemini-api/docs/video?example=dialogue#extending_veo_videos)), but it still doesn’t work.
I also investigated the root cause by checking the google/genai/models.py file and found that the code simply creates a new Video object with uri and mime_type like this:

Image

Unfortunately, the genai tool will not return mime_type in the first generation, and even I put `video/mp4` in it, the error still remains.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.