A Step-by-Step Guide to Building Your Own AI Tutor
Authors: Samuel Tobler & Katja Köhler
Important
Citation: Tobler, S., & Köhler, K. (2026). A Lecture-Specific AI-Based Tutor for Higher Education: Pedagogical Design and Empirical Evaluation. Education Sciences, 16(5), 812. https://doi.org/10.3390/educsci16050812
1.1 Preparing your Google account
(Skip the following sub-steps if you have already completed this process.)
- Visit Google and login to your Google account. If you do not have one, create one.
- Create a new Google Sheets file (https://docs.google.com/sheets).
- Give this sheet an identifiable name and create two worksheets: «Chat» and «Summary»
- Visit: https://console.cloud.google.com/ and log in with your Google account.
- Agree to the terms of service and continue.
- Click on "APIs & Services" and create a new project.
- Specify a project name and continue. Creating the project might take a while.
- Click on "Enable APIs and Services" and search for "Google Sheets API" and "Google Drive API."
- Enable the two APIs individually.
1.2 Connecting Google and RStudio
Run the following script to connect your Google Account to RStudio:
- Install and load dependencies
library("googlesheets4")
library("googledrive")
library("gargle")- Authenticate your account
Running these lines will open a browser window where you can log in to "Tidyverse API Packages" with your Google Account. Continue with the sign-in process and allow "Tidyverse API Packages" to view, edit, create, and delete all your Google Sheets spreadsheets and Google Drive files. Once the authentication is complete, you can close the browser window and continue in RStudio. Upon running the code below, a folder will appear in your working directory (called
.secrets) that contains a key to your Google account.
gs4_auth() # For Google Sheets
options(gargle_oauth_cache = ".secrets")
gs4_auth(cache = ".secrets")
drive_auth() # For Google Drive
options(gargle_oauth_cache = ".secrets")
drive_auth(cache = ".secrets")- Testing the setup
# Enter a file name (from your existing Google sheets library)
# Specify the sheet name
data <- read_sheet("LINKTOSHEET", col_names = F, sheet = "Sheet")
# Visualize the data
View(data)
2.1 Create an account on shinyapps.io
- Visit https://www.shinyapps.io/ and click on «Log In».
- Log In with your already existing account or create a new one. If you create a new one, you can choose an account name. This name will be also the link to your application.
Example: If your application should be called «geneticsBot», you can use this as the account name. Upon publishing your RShiny application, it can be found at https://geneticsBot.shinyapps.io
2.2 Connect your account to RStudio by running this code in RStudio
require("rsconnect")2.3 Get the Account Information
When logged in your shinyapps.io account, click on «Account» > «Tokens» and hit «Show». Click on «Show secret» and copy the resulting information to the script below. After running this code in RStudio, your account will be successfully linked.
rsconnect::setAccountInfo(name='YOURACCOUNTNAME', token='YOURTOKEN', secret='YOURSECRET')- Visit the OpenAI developer platform (https://platform.openai.com).
- If you already have an account, click on «Log in», otherwise, sign up with an email address and a password.
- Click on «Dashboard» and access your assistants and create a new one.
- Give your assistant a name and specify the system instructions (see below). Adjust these instructions according to your needs.
As a friendly Socratic biology teacher, evaluate the student's input based on factual correctness, providing concise feed-back. Encourage students expressing uncertainty while refraining from revealing the answer. Craft follow-up questions to deepen understanding, using information from provided files without introducing terms not present in them. Use natural conversational language.
- Evaluate the student's input for factual accuracy.
- Provide concise, encouraging feedback.
- Create a follow-up question based on information in the provided files.
- Avoid using terms not found in the files or referencing file names in your response.
- Limit responses to 50 words.
- Use natural conversational language.
- Use the same language as the user.
- Encourage students expressing uncertainty without providing direct answers.
- Remove any file name or document reference numbers from responses.
- Select the GPT model (e.g., GPT 4o).
- Activate the «File search» Tool and add files either by directly uploading individual files or by setting up a vector store (under «Dashboard» > «Storage»).
- Select «Text» as response format.
- Copy your assistant ID for later usage («asst_...»)
- Select «API keys» and create a new secret key. Copy this API key («sk-proj-…») for later usage.
OpenAI API-keyOpenAI Assistant IDGoogle Sheets Document ID
Required files:
app.R: Chatbot applicationfunctions/assistant_functions.R: The functions required for running up the chatbotfunctions/chat_setup.R: The information required for the chatbot that might be need to be adjustedfunctions/library.R: All required R packagesfunctions/style.css: Style sheet for the chatbot
To setup the chatbot, follow these steps:
- Open the files
chat/app.R,chat/functions/chat_setup.Rand create a new file calledprivate.Rin the same folder as theapp.Rfile. - In the
chat_setup.Rfile, specify the Google Sheet ID (sheet_id <- drive_get("...")$id") and adjust theChatbot Instructionsif necessary. - In the new
private.Rfile, specify your Open AI API key (apiKey <- "sk-...") and set it as system environment value (Sys.setenv(OPENAI_API_KEY = "sk-..."), specify your assistant ID (assistant_id <- "asst_..."), and the password for the dashboard (dash_pw <- "..."). - In the
app.Rfile, adjust the information, such as the contact address, as well as other formulations that you might want to change. - Run the application locally to double check that everything works properly.
- In the menu, select «File» > «Publish…» and choose the before connected Shiny Applications account.
- Select the files you want to upload (i.e., all files including the private files and Google secrets)
- Choose a title for your application (e.g., «chat») and hit publish.
Example: If you enter «chat» as a title, then your application will be available under https://geneticsBot.shinyapps.io/chat.
- On https://shinyapps.io, adjust the server configurations of the application accordingly (see «Server Configurations» below).
Required files:
app.R: Dashboard applicationfunctions/dashboard_variables.R: The variables required for running the dashbaord functionsfunctions/library.R: All required R packagesfunctions/style.css: Style sheet for the chatbot
To setup the dashboard, follow these steps:
- Open the file
dashboard/app.Ras well as the R scripts in thefunctions/subfolder. - Create a file named
private.Rin the same folder as you can find the dashboard application. - In the
private.Rfile, specify the OpenAI API key (apiKey <- "sk-...")and set it as system environment value (Sys.setenv(OPENAI_API_KEY = "sk-..."), and set the dashboard password (dash_pw <- "..."). - In the
app.Rfile, specify the start date of the semester (startdate2 <- "YYYY-MM-DD"). Additionally, adjust the information, such as the contact address, as well as other formulations that you might want to change. - In the
functions/dashboard_variables.Rfile, specify the GPT-model for the analyses ("gpt_dash_model <- "..."). Adjust other information if necessary. - Run the application locally to double check that everything works properly.
- In the menu, select «File» > «Publish…» and choose the before connected Shiny Applications account.
- Select the files you want to upload.
- Choose a title for your application (e.g., «dashboard») and hit publish.
- On https://shinyapps.io, adjust the server configurations of the application accordingly (see «Server Configurations» below).
To forward the chatbot or dashboard users to the Shiny applications via custom links (e.g., yourdomain.com/chatbot), you can create an empty HTML file and add the code below.
<meta http-equiv="refresh" content="0; URL='https://CHATBOTNAME.shinyapps.io/APPLICATIONNAME'" />
The following instruction applies to shinyapps.io-hosted servers. Please note that a payed plan might be required.
Standard settings
Instance Size: 2X-Large (2 GB) (Large instance is required to run the application)Instance Idle Timeout: 10 minutes
Advanced settings
-
Worker Settings- Max Worker Processes: 5 (One instance can start 5 worker processes; more simultaneously running processes required)
- Max Connections: 10 (Each worker process can handle 10 concurrent connections)
- Worker Load Factor: 5% (After 5%, a new worker process is added)
- Connection Timeout: 900 sec
- Read Timeout: 3600 sec
- Startup Timeout: 60 sec
- Idle Timeout: 5 sec
-
Instance Settings- Instance Load Factor: 50%
- Start Count: 1
Standard settings
Instance Size: 3X-Large (8 GB) (Large instance is required to run the application)Instance Idle Timeout: 30 minutes (Updating the dashboard may take time)
Advanced settings
-
Worker Settings- Max Worker Processes: 3
- Max Connections: 50
- Worker Load Factor: 5% (After 5%, a new worker process is added)
- Connection Timeout: 900 sec
- Read Timeout: 3600 sec
- Startup Timeout: 60 sec
- Idle Timeout: 5 sec
-
Instance Settings- Instance Load Factor: 50%
- Start Count: 1
To ensure data protection and avoid unintended access to sensitive data, all passwords and API keys are stored in an additional file referred to in the code as private.R. This file stores the password for the dashboard, the OpenAI API key, and the Assistant ID. When running your application, make sure that you have generated these files before executing the application.