From ef1241c95b5b1a253a415ffe9289c33c7dfa3793 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 20 Jan 2025 09:44:47 +0800 Subject: [PATCH] Refactor GPT client initialization to avoid redundant code --- gpt_shows_rename/gpt.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gpt_shows_rename/gpt.py b/gpt_shows_rename/gpt.py index b614283..e7ecd79 100644 --- a/gpt_shows_rename/gpt.py +++ b/gpt_shows_rename/gpt.py @@ -76,9 +76,9 @@ async def get_response(cfg: Config, inp: str, files: List[str], prompt += f'\nThe TMDB ID is `{tmdb_id}`.' if tvdb_id: prompt += f'\nThe TVDB ID is `{tvdb_id}`.' + http_client = httpx.AsyncClient(proxy=cfg.proxy) + client = openai.AsyncClient(api_key=cfg.api_key, base_url=cfg.base_url, http_client=http_client) if is_support_structed_output(cfg.model): - http_client = httpx.AsyncClient(proxy=cfg.proxy) - client = openai.AsyncClient(api_key=cfg.api_key, base_url=cfg.base_url, http_client=http_client) result = None mes = '' refusal = '' @@ -107,8 +107,6 @@ async def get_response(cfg: Config, inp: str, files: List[str], result = Files(**result) return result else: - http_client = httpx.AsyncClient(proxy=cfg.proxy) - client = openai.AsyncClient(api_key=cfg.api_key, base_url=cfg.base_url, http_client=http_client) res = await client.chat.completions.create( model=cfg.model, messages=[