Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,43 @@ make setup

This creates a virtual environment in `.venv/`, installs dependencies, and installs the tool locally in editable mode.

## Running MLPA locally with Docker
# Running MLPA locally with Docker

### Run LiteLLM
### Run LiteLLM and PostgreSQL

`docker compose -f litellm_docker_compose.yaml up -d`
1. `docker compose -f litellm_docker_compose.yaml up -d`

### Create and migrate appattest database
`sh ./scripts/create-app-attest-database.sh`

`alembic upgrade head`
2. `sh ./scripts/create-app-attest-database.sh`

### Set MLPA_DEBUG=true in the .env file
Verify FxA requests against staging URL
3. `alembic upgrade head`

4. Set `MLPA_DEBUG=true` in the `config.py` or `.env` file

### Create a virtual LiteLLM key

5. Run `python scripts/create-and-set-virtual-key.py` (also sets the value in `.env`)

### Run MLPA

1. install it as a library
6. Install it as a library:

```bash
pip install --no-cache-dir -e .
```

2. Run the binary
7. Run the binary

```bash
mlpa
```

## Config (see [LiteLLM Documentation](https://docs.litellm.ai/docs/simple_proxy_old_doc) for more config options)

`.env` (see `config.py` for all configuration variables)

```
MASTER_KEY="sk-1234..."
LITELLM_API_BASE="http://mlpa:4000"
DATABASE_URL=postgresql://... # required for direct user editing in SQL
CHALLENGE_EXPIRY_SECONDS=300
PORT=8080

APP_BUNDLE_ID="org.example.app"
APP_DEVELOPMENT_TEAM="12BC943KDC"
Navigate to

CLIENT_ID="..."
CLIENT_SECRET="..."
## Config (see [LiteLLM Documentation](https://docs.litellm.ai/docs/simple_proxy_old_doc) for more config options)

MODEL_NAME=""
TEMPERATURE=0.1
TOP_P=0.01
```
### See `config.py` for all configuration variables

### Also See `litellm_config.yaml` for litellm config

Expand Down
70 changes: 70 additions & 0 deletions scripts/create-and-set-virtual-key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Run before testing MLPA locally
LiteLLM and Postgres must be configured and running
This creates a virtual API key for testing purposes.
"""

import json
import os

import requests
from dotenv import load_dotenv

# Load environment variables from .env file if it exists
if os.path.exists(".env"):
load_dotenv(".env")

# Set your authorization token here
AUTH_TOKEN = os.environ.get("MASTER_KEY")

if not AUTH_TOKEN:
print("MASTER_KEY environment variable not set.")
exit(1)

# Call the API and capture the response
url = "http://localhost:4000/key/generate"
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + AUTH_TOKEN}
data = {
"user_id": "default_user_id",
"key_alias": "test-api",
"models": ["all-team-models"],
}

response = requests.post(url, headers=headers, json=data)
if response.status_code != 200:
print(f"API call failed with status code {response.status_code}: {response.text}")
exit(1)

try:
virtual_key = response.json().get("key")
except json.JSONDecodeError:
print("Failed to parse JSON response.")
exit(1)

if not virtual_key:
print("Failed to extract key from response.")
exit(1)

# Update or add MLPA_VIRTUAL_KEY in .env file
env_file = ".env"
lines = []
found = False

if os.path.exists(env_file):
with open(env_file, "r") as f:
for line in f:
if line.startswith("MLPA_VIRTUAL_KEY="):
lines.append(f"MLPA_VIRTUAL_KEY={virtual_key}\n")
found = True
else:
lines.append(line)
else:
lines = []

if not found:
lines.append(f"MLPA_VIRTUAL_KEY={virtual_key}\n")

with open(env_file, "w") as f:
f.writelines(lines)

print(f"MLPA_VIRTUAL_KEY set to {virtual_key} in {env_file}")