"""Local LLM provider (e.g. Ollama)."""

import os
import requests


class LocalProvider:
    """Generate text using a local HTTP endpoint such as Ollama."""

    def __init__(self, model: str = "llama3"):
        self.base_url = os.environ.get("LOCAL_LLM_URL", "http://localhost:11434")
        self.model = model

    def generate(self, prompt: str) -> str:
        """Send a prompt to the local LLM endpoint and return the response."""
        resp = requests.post(
            f"{self.base_url}/api/generate",
            json={
                "model": self.model,
                "prompt": prompt,
                "stream": False,
            },
            timeout=300,
        )
        resp.raise_for_status()
        return resp.json()["response"]
