Table of Contents
This project was made as an automation system for a teacher to generate questions from a pdf file using the openai api, the project uses tview as its text user interface (TUI), directory creation, json file creation, api requests, .env file, turning pdfs to images and turning them to base64 tosend over http and stuff. I hope it could be a life saver to someone who is starting go and doesent know how to use tview or send api requests.
First you have to have go installed on your system, I am developing on windows so my goto way is to use scoop.sh, visit the website and install scoop, then search for go and follow the instruction.
You also need poppler, I recommend installing that from scoop as well, we will need pdftocairo to turn pdfs to images.
Go has made dependencies so much easier, all you have to do after cloning the project is to run :
- Powershell:
go mod tidy
The dependencies will be installed automagically.
-
Get an api key from openai, it will cost a buck or five, and if you know of a free api, feel free to use it.
-
Clone the repo
git clone https://github.com/mehybinator/pdf2q.git
-
Install go dependencies
go mod tidy
-
Create a ".env" file and input the following :
OPENAI_API = "YOUR_API_KEY"; QUESTION_AMOUNT = "5";
Run the program with :
make runIf you dont have make installed just use :
go build -o ./bin/pdf2q.exe ./cmd
./bin/pdf2q.exeRunning the code initially will cause an error, this is due to the fact that on initial run, the code will create the data folder with images, pdfs and questions subfolders, but the pdfs directory needs to contain a pdf for the program to work.
After you put your pdfs in the respective directory, running the program should show you a list of your pdfs, go ahead and pres enter on your desired pdf, immediately the images should be generated and the api request should be sent, now you have to wait for gpt4-omni to respond, you should see both errors and success messages after the program is finished, now navigate to data/question and you should see a json file names rightly after your pdf file, this file contains the generated question.
Mehran Arkak - mehran.arkak@protonmail.com
Project Link: https://github.com/mehybinator/pdf2q