From 2b69956d0f3c90c85038fa04f1dbe1625693d1ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Mon, 11 May 2026 22:17:58 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20lazy=20OpenAI=20client=20=D0=B1=D0=B5=D0=B7=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20API=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/openai_client.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) 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 )