llama-platform-backend 0.1.0
Backend for Llama Platform
Requires Python: <3.12,>=3.10

# Platform Backend

Live at {TODO}

## Setup Dev Workspace

1. Make sure you have installed `sqlite-devel` e.g. `sudo apt install libsqlite3-dev` or `brew install sqlite3`
1. Pull git submodules with `git submodule update --init --recursive`
1. Install [pyenv](https://github.com/pyenv/pyenv#automatic-installer) and then use it to install the Python version in `.python-version`.
   1. install pyenv with `curl https://pyenv.run | bash`
   1. run `pyenv install` to install the correct python version
1. [Install AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
1. [Install docker](https://docs.docker.com/engine/install/)
1. Install poetry. `curl -sSL https://install.python-poetry.org | python3 -`
1. Run `poetry shell`
1. Run `poetry install` to install dependencies for the project
1. Go to the firebase console and download the service account key for the project (if you need to enable auth)
   1. Go to the [firebase console](https://console.firebase.google.com/)
   1. Click on the llamapl-dev project
   1. Click on the gear icon next to "Project Overview"
   1. Click on "Project Settings"
   1. Click on the "Service Accounts" tab
   1. Click on "Generate new private key"
   1. Save the file somewhere in your computer
1. Create the `.env` file and source it. The `.env.development` file is a good template.
   1. `cp .env.development .env`
   1. Copy the .env secrets from [1Password](https://start.1password.com/open/i?a=32SA66TZ3JCRXOCMASLSDCT5TI&v=lhv7hvb5o46cwo257c3hviqkle&i=3pdhbzdysmvhzvublewqwt6tku&h=llamaindex.1password.com)
   1. Modify the `.env` by adding your own API keys & localized paths
      - Make sure that `GOOGLE_APPLICATION_CREDENTIALS` points to the service account key you downloaded in the previous step (if you need to enable auth)
      - You can leave `AWS_KEY` & `AWS_SECRET` with dummy values
   1. `set -a && source .env`
1. Run `make migrate` which will create db and run alembic migrations (needed for 1st install and db updates)
1. Run `make test` to populate the database with test data.
1. Run `make run` to start the server locally
   - This spins up the Postgres 15 DB & Localstack in their own docker containers.
   - The server will not run in a container but will instead run directly on your OS.
     - This is to allow for use of debugging tools like `pdb`

## Scripts

The `scripts/` folder contains several scripts that are useful for both operations and development.

## Register Test Pipelines

This is useful to register test pipelines (from python framework) to test platform playground.
You can run `make register_test_pipelines` to trigger the script.

Currently, running the script will create test pipelines so you can use them for testing the playground UI.

## Register Test Pipelines for Prod/Staging

Get your API key from https://prod.llamaindex.ai/api-key or https://staging.llamaindex.ai/api-key after logging in.

Run this

```
export PLATFORM_API_KEY=YOUR_API_KEY
make register_test_pipelines_prod
# or
make register_test_pipelines_staging
```

## Generate OpenAPI Spec

This script dumps the latest OpenAPI spec of the latest FastAPI server.
This is useful whenever you want to re-generate the fern client library (for frontend client, or framework client).

You can run `make refresh_client` to generate the OpenAPI spec, and then run `fern generate` in a single command.

## Local Dashboards

There are a few services that the `Makefile` commands spin up via the `docker-compose.yml` file. Some of those services come with their own dashboards which can be useful for local debugging.

- Qdrant - http://localhost:6333/dashboard
- MongoDB - http://localhost:8081
  - The dashboard is actually from [mongo-express](https://github.com/mongo-express/mongo-express) which is a separate container that connects to the mongo container
  - If this website asks for username/password, use `admin` for the username and `pass` for the password.
- RabbitMQ - http://localhost:15672/
  - This requires a username & guest, both of which are "guest".

## VS Code Setup

1. Start your Poetry shell `poetry shell`
1. Get the path and copy it `poetry env info --path | pbcopy`
1. Open the "Select Python Interpreter" window in VS Code via Cmd+Shift+P and typing "Python: Select Interpreter"
1. Select "Enter interpreter path" and paste the Poetry path