This interactive script uses OpenAI's GPT-3 API to answer questions about a PDF document. It breaks the PDF document into chunks of text and uses GPT-3 to generate answers to user questions.
- Python 3
- OpenAI API key (sign up at openai.com)
- PyPDF2
- requests
- transformers
- python-dotenv
-
Clone the repository or download the ZIP file and extract its contents to a directory of your choice.
-
Install the required dependencies by running
pip3 install -r requirements.txt
in the project directory. -
Sign up for an OpenAI API key at openai.com and create a new file named
.env
in the project directory. -
Add your OpenAI API key to the
.env
file as shown below:API_KEY=your_api_key_here
Run the script by using the command python3 chat.py <URL>
in the project directory. Replace <URL>
with the URL of the PDF document you want to analyze.
Once the script is running, you can ask questions about the PDF document. Type a question and press Enter. The script will use GPT-3 to generate an answer to your question based on the PDF document.
After the script generates an answer, you can provide feedback by using one of the following options:
- Press the Spacebar to bypass the feedback prompt.
- Press the Up arrow key (
^
) to indicate that the answer was correct. - Press the Down arrow key (
v
) to indicate that the answer was incorrect.
If you indicate that the answer was incorrect, the script will prompt you to provide the correct information.
To quit the script, type quit
and press Enter.
This script should run on any platform that supports Python 3 and the required dependencies, including Windows, Mac, and Linux.
Note: This script was written with the assistance of ChatGPT, a language model trained by OpenAI.