Skip to content

Get help from an AI with university lectures and assignments

License

Notifications You must be signed in to change notification settings

nattvara/kthGPT

Repository files navigation

kthGPT

kthGPT is a free and open source tool that can watch a lecture for you. As a student, kthGPT can help you learn how to solve assignments and understand lecture slides and other course material.

This project is not affiliated with KTH. It's just a tool that's meant to be useful for KTH students.

Hero image

Table of Contents

Usage

kthGPT is available at https://kthgpt.com - it's free to use!

Understanding an assignment

1. Select an assignment

Take an image of the assignment you want help with. It can be handwritten or a screenshot straight from the exam. Note, kthGPT currently doesn't support PDF uploads.

Make sure the screenshot includes all the necessary information about the assignment. kthGPT can only consider one screenshot at the time.

The following is a good example of how to submit an image.

a good example

2. kthGPT will parse the assignment

Wait for kthGPT to analyze the assignment. This usually takes between 30-60 seconds.

3. Ask questions and find relevant lectures

The assignment is now ready for questions, ask-away! On the right hand side kthGPT is showing which lectures are relevant to the assignment, and where in the lecture you can learn how to solve the assignment.

Below are some examples of questions you can ask.

Detailed step-by-step instructions

Consider this assignment.

Example 2

kthGPT produced the following response to this question.

Question: Give me detailed step-by-step instructions of how to solve this assignment

Response Example response 2

Explaining exam solutions

Consider this image of an assignment and its solution

Example 40

kthGPT produced the following response to this question.

Question: Consider this solution to an assignment, explain how the solution works in detail. Include step by step instructions

The assignment is to analyze and solve a two-player game with a payoff matrix. The first step is to find all strategies that are strictly dominated. This means that for a given strategy, there is another strategy which gives a higher payoff regardless of the opponent's move. To do this, we can use the iterated elimination of strictly dominated strategies. This involves looking at all the strategies and seeing if any of them can be eliminated, i.e. if there is another strategy which always yields a higher payoff. In this case, strategy B is strictly dominated, as strategy A gives an equally high payoff in the first row of the matrix, and it also gives a higher payoff in the second row.

The next step is to find all rationalizable strategies for each player. This involves looking at the remaining strategies and seeing if any can be eliminated, as they are not considered 'rational'. For example, if one strategy yields a 0 payoff no matter what the opponent does, then it might not be considered rational. In this case, none of the remaining strategies are strictly dominated, so the subset consisting of strategies A, C, and D is the set of rational strategies for both players.

The third step is to find all the pure-strategy Nash equilibria. This means finding all the strategies where both players playing best response strategies will get the same payoff. In this case, the strategies A, C, and D all meet this criteria and hence can be considered Nash equilibria.

Finally, the fourth step is to find all pure-strategy perfect equilibria. This is similar to Nash equilibria, but with additional criteria. For a strategy to be considered a perfect equilibrium, both players must be playing Nash strategies and the strategy must not involve a player playing a weakly-dominated strategy. In this case, the strategies A and C are perfect equilibria, as they do not involve weakly-dominated strategies. The strategy D is not a perfect equilibrium, as it involves playing a weakly-dominated strategy.

Asking questions about notation

Sometimes it's tricky to put words against what question you have, consider this lecture slide.

Example 4

kthGPT produced the following answer to this question.

Question: What does the bolded one mean at the end of the slide? The one at 1_n_b

Example response 2

Watching lectures

1. Select lecture

Select a lecture that's already been watched or add a new one! kthGPT can watch lectures hosted on KTH Play or YouTube.

It can't watch any video on YouTube. Due to limited capacity kthGPT will only watch "relevant videos". Relevant videos are such that it thinks are Recorded Lectures. kthGPT uses a sample of the video to do this assessment.

2. Wait for kthGPT to "watch" the lecture

If the video has not been watched by kthGPT before, it will start watching the video and try to produce a summary. It will only listen to the audio, so nothing been shown or written in the lecture will be included in the summary.

This process is very resource intensive and usually takes between 20-60 minutes. This will be slower if many videos have been queued.

If the audio quality in the video is bad, the quality of the summary will be worse. kthGPT is generally best at understanding English. However, if the audio quality is good, Swedish should be just fine as well.

3. Ask questions about the lecture

The lecture is ready. kthGPT can now use GPT-3 to answer questions about the lecture. Some useful queries:

- Summarize the lecture for me into 10 bullets

This query obviously useful to get a brief overview about what's covered in the lecture

- Tell me the core concepts covered in the lecture and give some explanations for each

This usually produce very good results. Answers seem to be less inclined to summarise the audio transcript and focus more on the topics. Which seem to produce more accurate results.

- At which point in the lecture is X covered?

Pretty self explanatory, useful to quickly now where to look in a lecture.

- Where in the course book "X" can i read more about the topics from this lecture?

Very useful to find more reading instructions.

In this lecture the following question:

  • Where in the course book "Hans Peters, Game Theory: A Multi-Leveled Approach, Springer 2008" can i read more about the topics from this lecture?

