from langchain_openai import ChatOpenAI

from kbqa.config import Settings, validate_live_settings


def create_chat_model(settings: Settings) -> ChatOpenAI:
    validate_live_settings(settings)
    return ChatOpenAI(
        api_key=settings.dashscope_api_key,
        base_url=settings.dashscope_base_url,
        model=settings.chat_model,
        extra_body={"enable_thinking": False},
        temperature=0.2,
        streaming=True,
        timeout=120.0,
        max_retries=2,
    )
