demoprep / llm_client_factory.py
mikeboone's picture
refactor: centralize LLM config and env-backed client setup
cd91248
raw
history blame contribute delete
555 Bytes
"""Centralized LLM client construction helpers."""
from __future__ import annotations
from openai import OpenAI
from llm_config import get_openai_api_key
def create_openai_client(
api_key: str | None = None,
timeout: int = 30,
max_retries: int = 3,
) -> OpenAI:
"""
Create a configured OpenAI client.
Uses env-backed OPENAI_API_KEY when api_key is not explicitly supplied.
"""
key = (api_key or "").strip() or get_openai_api_key(required=True)
return OpenAI(api_key=key, timeout=timeout, max_retries=max_retries)