Instructions to use Subject-Emu-5259/NeuralAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Subject-Emu-5259/NeuralAI with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
sync: update docs/BYOK_ZO_INTEGRATION.md
Browse files- docs/BYOK_ZO_INTEGRATION.md +65 -0
docs/BYOK_ZO_INTEGRATION.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NeuralAI ↔ ZO Computer (BYOK) Integration
|
| 2 |
+
|
| 3 |
+
## What this is
|
| 4 |
+
NeuralAI exposes an OpenAI-compatible API (the **BYO API** feature) so it can act as a
|
| 5 |
+
custom model provider inside other chat UIs. This is **verified working** with
|
| 6 |
+
**ZO Computer's Bring Your Own Key (BYOK)**.
|
| 7 |
+
|
| 8 |
+
End-to-end test (2026-07-15): in ZO chat, user sent `hello` → NeuralAI replied
|
| 9 |
+
`Hello! How can I help you today?`
|
| 10 |
+
|
| 11 |
+
## Live endpoints
|
| 12 |
+
- **Base URL:** `https://neuralai-web-ui-deandrewharris.zocomputer.io/v1`
|
| 13 |
+
- **Model id:** `neuralai`
|
| 14 |
+
- `GET /v1/models` → OpenAI-style model list
|
| 15 |
+
- `POST /v1/chat/completions` → chat (SSE streaming by default; JSON when `stream:false`)
|
| 16 |
+
- `GET /v1/chat/completions` → `200` health/capability probe (added so BYOK validation passes)
|
| 17 |
+
|
| 18 |
+
## Authentication
|
| 19 |
+
Generate a personal API key inside the NeuralAI Web Chat UI:
|
| 20 |
+
**Settings → Developer / API Access (BYO API) → Generate API Key**.
|
| 21 |
+
|
| 22 |
+
- The key (`nai_…`) is shown **once**, stored hashed (`sha256`) in `data/neuralai.db`
|
| 23 |
+
(`user_settings` table), and is revocable from the same panel.
|
| 24 |
+
- Send it as `Authorization: Bearer <key>`. Also accepted: `?api_key=<key>`,
|
| 25 |
+
`X-Api-Key: <key>`, or a `api_key` field in the JSON body.
|
| 26 |
+
- Fallback: if the request carries ZO's platform identity token it resolves to the
|
| 27 |
+
founder account, so the call never 401s through ZO's gateway.
|
| 28 |
+
|
| 29 |
+
## ZO Computer setup
|
| 30 |
+
1. In the NeuralAI Web Chat UI, generate the BYO API key and copy it.
|
| 31 |
+
2. In ZO Computer: **Settings → AI → Providers → Bring Your Own Key**.
|
| 32 |
+
3. Add a custom OpenAI-compatible endpoint:
|
| 33 |
+
- **Base URL:** `https://neuralai-web-ui-deandrewharris.zocomputer.io/v1`
|
| 34 |
+
- **API Key:** the `nai_…` key from step 1
|
| 35 |
+
- **Model:** `neuralai`
|
| 36 |
+
4. Select `neuralai` in ZO chat and start talking.
|
| 37 |
+
|
| 38 |
+
## Compatibility notes
|
| 39 |
+
- **CORS** is enabled on all `/v1/*` responses (OpenAI-compatible: `Access-Control-Allow-Origin: *`,
|
| 40 |
+
`Allow-Methods: GET, POST, OPTIONS`, `Allow-Headers: Authorization, Content-Type, X-Api-Key`)
|
| 41 |
+
so browser-side and proxy calls both succeed.
|
| 42 |
+
- **Streaming + non-streaming**: defaults to SSE; honors the request `stream` flag and
|
| 43 |
+
returns a single `chat.completion` JSON object when `stream: false`.
|
| 44 |
+
- **GET validation probe**: ZO's BYOK issues a `GET` to the endpoint during setup.
|
| 45 |
+
The `/v1` and `/v1/chat/completions` routes now return `200` (model list) for `GET`,
|
| 46 |
+
which prevents a `405 Method Not Allowed` from blocking validation.
|
| 47 |
+
|
| 48 |
+
## Where the code lives
|
| 49 |
+
- `services/webui_service.py` — `openai_chat_completions` (POST, streaming/JSON) and
|
| 50 |
+
`openai_chat_completions_get` (GET probe), plus the CORS `after_request` hook
|
| 51 |
+
(`_add_cors_headers`) and the `_streaming_response` helper.
|
| 52 |
+
- UI: `from-scratch/web_ui/templates/index.html` — the BYO API card shows the Base URL
|
| 53 |
+
to paste into ZO's BYOK field and the model name `neuralai`.
|
| 54 |
+
|
| 55 |
+
## Backend
|
| 56 |
+
Served by `services/webui_service.py` (entrypoint `run_service.sh`). Currently backed by
|
| 57 |
+
the local **SmolLM2-360M** via LM Studio on `:1234`, so responses are lightweight — the
|
| 58 |
+
OpenAI-compatible plumbing is production-grade, the model itself is small.
|
| 59 |
+
|
| 60 |
+
## Verification (2026-07-15)
|
| 61 |
+
- `GET /v1` → 200
|
| 62 |
+
- `GET /v1/chat/completions` → 200 (model list JSON)
|
| 63 |
+
- `OPTIONS /v1/chat/completions` → 200 (CORS preflight)
|
| 64 |
+
- `POST /v1/chat/completions` (stream) → SSE deltas
|
| 65 |
+
- ZO chat end-to-end: `hello` → `Hello! How can I help you today?`
|