File size: 2,669 Bytes
92b08d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # INFERENCE β sovereign LLM execution
Hugging Chat / the HF router is fine for prototyping, but the critical path is
an endpoint you control that the harness hits programmatically. Two paths,
both OpenAI-compatible β no code changes, only env:
```bash
export FREESTREAM_AGENT=llm
export FREESTREAM_LLM_BASE_URL=<endpoint>/v1
export FREESTREAM_LLM_API_KEY=<key or "local">
export FREESTREAM_LLM_MODEL=local # llama.cpp/MLX serve any model name
export FREESTREAM_CHARACTER_CARD=identity/characters/vera-steel.json
```
## A. Dedicated HF Space (shipped β [freestream-llm](https://huggingface.co/spaces/LoveLogicAI/freestream-llm))
Docker Space running **llama.cpp server** (Qwen2.5-7B-Instruct Q4_K_M,
auto-downloaded on boot). Endpoint:
```
https://lovelogicai-freestream-llm.hf.space/v1/chat/completions
```
Setup once: Space settings β upgrade hardware to **CPU Upgrade** (8 vCPU) β
add the `LLM_API_KEY` secret β optionally enable persistent storage (`/data`)
so the 4.7GB model survives restarts. **Pause the Space when idle** β a 24/7
CPU-upgrade Space bills continuously, and sovereignty shouldn't mean a
standing bill.
Measured throughput will be reported in docs/LATENCY.md after the probe job.
## B. Mac mini (recommended primary β your hardware, no standing bill)
```bash
cd freestream
./scripts/serve_local_llm.sh mlx # MLX, fastest on Apple Silicon
# or: ./scripts/serve_local_llm.sh cpp
export FREESTREAM_LLM_BASE_URL=http://localhost:8080/v1
export FREESTREAM_LLM_MODEL=local
export FREESTREAM_LLM_API_KEY=local
python tests/e2e_roleplay.py # the harness hits localhost programmatically
```
- **MLX**: `pip install mlx-lm`, serves `mlx-community/Qwen2.5-7B-Instruct-4bit`
via `python -m mlx_lm.server` (OpenAI-compatible).
- **llama.cpp**: `brew install llama.cpp`, `llama-server -hf <gguf>` β same API.
The 4s assistant-profile win condition stays a **cloud-burst** feature
(router/GPU); sovereign local inference is the **roleplay/agentic profile**
(gates 20s/30s) β measure your mini's tok/s and record it in LATENCY.md.
## Harness wiring (both paths)
Every e2e harness reads the same env; nothing is hardcoded to the router.
`load_agent` accepts keyless **local** endpoints (localhost / *.local) without
falling back to the rule stub β set `FREESTREAM_LLM_API_KEY=local` for hosts
that ignore auth headers.
## Endpoint contract
CharacterAgent needs exactly one route: `POST {base}/chat/completions` with
`{"model", "messages", "max_tokens", "temperature"}` β
`choices[0].message.content`. Any OpenAI-compatible server satisfies it
(llama-server, mlx_lm.server, vLLM, Ollama with `base=/v1`). |