from langchain_openai import ChatOpenAI
from openai import AsyncOpenAI
from pydantic import SecretStr

from .base import BaseLlm


class OpenAiLlm(BaseLlm):
    def __init__(
        self,
        model: str,
        api_key: str | None = None,
    ):
        self._native = AsyncOpenAI(api_key=api_key)
        langchain_api_key = SecretStr(api_key) if api_key else None
        self._langchain = ChatOpenAI(
            model=model, api_key=langchain_api_key, temperature=0
        )

    @property
    def native(self) -> AsyncOpenAI:
        return self._native

    @property
    def langchain(self) -> ChatOpenAI:
        return self._langchain
