Skip to content

Commit

Permalink
Merge pull request #245 from edenai/SD2-187-key-error-content-google-…
Browse files Browse the repository at this point in the history
…text

[fix] catch google image QA error
  • Loading branch information
DninoAdnane authored Aug 5, 2024
2 parents 87d6ce6 + 5c6d9e9 commit 132470f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions edenai_apis/apis/google/google_image_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from http import HTTPStatus
import json
from typing import Sequence, Optional, BinaryIO, Dict
import numpy as np
Expand Down Expand Up @@ -54,6 +55,7 @@
)
from edenai_apis.features.image.question_answer import QuestionAnswerDataClass
from edenai_apis.utils.exception import ProviderException
from edenai_apis.utils.parsing import extract
from edenai_apis.utils.types import ResponseType
from edenai_apis.features.image.embeddings import (
EmbeddingsDataClass,
Expand Down Expand Up @@ -478,6 +480,13 @@ def _gemini_pro_vision_qa(
message="Internal Server Error",
code=500,
) from exc
if response.status_code >= HTTPStatus.BAD_REQUEST:
raise ProviderException(
extract(original_response, ["error", "message"])
or "Something went wrong when performing the request",
code=extract(original_response, ["error", "code"])
or HTTPStatus.BAD_REQUEST,
)
# calculate_usage_tokens(original_response=original_response)
answer = original_response["candidates"][0]["content"]["parts"][0]["text"]

Expand Down

0 comments on commit 132470f

Please sign in to comment.