Skip to content

Commit

Permalink
Merge pull request #274 from edenai/hotfix/delete-video-async
Browse files Browse the repository at this point in the history
[fix] video q&a google
  • Loading branch information
Daggx authored Oct 16, 2024
2 parents 09e0e97 + 65f1b98 commit 7705007
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions edenai_apis/apis/google/google_video_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,13 @@ def _request_question_answer(self, model, api_key, text, temperature, file_data)
try:
original_response = response.json()
except json.JSONDecodeError as exc:
self._delete_file(file=file_data["name"], api_key=api_key)
raise ProviderException(
"An error occurred while parsing the response."
) from exc

if response.status_code != 200:
self._delete_file(file=file_data["name"], api_key=api_key)
raise ProviderException(
message=original_response["error"]["message"],
code=response.status_code,
Expand All @@ -792,12 +794,12 @@ def video__question_answer(
api_key = self.api_settings.get("genai_api_key")
file_data = self._upload_and_process_file(file, api_key)
file_size_mb = self._bytes_to_mega(int(file_data.get("sizeBytes", 0)))
if file_size_mb >= 20:
if file_size_mb >= 10:
raise ProviderException(
message="The video file is too large (over 20 MB). Please use the asynchronous video question answering api instead.",
message="The video file is too large (over 10 MB). Please use the asynchronous video question answering api instead.",
)
if file_data["state"] == "PROCESSING":
sleep(3)
sleep(5)
file_data = self._check_file_status(file_data["uri"], api_key)

original_response, generated_text = self._request_question_answer(
Expand Down Expand Up @@ -887,6 +889,7 @@ def video__question_answer_async__get_job_result(
temperature=content["temperature"],
file_data=file_data,
)
self._delete_file(file=file_data["name"], api_key=api_key)
return AsyncResponseType[QuestionAnswerAsyncDataClass](
original_response=original_response,
standardized_response=QuestionAnswerAsyncDataClass(
Expand Down

0 comments on commit 7705007

Please sign in to comment.