forked from yigbt/EcoToxFred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllm.py
36 lines (27 loc) · 874 Bytes
/
llm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
import streamlit as st
def get_chat_llm() -> ChatOpenAI:
"""
Creates a ChatOpenAI LLM using the provided OpenAI API key and model.
Returns:
ChatOpenAI: The ChatOpenAI LLM
"""
return ChatOpenAI(
openai_api_key=st.secrets["OPENAI_API_KEY"],
model_name=st.secrets["OPENAI_MODEL"],
streaming=True,
temperature=0
)
def create_embeddings() -> OpenAIEmbeddings:
"""
Creates an OpenAIEmbeddings model using the provided OpenAI API key.
Returns:
OpenAIEmbeddings: The OpenAIEmbeddings model
"""
return OpenAIEmbeddings(openai_api_key=st.secrets["OPENAI_API_KEY"])
# create the llm, and the embeddings
# may now be imported as
# from llm import llm, embeddings
llm = get_chat_llm()
embeddings = create_embeddings()