The advancement of generative AI is remarkable. Now, with approximately 70 lines of Python code predominantly leveraging OpenAI GPT, llama-index, and Streamlit, you can craft chatbots infused with your specialized domain knowledge. This enables the creation of a personalized assistant tailored specifically for your needs.
This post is going to share how you can build your own powerful Chatbot for your own data!
1 Dependency
A few Python packages are needed for this app:
pip install streamlit openai llama-index nltk
Also, please get an OpenAI API key by following this guide:
Enter an identifier name (optional) and click on the Create secret key button.
Copy the API key to be used in this tutorial (the key shown below was already revoked).
2 Create the Chatbot
The project folder can be set up like this:
These files are:
a main.py to store the code of the app.
a data folder that stores the input data.
secrets.toml in the .streamlit folder that has the Open AI API key, like openai_key = 'Your OpenAI API key'
The main.py looks like this, this is all that it needs to pull up the chatbot:
Intuitively, it accepts the input from users, in this example it only accepts text and csv files, you can tweak the input types following the Streamlit guide.
Then the input file are saved and used to create a vector store, which has been used for the GPT to refer to in the question-answering sessions.
3 Activate the Chatbot
In the terminal of your laptop, run command:
The the app is up and you can upload your own files to the app, once that is done, the chat box will appear and you can ask questions regarding the data.
The sample credit card transaction data can be downloaded at datacamp.
๐ก
Watch out the cost of the usage of OpenAI API, set a limit for the cost just to avoid unexpected intensive usage.