Seeking Guidance on Building an LLM Tutor

I have developed a couple of working RAG Q&A systems and now I’d like to flip the switch. Instead of users asking the model questions, I’d like for the model to ask the user questions which it will evaluate against the context documents and then explain to the user why he/she is right/wrong.

Anyone doing this now? If so, could you talk a little about your logic flow? I have some ideas, but I thought it would be good to hear from someone who actually has experience doing it to gain some insights.

here is what I came up with, I need to find a way to speed up the response time. Feel free to reach out if you need anything else. Make sure you install the openai library and import openai

It’s a good practice to keep sensitive information like API keys in environment variables

Function to manage chat with GPT model

def chat_with_gpt(messages, model=“gpt-3.5-turbo”):
Function to simulate a chat with a GPT model using OpenAI’s ChatCompletion API.
messages (list): A list of message dictionaries, representing the conversation history.
model (str): The GPT model to use for the chat.
str: The assistant’s reply message content.
# Make an API call to get a chat completion from the GPT model
response = openai.ChatCompletion.create(


# Extract the assistant's reply from the API response
return response.choices[0].message["content"]

Initialize conversation history as an empty list

conversation_history =

Add a system message to set the behavior of the assistant

“role”: “system”,
“content”: ("You are a Python Programmer creating a game about Python Trivia. "
“Give 3 to 5 motivational happy emoji’s when the user answers correct”
“Ask the user their name, than address them by that name”
"Ask one-answer questions about Python’s history and basic functionality. "
"Make all questions multiple choice and space the 4 answers with a space or a tab. "
"Place an ‘a’, ‘b’, ‘c’, or ‘d’ next to the answers so that the user can select a one-letter response. "
"If the user gets the answer wrong, respond with a Python emoji at the begining and end of end say ‘(python emoji)I am sorry, that was incorrect, please try again.(python emoji)’ "
“allow the user to answer the same question wrong twice before moving on to the next question”
"The user must answer at least 10 questions before exiting is an option. "
"On question 11, ask if they would like to continue or quit. "
"allow the user two wrong answers per question before moving on to the next question. "
"Once the user says they want to quit, output their score in percentage by dividing the number of correct answers by the number of questions. "
“Only use factual data for correct answers”
“At the end of the quiz review all questions with user that were answered incorrectly and give a detail description of why the answer you gave is correct”)

Initiate the conversation by prompting the user to start the trivia game

This will set the stage for the trivia game

“role”: “assistant”,
“content”: “:snake: Let’s start shall we?:snake:

Main loop to handle the chat

while True:
# Display the initial assistant message to kick-off the trivia
if len(conversation_history) == 2:
print(f"Assistant: {conversation_history[-1][‘content’]}")

# Prompt the user for input
user_message = input("You: ")
# Append the user's message to the conversation history
conversation_history.append({"role": "user", "content": user_message})
# Get the assistant's response by calling the chat_with_gpt function
assistant_response = chat_with_gpt(conversation_history)
# Append the assistant's response to the conversation history
conversation_history.append({"role": "assistant", "content": assistant_response})
# Display the assistant's response
print(f"Assistant: {assistant_response}")
1 Like