Delete README.md
Browse files
README.md
DELETED
|
@@ -1,128 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Laya Decision Engine
|
| 3 |
-
emoji: 🧠
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: docker
|
| 7 |
-
app_port: 7860
|
| 8 |
-
pinned: false
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# 🧠 Laya Decision Engine — Self-Hosted Server (Jev-Compatible)
|
| 12 |
-
|
| 13 |
-
Self-hosted, non-autoregressive **System 1 decision engine** running 24/7 on Hugging Face Spaces CPU. Evaluates typed decisions (`choice`, `score`, `noul`) over any text or state in a single forward pass (~200–400 ms on CPU) across 100+ languages with calibrated probabilities.
|
| 14 |
-
|
| 15 |
-
Compatible with TypeSafe Jev's wire protocol (`POST /v1/systemone`).
|
| 16 |
-
|
| 17 |
-
---
|
| 18 |
-
|
| 19 |
-
## ⚡ API Endpoints
|
| 20 |
-
|
| 21 |
-
| Endpoint | Method | Description |
|
| 22 |
-
|---|---|---|
|
| 23 |
-
| `/` | `GET` | Plain text status (`"Laya is live."`) |
|
| 24 |
-
| `/v1/systemone` | `POST` | Primary Jev / System-1 Decision API |
|
| 25 |
-
| `/health` | `GET` | Health check & loaded model status |
|
| 26 |
-
|
| 27 |
-
---
|
| 28 |
-
|
| 29 |
-
## 🚀 Quick Usage Example
|
| 30 |
-
|
| 31 |
-
### 1. Evaluate a Decision (cURL)
|
| 32 |
-
|
| 33 |
-
```bash
|
| 34 |
-
curl -X POST "https://<YOUR-SPACE-NAME>.hf.space/v1/systemone" \
|
| 35 |
-
-H "Content-Type: application/json" \
|
| 36 |
-
-d '{
|
| 37 |
-
"state": "Hi, we were billed twice for March on invoice #4411. Refund please or we cancel our plan.",
|
| 38 |
-
"questions": {
|
| 39 |
-
"department": {
|
| 40 |
-
"type": "choice",
|
| 41 |
-
"instructions": "Which department should handle this request?",
|
| 42 |
-
"criteria": {
|
| 43 |
-
"billing": "invoices, payments, refund requests",
|
| 44 |
-
"technical": "system bugs, outages, crashes",
|
| 45 |
-
"sales": "upgrades, contracts, enterprise plans"
|
| 46 |
-
}
|
| 47 |
-
},
|
| 48 |
-
"urgency": {
|
| 49 |
-
"type": "score",
|
| 50 |
-
"instructions": "How urgent is this request on a 0 to 2 scale?",
|
| 51 |
-
"criteria": ["not urgent", "soon", "critical deadline or blocking issue"]
|
| 52 |
-
},
|
| 53 |
-
"churn_risk": {
|
| 54 |
-
"type": "noul",
|
| 55 |
-
"instructions": "Does the customer threaten to leave or cancel?"
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
}'
|
| 59 |
-
```
|
| 60 |
-
|
| 61 |
-
### 2. Python (Requests)
|
| 62 |
-
|
| 63 |
-
```python
|
| 64 |
-
import requests
|
| 65 |
-
|
| 66 |
-
HF_SPACE_URL = "https://<YOUR-SPACE-NAME>.hf.space/v1/systemone"
|
| 67 |
-
|
| 68 |
-
payload = {
|
| 69 |
-
"state": "The checkout page is throwing 500 errors and users cannot place orders!",
|
| 70 |
-
"questions": {
|
| 71 |
-
"severity": {
|
| 72 |
-
"type": "choice",
|
| 73 |
-
"instructions": "What is the severity of this ticket?",
|
| 74 |
-
"criteria": {
|
| 75 |
-
"P0_critical": "full outage, payment broken, revenue blocking",
|
| 76 |
-
"P1_high": "major feature failure",
|
| 77 |
-
"P2_normal": "minor inconvenience or general inquiry"
|
| 78 |
-
}
|
| 79 |
-
},
|
| 80 |
-
"page_oncall": {
|
| 81 |
-
"type": "noul",
|
| 82 |
-
"instructions": "Should we immediately alert the on-call engineering team?"
|
| 83 |
-
}
|
| 84 |
-
}
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
response = requests.post(HF_SPACE_URL, json=payload)
|
| 88 |
-
data = response.json()
|
| 89 |
-
|
| 90 |
-
print("Severity :", data["answers"]["severity"]["choice"], f"({data['answers']['severity']['confidence']:.2f} conf)")
|
| 91 |
-
print("Page OnCall:", "YES" if data["answers"]["page_oncall"]["noul"] > 0.5 else "NO")
|
| 92 |
-
print("Router :", data["routing"]["model"])
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
---
|
| 96 |
-
|
| 97 |
-
## 🔄 Automatic Updates & Factory Reboot
|
| 98 |
-
|
| 99 |
-
1. **Automatic Boot Update (No action required)**:
|
| 100 |
-
- `start.sh` automatically checks PyPI for the newest version of `laya[serve]` every time the container boots, restarts, or wakes up from sleep.
|
| 101 |
-
2. **Factory Reboot (Full Rebuild from Scratch)**:
|
| 102 |
-
- When a major new release of Laya drops, simply go to your Space's **Settings** $\rightarrow$ Click **"Factory reboot"**.
|
| 103 |
-
- Hugging Face will wipe the container and rebuild the image with zero cache, downloading the latest packages directly.
|
| 104 |
-
|
| 105 |
-
---
|
| 106 |
-
|
| 107 |
-
## ⚡ Maximum Resource Utilization Profile (16 GB RAM / 2 vCPU)
|
| 108 |
-
|
| 109 |
-
The container is configured to fully utilize Hugging Face Spaces' hardware allocation:
|
| 110 |
-
* **Memory (16 GB RAM)**:
|
| 111 |
-
- Preloads all three checkpoints into RAM at startup: `english` (ModernBERT-large), `multilingual` (mmBERT-base), and `typed-decisions` (ModernBERT-large).
|
| 112 |
-
- Keeps all 3 hot with `LAYA_MAX_LOADED=3` (Zero eviction, ~3.5–4.0 GB resident RAM).
|
| 113 |
-
- No cold-boot or checkpoint swap delays when alternating between languages or schemas.
|
| 114 |
-
* **Compute (2 vCPUs)**:
|
| 115 |
-
- Tuned with `torch.set_num_threads(2)` and OpenMP/MKL flags (`OMP_NUM_THREADS=2`, `MKL_NUM_THREADS=2`).
|
| 116 |
-
- Utilizes 100% of both CPU cores for vector matrix multiplication during single forward passes (~30–40ms).
|
| 117 |
-
|
| 118 |
-
---
|
| 119 |
-
|
| 120 |
-
## 🛡️ Optional API Key Authentication
|
| 121 |
-
|
| 122 |
-
To restrict access with a Bearer API token:
|
| 123 |
-
1. Go to your Hugging Face Space **Settings** $\rightarrow$ **Variables and Secrets**.
|
| 124 |
-
2. Add a Secret named `LAYA_API_KEY` with your secret key (e.g. `sk-laya-secret-key-12345`).
|
| 125 |
-
3. Clients must then include:
|
| 126 |
-
```http
|
| 127 |
-
Authorization: Bearer sk-laya-secret-key-12345
|
| 128 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|