99from 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
2324root_dir = '/Users/zainhazzouri/projects/RAG-Playground/core/src/sdk/python/rtdip_sdk/pipelines'
2425docs = []
2526
26- # Go through each folder
27+ # Go through each folder to extract all the files
2728for dirpath , dirnames , filenames in os .walk (root_dir ):
2829
2930 # Go through each file
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
4143RAG = 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