-
Notifications
You must be signed in to change notification settings - Fork 464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(ai_services): raise exception if api_key None or empty #1056
base: main
Are you sure you want to change the base?
Conversation
@@ -48,6 +48,8 @@ | |||
class AIService(FrameProcessor): | |||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self._require_api_key: bool = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this could go in the constructor:
def __init__(self, *, require_api_key: bool = True, **kwargs):
super().__init__(**kwargs)
self._require_api_key: bool = require_api_key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, we can also add and use self._api_key at all places, currently we are using self._api_key just for validation
super().__init__(**kwargs)
self._api_key = api_key
self._require_api_key: bool = require_api_key```
@@ -44,6 +44,7 @@ def __init__( | |||
self, *, model="vikhyatk/moondream2", revision="2024-08-26", use_cpu=False, **kwargs | |||
): | |||
super().__init__(**kwargs) | |||
self._require_api_key = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super().__init__(require_api_key = False, **kwargs)
@@ -49,6 +49,7 @@ def __init__( | |||
**kwargs, | |||
): | |||
super().__init__(**kwargs) | |||
self._require_api_key = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super().__init__(require_api_key = False, **kwargs)
@@ -80,6 +80,7 @@ def __init__( | |||
**kwargs, | |||
): | |||
super().__init__(sample_rate=sample_rate, **kwargs) | |||
self._require_api_key = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super().__init__(require_api_key = False, sample_rate=sample_rate, **kwargs)
@@ -61,7 +63,10 @@ def set_model_name(self, model: str): | |||
self.set_core_metrics_data(MetricsData(processor=self.name, model=self._model_name)) | |||
|
|||
async def start(self, frame: StartFrame): | |||
pass | |||
if self._require_api_key and not self._api_key: | |||
raise Exception(f"{self}: Error: No api_key value found.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could make it more explicit: No api_key provided
or You need to pass an api_key
.
@@ -61,7 +63,10 @@ def set_model_name(self, model: str): | |||
self.set_core_metrics_data(MetricsData(processor=self.name, model=self._model_name)) | |||
|
|||
async def start(self, frame: StartFrame): | |||
pass | |||
if self._require_api_key and not self._api_key: | |||
raise Exception(f"{self}: Error: No api_key value found.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we create a custom expection for this, like APIKeyMissing / APIKeyError
, this is save us from cases where we would need to catch it but can only do it via expect Exception
@@ -48,6 +48,8 @@ | |||
class AIService(FrameProcessor): | |||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self._require_api_key: bool = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, we can also add and use self._api_key at all places, currently we are using self._api_key just for validation
super().__init__(**kwargs)
self._api_key = api_key
self._require_api_key: bool = require_api_key```
Please describe the changes in your PR. If it is addressing an issue, please reference that as well.
closes #941
Raises exception if the value of an API key is None or empty.