from openai import OpenAI from app.config import get_settings _client: OpenAI | None = None DEFAULT_MODEL = "z-ai/glm-5.2" # swap to "meta/llama-3.1-70b-instruct" if tool-calling isn't confirmed for 5.2 def _get_client() -> OpenAI: global _client if _client is None: settings = get_settings() _client = OpenAI( api_key=settings.nvidia_api_key, base_url="https://integrate.api.nvidia.com/v1", ) return _client def ask(prompt: str, model: str = DEFAULT_MODEL) -> str: """ Minimal single-turn call to NVIDIA NIM (OpenAI-compatible endpoint). No tools, no memory — just proves the API key + connection work end-to-end. """ client = _get_client() response = client.chat.completions.create( model=model, messages=[{"role": "user", "content": prompt}], ) return response.choices[0].message.content or ""