"""Thin wrapper around the Groq chat API.""" from functools import lru_cache from groq import Groq from .config import settings @lru_cache def _client() -> Groq: return Groq(api_key=settings.groq_api_key) def chat(messages: list[dict], max_tokens: int = 2048, temperature: float = 0.2) -> str: if not settings.groq_api_key: raise ValueError("GROQ_API_KEY is not set in .env") kwargs = dict( model=settings.llm_model, messages=messages, temperature=temperature, max_tokens=max_tokens, ) if "gpt-oss" in settings.llm_model: kwargs["extra_body"] = {"reasoning_effort": "low"} # faster, saves free-tier tokens resp = _client().chat.completions.create(**kwargs) return (resp.choices[0].message.content or "").strip()