Produce the following results

  • Hans Peters, Game Theory: A Multi-Leveled Approach, Springer 2008 (Chapter 6) provides a deep exploration of the topics discussed in this lecture. It includes discussion on transferable utility and the core, super-aditivity, and finding efficient outcomes in non-zero sum games, as well as balancing games and linear programming.

- If i didn't attend this lecture what would I have to read-up on?

Tends to produce quite brief answers, with very "google:able" keywords.

Run the tool locally

Docker

The easiest way to run kthGPT locally is using docker.

Update the environment.

cp .env.example .env

Make sure to update OPENAI_API_KEY=sk-xxx... with an API key from OpenAI available here.

Also set MATHPIX_APP_ID and MATHPIX_APP_KEY for the Mathpix API.

For Mathpix to work you need to set up a proxy to your local environment, for instance using ngrok.

# If host machine is running ARM (eg. M1 macs)
export DOCKER_DEFAULT_PLATFORM=linux/amd64

# Start the application
docker-compose up

# Download the course list
docker exec -it api sh -c "fetch_kth_courses"

The application should now be available on http://localhost:1337.

Development

The following commands are useful to get the project setup for local development.

Clone the repo

git clone https://github.com/nattvara/kthGPT.git
cd kthGPT
python --version
# Python 3.10.8   Tested with this version
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
python setup.py develop
playwright install
playwright install-deps

Start the database.

docker run --name db -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres

psql -h 127.0.0.1 -p 5432 -U postgres -c "CREATE DATABASE kthgpt;" # password: postgres

# Create the database
create_db_schema

Start the redis server (used as backend for the job server).

docker run --name redis -d -p 6379:6379 redis redis-server --requirepass redis

Start the OpenSearch index.

docker run -p 9200:9200 -p 9600:9600 -e "discovery.type=single-node" --name opensearch -d opensearchproject/opensearch:latest

Start a queue worker.

rq worker --with-scheduler --url='redis://:@localhost:6379' default download extract transcribe summarise monitoring approval metadata image image_metadata classifications
rq worker --with-scheduler --url='redis://:redis@localhost:6379' gpt # gpt queue must run on at least one separate worker

Start the web server.

uvicorn api:main --reload

Start a reverse proxy using ngrok (used for MathPix API).

ngrok http 8000

Make sure to update the value in the .env file accordingly API_ENDPOINT=https://xxx.ngrok.io/

Start the frontend.

# make sure pnpm is installed
npm install -g pnpm

cd web-ui
pnpm install

npm run dev

Testsuite

To run the testsuite execute the following command in the repository root.

$ pytest
=================================== test session starts ===================================
collected 100 items

tests/feature/api/test_assignments.py ........                                      [  8%]
tests/feature/api/test_courses.py .                                                 [  9%]
tests/feature/api/test_index.py .                                                   [ 10%]
tests/feature/api/test_lectures.py .                                                [ 11%]
tests/feature/api/test_query.py ........                                            [ 19%]
tests/feature/api/test_search.py ...............                                    [ 34%]
tests/feature/jobs/pipelines/analyse_lecture/test_clean_lecture.py .                [ 35%]
tests/feature/jobs/pipelines/analyse_lecture/test_download_lecture.py .             [ 36%]
tests/feature/jobs/pipelines/analyse_lecture/test_extract_audio.py .                [ 37%]
tests/feature/jobs/pipelines/analyse_lecture/test_transcribe_lecture.py ...         [ 40%]
tests/feature/jobs/pipelines/parse_image_upload/test_classify_subjects.py ...       [ 43%]
tests/feature/jobs/pipelines/parse_image_upload/test_create_description.py ....     [ 47%]
tests/feature/jobs/pipelines/parse_image_upload/test_create_search_queries.py ....  [ 51%]
tests/feature/jobs/pipelines/parse_image_upload/test_create_title.py ..             [ 53%]
tests/feature/jobs/pipelines/parse_image_upload/test_parse_image_content.py ...     [ 56%]
tests/feature/jobs/tasks/lecture/test_capture_preview.py .                          [ 57%]
tests/feature/jobs/tasks/lecture/test_classify_video.py ..                          [ 59%]
tests/feature/jobs/tasks/lecture/test_fetch_metadata.py .......                     [ 66%]
tests/feature/jobs/tasks/lecture/test_lecture_classify_subjects.py ..               [ 68%]
tests/feature/jobs/tasks/lecture/test_lecture_create_description.py .               [ 69%]
tests/unit/classifiers/test_subject.py ...........                                  [ 80%]
tests/unit/classifiers/test_subject_multipass.py ......                             [ 86%]
tests/unit/db/test_crud.py ..                                                       [ 88%]
tests/unit/db/models/test_image_question.py ........                                [ 96%]
tests/unit/index/test_lecture.py ..                                                 [ 98%]
tests/unit/tools/video/test_img.py ..                                               [100%]

=================================== 100 passed in 6.67s ===================================

Screenshots

kthGPT start-page

homepage

Add lectures from KTH Play or YouTube lecture

Add new lecture

Ask questions about lectures

Questions

Full transcript search across lectures

Search in transcripts

Ask questions about assignments

Ask questions about assignments

License

MIT © Ludwig Kristoffersson

See LICENSE file for more information.