This article is the revised version of my previous article published here. Reason for this revision is, GPT Index is renamed to LlamaIndex. Here problem is not only renaming, lot many classes are removed, function parameters are changed and much more.
So, let’s get started.
In this article, I’ll show you how can you create a basic chat bot which utilizes the data provided by you. Here we will be using LlamaIndex, OpenAI and Python.
Let’s get started by installing the required Python module.
We need to install, two packages named gpt_index and langchain and this can be done using below lines:
pip install llama-index
pip install langchain
Next, we need to import those packages so that we can use them:
from llama_index import SimpleDirectoryReader,GPTListIndex,GPTVectorStoreIndex,LLMPredictor,PromptHelper,ServiceContext,StorageContext,load_index_from_storage
from langchain import OpenAI
Please note that, here, we don’t need an GPU because we are not doing anything local.
Grab OpenAI Key
To grab the OpenAI key, you need to go to https://openai.com/, login and then grab the keys using highlighted way:
Once you got the key, set that inside an environment variable(I’m using Windows). If you do not want to set as an environment, you have to pass this key in each and every function call.
os.environ["OPENAI_API_KEY"] = "YOUR_KEY"
Once our environment is set, next thing we need is data. Here, you can either take an URL having all the data or you can take the data, which is already downloaded and is available in the form of a flat file.
If you are going with URL, then you use wget to download your text file:
Once text file is downloaded, make sure to keep it in a directory. If you have multiple text files, you can keep all of them into the same directory.
Now we have the data, we have the knowledge. Next thing is to use this knowledge base.