diff --git a/backend/openai_client.py b/backend/openai_client.py index f36d192..8a5910e 100644 --- a/backend/openai_client.py +++ b/backend/openai_client.py @@ -1,14 +1,28 @@ from openai import OpenAI -import os -client = OpenAI( - api_key=os.getenv('OPENAI_API_KEY') -) +from backend.config_store import get_openai_key, get_openai_model + + +class OpenAIConfigurationError(Exception): + pass + + +def _client() -> OpenAI: + api_key = get_openai_key() + + if not api_key: + raise OpenAIConfigurationError( + 'OpenAI API key is not configured' + ) + + return OpenAI(api_key=api_key) async def ask_ai(prompt: str): + client = _client() + response = client.responses.create( - model='gpt-5', + model=get_openai_model(), input=prompt )