The Doc Chatbot with LlamaIndex is a chatbot that answers questions about a PDF document. It uses the LlamaIndex and LangChain libraries to connect large language models (LLMs) to external data sources like PDF car manuals, enabling the creation of chatbots that can learn from diverse data sources and deliver good answers.
Follow the instructions below to run the Doc Chatbot with LlamaIndex application on your machine:
- Clone the repository to your local machine:
git clone https://github.com/conect2ai/carbot-manual-compare.git
- Navigate to the cloned repository:
cd carbot-manual-compare
- Enter the
doc-chatbot-with-llamaindex
folder:
cd doc-chatbot-with-llamaindex
-
Create an account at OpenAI API. You will need OpenAI credits to run the application, and in general, new users get $5 credits to test the API. This is enough to run the application;
-
Create an API key in the OpenAI API. To do this, click on the
View API keys
option and create a new API key. Copy the value from the key that was created; -
In the same directory where the
index.py
file is located on your machine, create the.env
file and paste the following code snippet, replacingyour-api-key
with the key you generated in step 5:
OPENAI_API_KEY='your-api-key'
-
In the same directory, create a folder called
data
and put the PDF car manual file, such asFord_Fiesta_2015.pdf
; -
Run the
index.py
script, replacing the variablequery_str
with the question you wish to ask the chatbot.
from langchain.callbacks import get_openai_callback
query_engine = index.as_query_engine()
with get_openai_callback() as cb:
query_str = "How does the air recycle button work?"
response = query_engine.query(query_str)
print(cb)
This will provide the chatbot's response to your question based on the information available in the car manual PDF file.