Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
refactor: Refactors header
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Nov 7, 2023
1 parent 1f8a2a1 commit a23a025
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/services/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit a23a025

Please sign in to comment.