Use Your Locally Stored Files To Get Response From GPT like ChatGPT | Python

Shweta Lodha
3 min readFeb 28, 2023

In this article, I’ll show you how you can use your locally stored text files to get response using GPT-3. You can ask questions and get response like ChatGPT.

On technology front, we will be using:

  • OpenAI
  • Langchain
  • Python

Input files

You can take bunch of text files and store them in a directory on your local machine. I’ve grabbed input data from https://essaypro.com/blog/essay-samples and created 5 text files. My files are all about ‘Cause And Effect Of Homelessness’ and are placed in a directory named Store.

Import Required Packages

As we are using Python, let’s go ahead and import the required packages.

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.text_splitter import CharacterTextSplitter
from langchain import OpenAI, VectorDBQA
from langchain.document_loaders import DirectoryLoader
import magic
import os
import nltk

If you do not have above packages installed on your machine, then please go ahead and install these packages before importing.

nltk.download(‘averaged_pe…

--

--