|
Download knowledge.md from shimen/yapapa: direct link, hf CLI and curl.
- Browser
- Download file 5.9 kB
-
https://huggingface.co/spaces/shimen/yapapa/resolve/main/knowledge.md
- Command line
-
hf download hf://spaces/shimen/yapapa/knowledge.md
-
curl -L -o knowledge.md https://huggingface.co/spaces/shimen/yapapa/resolve/main/knowledge.md
5.9 kB
knowledge.md — wiwi agent knowledge
What this is
Self-hosted unified LLM gateway proxy (FastAPI + React admin SPA). Three inbound dialects
(OpenAI Chat /v1/chat/completions, OpenAI Responses /v1/responses, Anthropic Messages
/v1/messages) are decoded into one canonical IR (wiwi/ir/) and re-encoded to any of 13
outbound provider types (openai, anthropic, gemini, openrouter, nvidia-nim, bai, cline-OAuth,
workbuddy, opencode, hermes, ifm, gmicloud, openai-compatible) — always answered back in the
caller's dialect.
Where key code lives
| Path | Role |
|---|---|
wiwi/wire/ |
Inbound codecs/encoders: openai_chat.py, openai_responses.py, anthropic_messages.py, openai_completions.py (legacy /v1/completions) |
wiwi/ir/ |
Canonical IR types (tagged parts, messages, tools, params, usage) |
wiwi/providers/ |
Outbound adapters + registry.py (one branch per provider type; import-time assert catches missing branches) |
wiwi/router/router.py |
Key pools (smooth WRR), cooldowns, retries, fallbacks |
wiwi/server/app.py |
FastAPI app; run_chat_like = decode → auth → rate limit → router → gateway |
wiwi/core/context.py |
RequestContext — single mutable object threaded through every stage |
wiwi/core/gateway.py |
Surface-agnostic execution engine + pricing + log events |
wiwi/streaming/ |
IR stream delta taxonomy, SSE, coalesce, resume, validation |
wiwi/auth/ |
Virtual keys (SHA-256 at rest), budgets, users |
wiwi/wire/ quirks |
NVIDIA NIM tool-schema sanitizer, Cline OAuth refresh |
web/ |
Admin SPA (React 19 + TS + Vite + Tailwind 4, npm) |
tests/ |
pytest suite; bugfix regressions in test_fix_roundN.py |
Commands (verified in this checkout)
python3 -m pytest tests/ -q # full suite (~4,000 tests, ~247s)
python3 -m pytest tests/test_codecs.py -q # single file
ruff check wiwi/ tests/ scripts/ # lint (line-length 100, py311)
python3 -m pytest tests/ -q && ruff check wiwi/ tests/ scripts/ # verify before claiming done
# Admin UI (npm)
cd web && npm install && npm run dev # Vite dev, proxies /admin /v1 /auth → :4000
cd web && npm run build # tsc -b && vite build → wiwi/server/static/
cd web && npm run lint # eslint (web/ is NOT covered by ruff)
# Run the gateway
wiwi --config wiwi.yaml # or: wiwi -c wiwi.yaml --host 0.0.0.0 --port 4000
Gotchas / constraints (read before touching code)
.venv/bin/pythonis broken in this checkout (symlink to empty Py3.14 venv). Use ambientpython3/pytest/ruff(Py 3.13.5, pytest 9.1.1). Never.venv/bin/python.- Hub-and-spoke is binding: dialect logic only in
wiwi/wire/, provider logic only inwiwi/providers/+ one branch inregistry.get_adapter(). Never branch on dialect/provider incore/,router/,auth/.registry.pyasserts loudly at import if a provider type lacks a branch. - Streaming contract (
wiwi/streaming/deltas.py): oneStreamStart;ToolCallOpen→ArgsDelta*→Closenested per index (parallel calls are siblings);UsageFinalat least once (may repeat, may precede the last content delta); thenFinish; thenStreamEndxorStreamError. Adapters guarantee legality; encoders never defend. Exception:StreamErrormay terminate anytime with noFinish. - The old "docs run ahead" warning is stale. Earlier
docs/ARCHITECTURE.md/docs/CORE.mdrevisions described a handler pipeline,DeltaBus, and Postgres/Redis backends that were never built;docs/CORE.mdnow disavows them and both docs match the shippedGateway+execute_with_retriesdesign. Postgres and Redis backends do exist (server/config_store.py,ratelimit/redis.py,cache/redis_cache.py). Still trust the code over docs. - Read
UPDATE.md(translation-fix changelog: reasoning/thinking params, tool_result,content: null, OpenRouterreasoning,stream_options) andAUDIT.md(known bugs with file:line + fix sketches) before bugfix work. - Tests:
asyncio_mode = "auto"(bareasync def test_…); mock upstream HTTP withrespx; app-level tests viaasgi-lifespan+httpx.ASGITransport; property round-trips viahypothesis. - New bugfix regressions go in numbered
tests/test_fix_roundN.py(latest present:test_fix_round194.py; next: round195 — confirm numerically, never with a plainls). - Ruff only (no black/isort),
line-length = 100,target-version = "py311". Pydantic v2 for config; plain dataclasses for IR/streaming hot paths;orjsonin hot paths;structlogneverprint. - Never commit:
wiwi.yaml,wiwi.db,key.md,.env,.verify/*,opencode.json(c)— live keys/runtime state. Provider keys viaos.environ/NAMEinwiwi.yaml; master key viaWIWI_MASTER_KEY. - Admin endpoints need master key; client traffic uses virtual keys (
sk-wiwi-…, SHA-256 at rest, plaintext shown once at mint). web/uses npm;web/package-lock.jsonis authoritative andstart.shuses npm.web/is eslint-only, NOT ruff.web/src/pages/mixes ~15 console pages with ~30 marketing pages (56 components total) — directory alone doesn't tell you if a page is admin-facing.web/tsconfig.json+npm run buildoutput lands inwiwi/server/static/(served at/, console at/console); rebuild after UI changes or the served bundle is stale.
Test conventions
asyncio_mode = "auto"— bareasync def test_…, no@pytest.mark.asyncio.- Upstream HTTP mocked with
respx; app-level tests viaasgi-lifespan+httpx.ASGITransport. - Property round-trips with
hypothesis(tests/test_property_roundtrip.py). - Full suite: ~4,000 tests, ~247s. Verify before claiming done:
python3 -m pytest tests/ -q && ruff check wiwi/ tests/