CoolFace
Apppublic

lenox-ai/prototype

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
model_loading.py38 linesDownload Raw Back to src
1from langchain.chat_models import ChatOpenAI2from environs import Env3import typing4 5 6def load_open_ai_llm(model_loading_kwargs: typing.Optional[dict] = None) -> ChatOpenAI:7    """Load the openai language model8 9    Args:10        model_loading_kwargs (typing.Optional[dict], optional): Keyword arguments for loading the model.11            These are passed to the ChatOpenAI class. Defaults to None.12 13    Returns:14        ChatOpenAI: ChatOpenAI language model15    """16    env = Env()17    env.read_env()18    openai_api_key = env.str("OPENAI_API_KEY")19    openai_organization = env.str("OPENAI_ORGANIZATION")20 21    # Create the default model kwargs22    default_model_kwargs = dict(23        model_name="gpt-3.5-turbo",24        temperature=0.0,25        openai_api_key=openai_api_key,26        openai_organization=openai_organization,27    )28 29    # Update the default model kwargs with the provided model loading kwargs30 31    if model_loading_kwargs:32        default_model_kwargs.update(model_loading_kwargs)33 34    # Load the model35    openai_llm = ChatOpenAI(**default_model_kwargs)36 37    return openai_llm38