Skip to content

Latest commit

 

History

History
156 lines (124 loc) · 4.54 KB

README.md

File metadata and controls

156 lines (124 loc) · 4.54 KB

Sunbird AI API

coverage badge tests

This repository contains code for the publicly accessible Sunbird AI APIs.

To get started using the API, view the tutorial.

Getting started locally on Windows

Ensure virtualization is enabled on your computer

This is required because CPU virtualization is needed for Windows to emulate Linux. For more on enabling virtualization.

Ensure your windows is fully updated.

Install WSL (Windows Subsystem for Linux). This is required because redis is not officially supported on Windows.

Downloading, Setting Up, and Configuring WSL on Windows

  • Open PowerShell as an Administrator and run the following command to enable WSL:
    wsl --install
  • Restart your computer if prompted.
  • Once the system restarts, set up your Linux distribution (e.g., Ubuntu) from the Microsoft Store.

After successfully installing wsl:

  • Press windows button and in the search bar type windows features on or off

  • Click on Turn Windows features on or off and a pop-up window will appear features2

  • Ensure option Windows Subsystem for Linux is checked

    features

  • Restart your computer and launch Ubuntu

Cloning the API Repository Locally on Your Windows Machine

  • Open your WSL terminal (e.g., Ubuntu).

  • Navigate to the directory where you want to clone the repository:

    cd /mnt/c/your-directory
  • Clone the Sunbird AI API repository:

    git clone https://github.com/SunbirdAI/sunbird-ai-api.git
  • Continue with Getting started locally on Linux/macOS

Getting started locally on Linux/macOS

To run the app locally:

  • Create and activate a local environment

    python3 -m venv .venv
    source .venv/bin/activate
  • Install the requirements:

    pip install -r requirements.txt
  • Set the environment variables in a .env file, the following variables are required:

    SECRET_KEY
    DATABASE_URL
    RUNPOD_API_KEY
    REDIS_URL
    RUNPOD_ENDPOINT
    AUDIO_CONTENT_BUCKET_NAME
    

    NB: Reach out to the engineering team to get these environment variables.

Install Redis, this is required for the Rate Limiting functionality.

sudo apt update && sudo apt install redis-server
  • Start the Redis sever:

    sudo service redis-server start
  • Verify that Redis is running:

    redis-cli ping

Setting Up and Configuring PostgreSQL Server

  • Install PostgreSQL:

    sudo apt-get install postgresql postgresql-contrib
  • Start the PostgreSQL service:

    sudo service postgresql start
  • Switch to the PostgreSQL user:

    sudo -i -u postgres
  • Open the PostgreSQL interactive terminal:

    psql

Install tailwind css.

  • Run tailwind in a separate terminal tab:

    npx tailwindcss -i ./app/static/input.css -o ./app/static/output.css --watch

This step is only necessary if you're going to make changes to the frontend code.

Creating PostgreSQL Database and Running Alembic Migrations

  • Create a new database:
    CREATE DATABASE sunbird_ai;
  • Exit the PostgreSQL interactive terminal:
    \q
  • Navigate to the API repository directory and run Alembic migrations:
    cd your-directory/sunbird-ai-api
    alembic upgrade head
  • Run the app:
    uvicorn app.api:app --reload

Running the migrations with alembic:

  • After making a change to the models, run the command below to make the migrations:

    alembic revision --autogenerate -m 'message'
  • Check the created migration file in app/alembic/versions to ensure it does what's expected.

  • Apply the migration with:

    alembic upgrade head

Deployment

The app is deployed on Google Cloud Run and is backed by PostgreSQL DB hosted in Google Cloud SQL.

Other docs