Skip to content

Commit 554cb6a

Browse files
committed
[fix] handle sent user api_keys to google
1 parent 28ffcad commit 554cb6a

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

edenai_apis/apis/google/google_api.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from google.cloud import translate_v3 as translate
66
from google.cloud import videointelligence, vision
77
from google.cloud.language import LanguageServiceClient
8+
from google.oauth2 import service_account
89

910
from edenai_apis.apis.google.google_audio_api import GoogleAudioApi
1011
from edenai_apis.apis.google.google_image_api import GoogleImageApi
@@ -43,14 +44,24 @@ def __init__(self, api_keys: Dict = {}):
4344
self.webhook_settings = load_provider(ProviderDataEnum.KEY, "webhooksite")
4445
self.webhook_token = self.webhook_settings["webhook_token"]
4546
self.project_id = self.api_settings["project_id"]
46-
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.location
47+
48+
clients_init_payload = {}
49+
if self.location:
50+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.location
51+
else:
52+
credentials = service_account.Credentials.from_service_account_info(
53+
self.api_settings
54+
)
55+
clients_init_payload["credentials"] = credentials
4756

4857
self.clients = {
49-
"image": vision.ImageAnnotatorClient(),
50-
"text": LanguageServiceClient(),
51-
"storage": storage.Client(),
52-
"video": videointelligence.VideoIntelligenceServiceClient(),
53-
"translate": translate.TranslationServiceClient(),
58+
"image": vision.ImageAnnotatorClient(**clients_init_payload),
59+
"text": LanguageServiceClient(**clients_init_payload),
60+
"storage": storage.Client(**clients_init_payload),
61+
"video": videointelligence.VideoIntelligenceServiceClient(
62+
**clients_init_payload
63+
),
64+
"translate": translate.TranslationServiceClient(**clients_init_payload),
5465
"llm_client": LLMEngine(
5566
provider_name="gemini",
5667
provider_config={
@@ -59,6 +70,4 @@ def __init__(self, api_keys: Dict = {}):
5970
),
6071
}
6172

62-
aiplatform.init(
63-
project=self.project_id,
64-
)
73+
aiplatform.init(project=self.project_id, **clients_init_payload)

edenai_apis/loaders/data_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def load_key(provider_name, location=False, api_keys: Dict = {}):
4444
# check_messsing_keys(provider_settings_data, data)
4545

4646
if location:
47-
return data, provider_settings_path
47+
return data, provider_settings_path if not api_keys else ""
4848
return data
4949

5050

0 commit comments

Comments
 (0)