Joris de Jong Profile picture
I help you implement Generative AI | Every Saturday, I navigate the world of AI development with AI Unchained ⬇️

Jun 14, 2023, 10 tweets

ChatGPT is great for studying.

But did you know you can use it to help you prepare for specific exams?

With the power of @LangChainAI you can!

Here's a 9-step breakdown including code: 🧵

#AI #study #buildinpublic #indiehacker

1/9 A high-level overview:

1. Input: PDF of study material
⬇️
2. Process documents
⬇️
3. Generate questions based on study material and exam guidelines
⬇️
4. Answer the questions based on the study material

You could combine step 3 & 4, but separating them = better results👇

2/9 Let's dive into the code:

First, load and process data for question generation.

I'm using the new gpt-3.5-turbo-16k model for a larger context window.

Result: Less calls to the model and higher context-awareness

3/9 Process the data for question answering.

We'll be storing the data in a vector database for easy retrieval and search possibilities later.

Standard gpt-3.5-turbo model for lower cost.

Lower chunk size = lower token usage when retrieving.

4/9 The part where you can get creative. Prompting.

Prompting is key to getting great results. Play around with this and get as creative as you want.

You could let it generate multiple-choice questions, in any language you'd like, include your exam criteria and much more.

5/9 Generating the actual questions.

Initialize the large language model. You can use the one you like most.

Use the refine summarization chain to move through all the documents and generate questions based on the content provided.

6/9 Create the vector database and initialize the retrieval Q&A chain.

Work with the embeddings of your choice. Set up your preferred vector database and initialize the Retrieval chain with the database as the retriever.

We're now all set for answering the questions.

7/9 Run the answering chain and print the results.

Tada... You've just created personalized practice questions for your exam!

As I said, prompting determines the quality of your results. Play around with this.

Check out @Luc_AI_Insights for some advanced prompting tips!

8/9 How much does this cost?

You can track your OpenAI API costs with this simple function. Just wrap all the code within it and see your token cost.

I just did this for a 30-page document. Total cost? $0.10.

Not bad for some detailed exam prep if you ask me.

9/9 Say thanks to @LangChainAI and @hwchase17.

LangChain is such a powerful framework. It gives you instant access to some of the most advanced technology we've seen.

If you have any questions, don't hesitate to ask!

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling