Before attempting this project, I didn't had any prior knowledge on how language models worked. I did use chatGPT to answer a few questions for me, but didn't built a solution from ground up. The problem shared was hard at first and eventually became easier. There were parts which were unknowns and a few which I knew I would be able to complete easily.
Demo is live here
The goal of this project is to enable user to upload any pdf and create answering bot out of it.
The foundation of the project is done. We are able to take in a pdf file, and expose APIs to ask questions to it.
Currently users are able to ask questions from only one book. Next steps would be :
- ability for users to upload a book of choice.
- ability configure the prompt (as owner of the book)
- ability for platform users list of books uploaded by self or other users
- ability to navigate to page of a particular book and ask questions
I took inspiration from askmybook and built the same using Ruby.
The v0, as it was aiming to exactly replicate what askmybook did, the architecture was dependent on two csv files namely book_embeddings.csv
and book_sections.csv
.
scripts/book.pdf
andscripts/create_embeddings.rb
, were used to generate./book_embeddings.csv
and./book_sections.csv
- To run this script on any machine, it was required, to have python and related python packages like
GPT2TokenizerFast
to be installed already. script could be run usingruby scripts/create_embeddings.rb
- The
app/services/answer_generation.rb
handled in finding the most relevant sections, embedding the context in the prompt, and use the prompt to answer the query. PS: This service is now updated to accomodate v0.1 More on v0 journey
v0 worked but it was slow.
Primary reason - We worked with large CSV and the logic was based on reading the CSV for each request.
We figured out that CSV files were not needed.
We moved away from that dependency and stored the embeddings as JSON in the database.
We also figured out, the interop with python was not required at all.
We removed it completely.
We are now a pure ruby implementation.