"""LLM adapter — builds a LangChain chat model from config. LangChain's BaseChatModel IS the contract,
so the provider (local Ollama now; cluster-served or API later) is swappable without touching the agent.
"""
from __future__ import annotations

from fxhnt.config import Settings


def build_chat_model(settings: Settings):  # type: ignore[no-untyped-def]  # returns langchain BaseChatModel
    a = settings.agent
    if a.provider == "ollama":
        from langchain_ollama import ChatOllama

        return ChatOllama(model=a.model, base_url=a.base_url, temperature=a.temperature)
    if a.provider == "openai":
        from langchain_openai import ChatOpenAI

        return ChatOpenAI(model=a.model, temperature=a.temperature)
    raise ValueError(f"unknown LLM provider: {a.provider!r}")
