---
# System prepended metadata

title: Lecture Helper

---

# Lecture Helper
This is a group project by Dante Suwanda and Janosch Bühler.

<!-- <img src="https://i.imgur.com/a2uDDCs.png" style="zoom: 67%;" /> -->
[[_TOC_]]

---
## Inspiration
When we first started exploring ideas, we thought of reworking the project we did in AIFo, our AoE2-helper. It might have been a good idea, but we soon found out that OpenAI would be able to do those things with ease. But then we asked ourselves how many of our fellow students would really use this? We tried to be totally honest with ourselves and came to the conclusion that it would only be a few persons at most. So then we thought, what could be useful for students? And thus the idea for lecture helper was born: A service which takes questions, corrects them (grammatically), answers them and returns a Markdown file. It does a bunch of other cool stuff now, but we didn't think of that at the beginning and the ideas came gradually.

<div style="page-break-after: always;"></div>

## OpenAI

### What is OpenAI?
OpenAI is a company that researches and develops AI. The name is also often used for the newest AI they developed, which is currently GPT-3. In our project we used GPT-3.

OpenAI GPT-3 is a machine learning platform that can be used to train and deploy artificial intelligence models. It is also capable of natural language processing and can be used to generate text, translate languages, and understand and respond to questions.

### Getting started
OpenAI GPT-3 is very easy to get started with. All you need is a text editor and a web browser and you can start with using the services they offer. You can find all the necessary documentation and resources on the [OpenAI website](https://beta.openai.com/docs/introduction). You need to register there and after that you can use your API key to communicate with the AI via the API. There are also some really good [examples](https://beta.openai.com/examples) to get you started. 
Thats also how we started to work on our little project with OpenAI. We just began to import the OpenAI into our IDE and played around with it and test its boundaries. 

### Cost for commercial use
OpenAI GPT-3 is basically free for non-commercial use. For commercial use, pricing starts at \$10 per hour. You also have to consider that you have prices per use which apply to non-commercial and commercial use. Those start at \$0.10 per token and \$0.01 per API request. As a non-commercial user you get 18$ for free. Tokens are "pieces of words", 1000 tokens average about 750 words. 
> For the base models the following prices apply.

![](https://i.imgur.com/KrPCUCO.png)

We use Davinci for our project and the cost is therefore 0.06$/1k tokens.
### Market
You can use the services OpenAI offers for various things. Some might be niche but others could potentially get used by the whole world. Our lecture helper could potentially be of use for millions of students worldwide.
Open AI is a really powerful tool which, in combination with enough resouces, can basically learn and therefore automate almost everything.

<!-- ### Include a code snippet only if it demonstrates something interesting (e.g. only two lines of code to solve this or that)
###Anything else you find worth mentioning. 
-->

<div style="page-break-after: always;"></div>

## Lecture Helper
<!-- Rework titles, only for now to structure report -->
<!-- Include small intro here -->

### Specs
The backend of our tool is written in Python and the generation of the Markdown is done using Jinja. We plan to create a frontend, but the technologies we want to use for that aren't fixed yet.

> We created a simple workflow to better understand how it works exactly
<center>

![](https://i.imgur.com/GhmzfgC.png)

</center>

### What it can do
Our tool is great at giving answers to questions which have a definitive answer. It will then create a markdown file with the evaluated topic of the questions as the title, all the questions with their answers, and a quick summary. It also generates a table of contents and an inspirational quote which suits the topic of the questions. The inspirational quote is in a colored box, and the color of the box is a color that the AI regards as suiting for the topic.

### What it can't do
The AI is bad at giving answers to non-scientific questions. It will try to avoid answering those questions most of the time or give a vague answer. To get a useful answer, you need to pressure the AI into giving it by including things like *'Answer the question and don't avoid it.'*

We expected this and it isn't a problem for us. Our lectures are scientific and the quality of the answers to our questions is quite good. If you ask theological questions the quality of the answers is interesting and quite amusing. We don't regard this as a problem because we don't think that you should ask an AI those questions anyway.

### Challenges
We tried to keep the count of API requests per generated PDF low to be able to generate it faster and to keep the costs down. We came to the conclusion that it would be a good idea to send all the questions in one request. This also had the advantage that the AI could evaluate the connections and the topic of the questions way better. But it was really hard to convince the AI to give us separate answers to each question and not merge all the answers together. We found out that the best way to achieve that was to give it short and simple sentences as instructions on what it had to do with the next lines. If the instructions were long sentences or complicated, it ignored some of the instructions.
We also narrowed the input down by pre-defining some instructions like that the answer should be "a simplified and scientic answer". Because the AI is input reliant and sensitive, pre-defining some instructions is very important, so that the user can ask short questions or give little input, but gets a usable answer for the lecture.

### Wordsmithing
To some questions the AI returns, for human understanding, random and out of context answers. Therefore we tried to mitigate this problem by manually appending predefining sentences to each user input. Below are some interesting API query examples.

Because our lecture helper is for students who are interested in fact-based knowledge, we defined each request as a question that requires scientific answer:

```python=
response_scientific_definition = query_openai("I need a simple definition for each line of the text that starts below. Separate your answers by ###: \n\n" + joined_notes)
```
---
The following statement also corrects the user input which is also displayed in our final notes. This is a nice and easy way to guarantee the grammatical correctness of our returned markdown file and will simultaneously have a nice learning effect on it's user.
```python=
response_question = query_openai("Correct these sentences to standard English and separate your answers with a ###: \n\n" +joined_notes)
```
---
It was quite hard to stop the enthusiasm of the AI when picking a CSS color code. Sometimes it explained why it picked the color, sometimes it returned multiple color codes and sometimes it didn't return a color code but returned a made up color. We would have been able to fix this by using something like regex but doing this only with the AI was a fun challenge.
```python=
response_color = query_openai("A CSS color code that matches the keywords below. The CSS code should be bright and suited for black text. Answer only with the CSS code:  \n\n" + str(output['keywords']))
```
### Example
You can view an example in the [appendix](#Example-Output)
### Current status
Our tool is already usable and works well. You do, however, have to submit your questions either via a commandline interface or as a CSV file. Sometimes (about 5% of the time) the format in which the AI replies is weird, and we still need a way to fix that or minimize it even further.
But in general it works astonishingly well and already had it's use cases for our lectures.

<div style="page-break-after: always;"></div>

### Possibilites of Lecture Helper
You could fine-tune the OpenAI GPT-3 Model by submitting PDFs on your own. You could do that by submitting the PDFs of the course you are currently visiting. Those PDFs would be perfect because they include the things you need to know for the exam. Sometimes there are multiple definitions of the same thing and right now the AI could get that wrong because it simply doesn't know which definition we are using.

## Conclusion
This project was a lot of fun and taught us much about OpenAI. We noticed that it is not hard at all to start working with such a powerful tool and implementing it in to a little project like lecture helper, but we can only imagine how hard it must be to master that kind of technology, for example to go as far as putting human lives into an AI-controlled vehicle, this would take much more experience, precision and resources.We would absolutely love to use a tool like OpenAI GPT-3 in a bigger project. We had a lot of fun experimenting and testing the AI.

It was really interesting to see how far the technology of text-based AIs has come, how well they work and how easy it is to implement them into your projects. It was a lot of fun to think of other possible projects that we could do with it, because the possibilities of AI are limitless and you can get really creative with them. And we still didn't fully let go of the idea to improve our aoe2-helper which we made in AIFo so we might do that in the future.

<!-- ### What are your conclusions? Ask yourself: would you like to use the tool in a semester or bachelor project? Describe what kind of project idea that would be? -->

---

<!-- <div style="page-break-after: always;"></div> -->
# Appendix
## Jinja Template
> Our Jinja template is simple but includes everything we need quite elegantly. We had to include some CSS styling for the inspirational quote which is supported by Markdown.

```javascript=
# {{ values.topic }}
<div style="background-color: {{ values.color }};border-radius: 10px;">
    {{ values.inspirational_quote }}
</div>
[[_TOC_]]
## Notes
{% for entry in values.entries %}

### {{ entry.keyword }}

> {{ entry.question }}

{{ entry.response }}
{% endfor %}

## Summary
{{ values.summary }}
```
## Example Output
This is a real life example of notes we took with lecture helper during our CN2 lecture:

>In the screenshot below you can see a snipped of the postman request that our lecture helper makes to OpenAI

<center>

![](https://i.imgur.com/RYDPZbN.png)
<div style="page-break-after: always;"></div>

</center>

>And the following markdown file is the output that our lecture helper returns to the user:

<center>


![](https://i.imgur.com/fWp0H5Z.png)
<div style="page-break-after: always;"></div>
    
![](https://i.imgur.com/HWNa8uK.png)

</center>