Skip to content

Commit d4f209f

Browse files
committed
integrating OPENAI and Langchain into the ChatUI, comments added for explainations with source links
Signed-off-by: BergZain <50025962+bergzain@users.noreply.github.com>
1 parent 0abb995 commit d4f209f

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/ChatUI_streamlit/LLMModel.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@
99
from langchain.prompts import PromptTemplate
1010

1111

12-
YourAPIKey = os.environ['OPENAI_API_KEY']
12+
YourAPIKey = os.environ['OPENAI_API_KEY'] # This is the API key for OpenAI
1313

14-
load_dotenv()
14+
load_dotenv() # Load the .env file
1515

16-
openai_api_key=os.getenv('OPENAI_API_KEY', 'YourAPIKey')
16+
openai_api_key=os.getenv('OPENAI_API_KEY', 'YourAPIKey') # Get the API key from the .env file
1717

18-
llm = ChatOpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key)
18+
llm = ChatOpenAI(model_name='gpt-3.5-turbo', openai_api_key=openai_api_key) # Load the LLM model
1919

2020

21-
embeddings = OpenAIEmbeddings(disallowed_special=(), openai_api_key=openai_api_key)
21+
embeddings = OpenAIEmbeddings(disallowed_special=(), openai_api_key=openai_api_key) # Load the embeddings
2222

23+
# This is the root directory for the documents i want to create the RAG from
2324
root_dir = '/Users/zainhazzouri/projects/RAG-Playground/core/src/sdk/python/rtdip_sdk/pipelines'
2425
docs = []
2526

26-
# Go through each folder
27+
# Go through each folder to extract all the files
2728
for dirpath, dirnames, filenames in os.walk(root_dir):
2829

2930
# Go through each file
@@ -35,7 +36,9 @@
3536
except Exception as e:
3637
pass
3738

38-
docsearch = FAISS.from_documents(docs, embeddings)
39+
docsearch = FAISS.from_documents(docs, embeddings) # Create the FAISS index
40+
# source https://python.langchain.com/docs/integrations/vectorstores/faiss_async
3941

40-
# Get our retriever ready
42+
# Get our retriever ready for the RAG or creating the chain
4143
RAG = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=docsearch.as_retriever())
44+
# source link for reference https://python.langchain.com/docs/use_cases/question_answering/document-context-aware-QA

0 commit comments

Comments
 (0)