Introduction

The backend for LayeredLearning is built on Flask. The application uses OpenAI's GPT-3.5 to generate explanations and quizzes on various topics, suitable for different educational levels. Additionally, it can accept user feedback and apply it to modify the generated content.

Concepts

The primary concepts this backend application handles include Language Model chains (LLMChain) on LangChain, Prompt Templates, and the OpenAI GPT-3.5 engine. It also uses Flask for creating the web service and Firebase for data storage and retrieval.

The principles of caching are also applied as the topic is stored in the Firebase real-time database and is retrieved if it has already been searched, reducing latency by a large amount for topics that have already been queried.

Untitled

Architecture

The application uses Flask, a lightweight web application framework, to create the web service. It uses Firebase Admin SDK for Python to interact with the Firebase Realtime Database and storage.

The OpenAI GPT-3.5 engine is employed for generating the educational content. The Flask application is served with the standard Flask server for local development purposes and subsequently deployed to PythonAnywhere.

Firebase is used as the database of choice, with the Realtime Database being used for increased performance.

Libraries Used

  1. Flask: Flask is a micro web framework written in Python. It's used to create the API endpoints in the application.
  2. Flask-CORS: This is a Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible. It is used to allow the frontend to communicate with the backend.
  3. os: This is a Python built-in library that allows you to interface with the underlying operating system that Python is running on, be that Windows, Mac, or Linux. In the application, it's used to manage environment variables.
  4. firebase_admin: This SDK allows interaction with Firebase from a server using Python. It's used for authentication, storage, and database services in the application.
  5. OpenAI: The OpenAI library is used to access OpenAI's GPT-3.5 API for the generation of educational content.
  6. Langchain: Langchain is a utility library designed to facilitate the usage of OpenAI's language models and Large Language Models as a whole. It provides the LLMChain, PromptTemplate, and ConversationChain classes used in the application to facilitate interactions with OpenAI.

API Endpoints

Endpoint 1: Explainer (/explainer)

This is a POST endpoint that expects a JSON object in the format {'topic': '<topic_name>'}. It returns a generated explanation of the provided topic, suitable for five different education levels in JSON format.