From f31b2b35015441e984f2615a14176e7f3fc72c0c Mon Sep 17 00:00:00 2001 From: Jocelyn Vernay Date: Tue, 20 Feb 2024 11:02:46 +0100 Subject: [PATCH 1/3] Allow GiskardClient to read api key from env --- giskard/client/giskard_client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/giskard/client/giskard_client.py b/giskard/client/giskard_client.py index 4d4bcaad21..51217139c0 100644 --- a/giskard/client/giskard_client.py +++ b/giskard/client/giskard_client.py @@ -126,9 +126,9 @@ def _limit_str_size(json, field, limit=255): class GiskardClient: - def __init__(self, url: str, key: str, hf_token: str = None): + def __init__(self, url: str, key: str = None, hf_token: str = None): self.host_url = url - self.key = key + self.key = key or os.getenv('GSK_API_KEY') self.hf_token = hf_token base_url = urljoin(url, "/api/v2/") @@ -138,6 +138,9 @@ def __init__(self, url: str, key: str, hf_token: str = None): self._session.mount(url, adapter) + if self.key is None: + raise RuntimeError('You must provide an API key to connect to the Giskard Hub.') + self._session.auth = BearerAuth(key) if hf_token: From ada52c96b3666357bc572532da9d16e8dd275a07 Mon Sep 17 00:00:00 2001 From: Jocelyn Vernay Date: Tue, 20 Feb 2024 11:03:57 +0100 Subject: [PATCH 2/3] Normalize quotes --- giskard/client/giskard_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/giskard/client/giskard_client.py b/giskard/client/giskard_client.py index 51217139c0..053caf45f3 100644 --- a/giskard/client/giskard_client.py +++ b/giskard/client/giskard_client.py @@ -128,7 +128,7 @@ def _limit_str_size(json, field, limit=255): class GiskardClient: def __init__(self, url: str, key: str = None, hf_token: str = None): self.host_url = url - self.key = key or os.getenv('GSK_API_KEY') + self.key = key or os.getenv("GSK_API_KEY") self.hf_token = hf_token base_url = urljoin(url, "/api/v2/") @@ -139,7 +139,7 @@ def __init__(self, url: str, key: str = None, hf_token: str = None): self._session.mount(url, adapter) if self.key is None: - raise RuntimeError('You must provide an API key to connect to the Giskard Hub.') + raise RuntimeError("You must provide an API key to connect to the Giskard Hub.") self._session.auth = BearerAuth(key) From 9650f73ac540a5ab709c9ae8c7f76919308e727d Mon Sep 17 00:00:00 2001 From: Jocelyn Vernay Date: Tue, 20 Feb 2024 11:13:13 +0100 Subject: [PATCH 3/3] Update error message --- giskard/client/giskard_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/giskard/client/giskard_client.py b/giskard/client/giskard_client.py index 053caf45f3..12aa908c9f 100644 --- a/giskard/client/giskard_client.py +++ b/giskard/client/giskard_client.py @@ -139,7 +139,7 @@ def __init__(self, url: str, key: str = None, hf_token: str = None): self._session.mount(url, adapter) if self.key is None: - raise RuntimeError("You must provide an API key to connect to the Giskard Hub.") + raise RuntimeError("You must provide an API key for the client to connect to the hub") self._session.auth = BearerAuth(key)