From a23a02576c6be966030581fc9bf9354cbbc85cc1 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:07:55 +0100 Subject: [PATCH] refactor: Refactors header --- src/app/services/openai.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/services/openai.py b/src/app/services/openai.py index 510445a..5fbb386 100644 --- a/src/app/services/openai.py +++ b/src/app/services/openai.py @@ -95,7 +95,7 @@ class OpenAIClient: def __init__( self, api_key: str, model: OpenAIModel, temperature: float = 0.0, frequency_penalty: float = 1.0 ) -> None: - self.headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} + self.headers = self._get_headers(api_key) # Validate model model_card = requests.get(f"https://api.openai.com/v1/models/{model}", headers=self.headers, timeout=2) if model_card.status_code != 200: @@ -107,6 +107,10 @@ def __init__( f"Using OpenAI model: {self.model} (created at {datetime.fromtimestamp(model_card.json()['created']).isoformat()})" ) + @staticmethod + def _get_headers(api_key: str) -> Dict[str, str]: + return {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} + def analyze_multi( self, code: str,