106 lines
1.8 KiB
Markdown
106 lines
1.8 KiB
Markdown
# 🤖 MAID Proxy
|
|
|
|
MAID Proxy is a simple Flask application that acts as a proxy for OpenAI's API. It allows you to manage access to the API using time-limited keys, making it suitable for educational or controlled environments.
|
|
This project is designed to be easy to set up and use. It includes an admin dashboard for managing keys.
|
|
|
|
## Getting Started
|
|
|
|
### 1. Set up environment
|
|
|
|
```bash
|
|
python3 -m venv .venv
|
|
source .venv/bin/activate
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
### 2. Configure `.env`
|
|
|
|
Create a `.env` file with:
|
|
|
|
```env
|
|
OPENAI_API_KEY=your-openai-api-key
|
|
OPENAI_MODEL=gpt-3.5-turbo
|
|
ADMIN_USERNAME=admin
|
|
ADMIN_PASSWORD=yourStrongPassword
|
|
```
|
|
|
|
### 3. Recreate the SQLite database
|
|
|
|
```bash
|
|
python recreate_db.py
|
|
```
|
|
|
|
---
|
|
|
|
## API Endpoints
|
|
|
|
### `POST /ask`
|
|
|
|
Send prompt and user input to the model (requires valid proxy key):
|
|
|
|
```json
|
|
{
|
|
"proxy_key": "student123",
|
|
"system_role": "You are a helpful assistant.",
|
|
"prompt": "What's the weather like in Stockholm?"
|
|
}
|
|
```
|
|
|
|
### `GET /admin`
|
|
|
|
Admin dashboard (requires basic auth):
|
|
|
|
- View existing keys
|
|
- Add/remove time-window access keys
|
|
- The admin UI is protected with HTTP Basic Auth (`ADMIN_USERNAME` / `ADMIN_PASSWORD`)
|
|
|
|
---
|
|
|
|
## Development
|
|
|
|
To run locally:
|
|
|
|
```bash
|
|
python app.py
|
|
```
|
|
|
|
---
|
|
|
|
## Production Deployment
|
|
|
|
### With systemd:
|
|
|
|
Create a `maid.service`:
|
|
|
|
```ini
|
|
[Unit]
|
|
Description=Flask MAID app
|
|
After=network.target
|
|
|
|
[Service]
|
|
User=youruser
|
|
Group=www-data
|
|
WorkingDirectory=/home/youruser/maid
|
|
Environment="PATH=/home/youruser/maid/.venv/bin"
|
|
ExecStart=/home/youruser/maid/.venv/bin/gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app
|
|
Restart=always
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
```
|
|
|
|
Then enable and start it:
|
|
|
|
```bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable maid
|
|
sudo systemctl start maid
|
|
```
|
|
|
|
---
|
|
|
|
## Maintainers
|
|
|
|
Created by [@nenzen](mailto:nenzen@dsv.su.se).
|
|
Feel free to fork and adapt.
|