Build a LLM app with RAG to chat with any AI newsletter on Substack in just 30 lines of Python Code (step-by-step instructions):
1. Import necessary libraries
• Streamlit for building the web app
• Embedchain for the RAG functionality
• tempfile for creating temporary files and directories
2. Configure the Embedchain App
For this application we will use GPT-4 Turbo, you can choose from cohere, anthropic or any other LLM of your choice.
Select the vector database as the opensource chroma db (you are free to choose any other vector database of your choice)
3. Set up the Streamlit App
Streamlit lets you create user interface with just python code, for this app we will:
• Add a title to the app using 'st.title()'
• Create a text input box for the user to enter their OpenAI API key using 'st.text_input()'
4. Initialize the Embedchain App
• If the OpenAI API key is provided, create a temporary directory for the vector database using 'tempfile.mkdtemp()'
• Initialize the Embedchain app using the 'embedchain_bot' function
5. Get the Substack Newsletter URL from the user and add it to the knowledge base
• Use 'st.text_input()' to get the substack URL from the user
• Given the video URL, add it to the embedchain application
6. Ask question about the AI newsletter and display the answer
• Create a text input for the user to enter their question using 'st.text_input()'
• If a question is asked, get the answer from the Embedchain app and display it using 'st.write()'
Full RAG Application Code to Chat with Substack Newsletter👇
Working Application demo using Streamlit
Paste the above code in vscode and run the following command: 'streamlit run chat_substack.py'
If you’re interested in:
- ML/NLP
- LLMs
- RAG
Connect with me → @Saboo_Shubham_
My Newsletter →
Everyday, I share tip & tutorials on above topics on X and my newsletter. unwindai.substack.com
Find all the awesome LLM Apps demo with RAG in the following Github Repo.
Build LLM app with RAG in a few lines of Python Code (step-by-step instructions):
1. Install Embedchain
Embedchain is an opensource AI framework for creating LLM apps with RAG. It effectively segments data into manageable chunks, generates relevant embeddings, and stores them in a vector database for optimized retrieval.
3 ways to run Llama-3 locally (100% free and without internet):
1. GPT4All
An open-source project that provides tools and software to run powerful LLMs on your computer, without needing access to expensive GPU hardware or cloud services.
2. LM Studio
It is a tool that allows you to run Llama-3 and other opensource LLMs offline on your local PC.
You can download the LM Studio application, install it, and then use it to download and run any opensource LLM completely offline.