Skip to content

samueltobler/bioTutor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧬 bioTutor

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


Setting up the chatbot and dashboard

1. Setup a Google Sheets account and connect it to RStudio

1.1 Preparing your Google account

(Skip the following sub-steps if you have already completed this process.)

  1. Visit Google and login to your Google account. If you do not have one, create one.
  2. Create a new Google Sheets file (https://docs.google.com/sheets).
  3. Give this sheet an identifiable name and create two worksheets: «Chat» and «Summary»
  4. Visit: https://console.cloud.google.com/ and log in with your Google account.
  5. Agree to the terms of service and continue.
  6. Click on "APIs & Services" and create a new project.
  7. Specify a project name and continue. Creating the project might take a while.
  8. Click on "Enable APIs and Services" and search for "Google Sheets API" and "Google Drive API."
  9. Enable the two APIs individually.

1.2 Connecting Google and RStudio

Run the following script to connect your Google Account to RStudio:

  1. Install and load dependencies
library("googlesheets4") 
library("googledrive")
library("gargle")
  1. 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")
  1. 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. Setup a ShinyApps account and connect it to RStudio

2.1 Create an account on shinyapps.io

  1. Visit https://www.shinyapps.io/ and click on «Log In».
  2. 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')

3. Setup an OpenAI account and create an assistant

  1. Visit the OpenAI developer platform (https://platform.openai.com).
  2. If you already have an account, click on «Log in», otherwise, sign up with an email address and a password.
  3. Click on «Dashboard» and access your assistants and create a new one.
  4. Give your assistant a name and specify the system instructions (see below). Adjust these instructions according to your needs.

System Instruction

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.

Steps

  1. Evaluate the student's input for factual accuracy.
  2. Provide concise, encouraging feedback.
  3. Create a follow-up question based on information in the provided files.
  4. Avoid using terms not found in the files or referencing file names in your response.

Output Format

  • Limit responses to 50 words.
  • Use natural conversational language.
  • Use the same language as the user.

Notes

  • Encourage students expressing uncertainty without providing direct answers.
  • Remove any file name or document reference numbers from responses.
  1. Select the GPT model (e.g., GPT 4o).
  2. Activate the «File search» Tool and add files either by directly uploading individual files or by setting up a vector store (under «Dashboard» > «Storage»).
  3. Select «Text» as response format.
  4. Copy your assistant ID for later usage («asst_...»)
  5. Select «API keys» and create a new secret key. Copy this API key («sk-proj-…») for later usage.

4. Gather the required login information for all interfaces

  • OpenAI API-key
  • OpenAI Assistant ID
  • Google Sheets Document ID

5. Setting up the chatbot

Required files:

  • app.R: Chatbot application
  • functions/assistant_functions.R: The functions required for running up the chatbot
  • functions/chat_setup.R: The information required for the chatbot that might be need to be adjusted
  • functions/library.R: All required R packages
  • functions/style.css: Style sheet for the chatbot

To setup the chatbot, follow these steps:

  1. Open the files chat/app.R, chat/functions/chat_setup.R and create a new file called private.R in the same folder as the app.R file.
  2. In the chat_setup.R file, specify the Google Sheet ID (sheet_id <- drive_get("...")$id") and adjust the Chatbot Instructions if necessary.
  3. In the new private.R file, 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 <- "...").
  4. In the app.R file, adjust the information, such as the contact address, as well as other formulations that you might want to change.
  5. Run the application locally to double check that everything works properly.
  6. In the menu, select «File» > «Publish…» and choose the before connected Shiny Applications account.
  7. Select the files you want to upload (i.e., all files including the private files and Google secrets)
  8. 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.

  1. On https://shinyapps.io, adjust the server configurations of the application accordingly (see «Server Configurations» below).

6. Setting up the dashboard

Required files:

  • app.R: Dashboard application
  • functions/dashboard_variables.R: The variables required for running the dashbaord functions
  • functions/library.R: All required R packages
  • functions/style.css: Style sheet for the chatbot

To setup the dashboard, follow these steps:

  1. Open the file dashboard/app.R as well as the R scripts in the functions/ subfolder.
  2. Create a file named private.R in the same folder as you can find the dashboard application.
  3. In the private.R file, 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 <- "...").
  4. In the app.R file, 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.
  5. In the functions/dashboard_variables.R file, specify the GPT-model for the analyses ("gpt_dash_model <- "..."). Adjust other information if necessary.
  6. Run the application locally to double check that everything works properly.
  7. In the menu, select «File» > «Publish…» and choose the before connected Shiny Applications account.
  8. Select the files you want to upload.
  9. Choose a title for your application (e.g., «dashboard») and hit publish.
  10. On https://shinyapps.io, adjust the server configurations of the application accordingly (see «Server Configurations» below).

7. Forwarding your users to Shiny via custom links

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'" />

Server configurations

The following instruction applies to shinyapps.io-hosted servers. Please note that a payed plan might be required.

Chatbot Configurations

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

Dashboard Configurations

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

Login requirements and data handling

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.

About

A Lecture-Specific AI-Chatbot for Biology Classes

Resources

License

Stars

Watchers

Forks

Contributors