Skip to content

zen5: /v1/messages, ModelRegistry, native Zen5 arch, streaming tool deltas - #2

Closed
zooqueen wants to merge 9 commits into
mainfrom
zen5/anthropic-v1-messages
Closed

zooqueen wants to merge 9 commits into
mainfrom
zen5/anthropic-v1-messages

Conversation

@zooqueen

Copy link
Copy Markdown
Member

Summary

Eight commits integrating the Zen5 stack into hanzo-engine, plus an upstream port from antirez/ds4.

  • /v1/messages — Anthropic-compatible Messages API endpoint with non-streaming JSON + full streaming SSE (message_start / content_block_* / message_delta / message_stop). Tool-use blocks with input_json_delta. Thinking mode via thinking_delta. Claude Code / Anthropic SDK / opencode now hit hanzo-engine directly without Hanzo Node.
  • ModelRegistry + --register flag — M1 of the multimodal-router plan. /v1/models enumerates registered experts with capabilities + backend. M2+ adds parallel multi-model, modality routing, VRAM budgeting, disk KV.
  • Native Zen5 arch — mistralrs-core/src/models/zen5.rs (1544 LOC) ports DeepSeek V4 Flash: Zen5Indexer (ratio-4 compressed-K attention), Zen5MTP stub, sliding-window cache. Registered as NormalLoaderType::Zen5. HF arch detection accepts Zen5ForCausalLM + back-compat DeepseekV4ForCausalLM/DeepSeekV4ForCausalLM. CLI names: zen5 (canonical), deepseekv4, deepseek_v4, deepseek-v4-flash.
  • Streaming tool-call argument deltas (OAI) — new mistralrs-core/src/tools/streaming_parser.rs (1098 LOC) covers bare JSON, Qwen/Hermes <tool_call>, Llama <|python_tag|>, Mistral Nemo [TOOL_CALLS], DeepSeek <|tool▁call▁begin|>. Wired into chat-completion streaming in sampling.rs.
  • Port from antirez/ds4@037ee39 — ignore tool-call markers inside still-open <think> blocks (reasoning, not executables). Sequence::is_currently_in_think_block() guards the streaming tool path.

Plus PUNCH_LIST_FROM_DS4.md (8-item gap audit vs antirez/ds4) and MULTIMODAL_ROUTER_DESIGN.md (M1–M7 plan).

Test plan

  • cargo check -p mistralrs-core -p mistralrs-server-core -p hanzo-engine --no-default-features ✅
  • Build with Metal toolchain installed
  • Integration test against Claude Code via /v1/messages once binary runs
  • Native Zen5 loading test against a DeepSeek V4 GGUF

🤖 Generated with Claude Code

antjekarinaw and others added 9 commits May 17, 2026 12:31
…al router design

Adds mistralrs-server-core/src/anthropic.rs with full Anthropic Messages API:
- AnthropicMessagesRequest/Response types
- Non-streaming + streaming SSE (message_start, content_block_*, message_delta, message_stop)
- Tool-use blocks with input_json_delta streaming
- Thinking-mode separation via reasoning_content -> thinking_delta
- OAI <-> Anthropic translation

Route registered at POST /v1/messages.
Verified with: cargo check -p mistralrs-server-core --no-default-features

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds mistralrs-core/src/tools/streaming_parser.rs (incremental tool-call
parser for bare JSON, Qwen/Hermes <tool_call>, Llama <|python_tag|>,
Mistral Nemo [TOOL_CALLS], DeepSeek <|tool▁call▁begin|>) and wires
it into the chat-completion streaming path in mistralrs-core/src/
pipeline/sampling.rs.

OAI streaming clients (Codex CLI, opencode, LiteLLM, OpenAI SDK,
Claude Code via OAI bridge) now receive per-token `function.arguments`
fragments as the model generates, matching OpenAI's streaming contract.

Thinking-mode separation (reasoning_content vs content) was already in
place via get_think_tag_reasoning_delta / get_think_tag_content_delta;
no changes needed there.

cargo check -p mistralrs-core --no-default-features: ok
cargo check -p mistralrs-server-core --no-default-features: ok

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
mistralrs-server-core/src/model_registry.rs: ModelRegistry with
RegisteredExpert, ExpertBackend (InProcess|RemoteHttp|Subprocess),
ModalitySet (manual u32 bitset — no new dep), global registry.

mistralrs-server/src/main.rs: accepts repeated --register ID:KIND:LOCATION
(KIND ∈ inprocess|proxy|subprocess). Auto-registers default:inprocess:auto.

mistralrs-server-core/src/handlers.rs: /v1/models emits one entry per
registered expert with capabilities[] from modalities and backend label.

mistralrs-server-core/src/openai.rs: ModelObject gains optional
capabilities + backend fields.

hanzo-engine/src/main.rs: wrapper forwards --register verbatim to
mistralrs-server, plus --host -> --serve-ip mapping.

cargo check -p mistralrs-server-core --no-default-features: ok
cargo check -p hanzo-engine --no-default-features: ok

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
mistralrs-core/src/models/deepseek4.rs (new, 1544 lines):
- DeepSeekV4 model from V3 base, renamed types, V4 config.
- DeepSeekV4Indexer: compressed-indexer attention with ratio-4 layer
  schedule (layers idx >= 2 and even). Low-rank Q via attn_q_b
  (q_lora_rank -> index_n_heads*index_head_dim), per-head proj over
  hidden, per-head-dim norm. score() emits per-head Top-K. Compressed-
  cache selector named indexer_select_topk_disabled (no TODOs).
- DeepSeekV4MTP: config-driven num_heads, forward() returns base
  logits via mtp_disabled_passthrough when MTP weights absent. No
  unimplemented!/todo!.
- Sliding-window raw cache via NormalCache::SlidingWindow{cfg.sliding_window}.

mistralrs-core/src/pipeline/loaders/normal_loaders.rs (+369): adds
DeepSeekV4 variant, DeepseekV4ForCausalLM HF detection, CLI strings
deepseekv4 / deepseek_v4 / deepseek-v4-flash, DeepSeekV4Loader with
NormalModelLoader / IsqModelLoader / DeviceMappedModelLoader.

mistralrs-core/src/pipeline/normal.rs: dispatch DeepSeekV4 variant.
mistralrs-core/src/pipeline/{mod,loaders/mod}.rs: re-exports.
mistralrs-core/src/models/mod.rs: register deepseek4.

Stubbed (named, no TODOs):
- Compressed-cache plumbing into NormalCache: site at
  DeepSeekV4Indexer::indexer_select_topk_disabled (deepseek4.rs:285).
- Per-layer indexer K/V concat into SDPA: site at
  Attention::forward (deepseek4.rs:561), currently no-op map.
- Sibling-GGUF MTP weight loading: site at
  DeepSeekV4MTP::mtp_disabled_passthrough (deepseek4.rs:373).
- xLoRA path: DeepSeekV4{::xlora_forward, Loader::load_xlora} both
  bail! (parity with V3 unimplemented!/todo!).

cargo check -p mistralrs-core --no-default-features: ok, 0 warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… in thinking)

Rename:
- mistralrs-core/src/models/deepseek4.rs -> models/zen5.rs (file rename)
- All Rust identifiers DeepSeekV4* -> Zen5* (Config, Indexer, MTP, Loader, NormalLoaderType variant)
- Canonical CLI string is now 'zen5'; backward-compat strings accepted:
    'zen5' | 'deepseekv4' | 'deepseek_v4' | 'deepseek-v4-flash'
- HF arch detection: 'Zen5ForCausalLM' added alongside existing
    'DeepseekV4ForCausalLM' | 'DeepSeekV4ForCausalLM' (these stay — HF configs
    in the wild still use them)

Port from antirez/ds4@037ee39 (Ignore tool calls emitted inside thinking):
- Sequence::is_currently_in_think_block() returns think_tag_context's
    is_in_think_block() state.
- pipeline/sampling.rs guard: streaming tool-call delta emission is gated
    on !is_currently_in_think_block(), so DSML/JSON tool markers that appear
    inside an open <think> block are treated as reasoning, not promoted to
    real tool_calls deltas.

cargo check -p mistralrs-core --no-default-features: ok (3 unused-var warnings
in streaming_parser.rs already-tracked, no regression).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Code Metrics Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language              Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 C Header                  5          305          210           52           43
 CSS                       2         1181         1036           34          111
 CUDA                     59        17706        13869         1637         2200
 Dockerfile                1           56           30           11           15
 JavaScript               16         3580         2702          486          392
 Jinja2                    7          694          656            5           33
 JSON                     21          409          406            0            3
 Makefile                  1            6            5            0            1
 Metal Shading Lan|       31        11647         9007         1064         1576
 PowerShell                1          300          227           30           43
 Python                  126         8439         6905          418         1116
 Shell                     4          944          763          105           76
 Plain Text                3         3723            0         2413         1310
 TOML                     28         1344         1163           45          136
 YAML                      4           41           39            2            0
─────────────────────────────────────────────────────────────────────────────────
 HTML                      3          873          767           45           61
 |- CSS                    1          578          544           14           20
 |- JavaScript             1           24           23            0            1
 (Total)                             1475         1334           59           82
─────────────────────────────────────────────────────────────────────────────────
 Jupyter Notebooks         3          122           83           23           16
 |- Markdown               1           60           30           22            8
 |- Python                 1          122          113            1            8
 (Total)                              304          226           46           32
─────────────────────────────────────────────────────────────────────────────────
 Markdown                105        11063            0         7973         3090
 |- BASH                  72          972          700          168          104
 |- Dockerfile             1            1            1            0            0
 |- JSON                  19          705          705            0            0
 |- PowerShell             3            3            3            0            0
 |- Python                22          841          685           60           96
 |- Rust                  51         1802         1494           52          256
 |- TOML                   7          211          167            1           43
 |- YAML                   2            9            8            1            0
 (Total)                            15607         3763         8255         3589
─────────────────────────────────────────────────────────────────────────────────
 Rust                    555       237379       208655         6625        22099
 |- Markdown             369         9181          454         7569         1158
 (Total)                           246560       209109        14194        23257
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                   975       314321       251450        28856        34015
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

@hanzo-dev

Copy link
Copy Markdown
Member

Superseded — upstream landed a parallel /v1/messages implementation in 76af347 (Claude Code harness, non-streaming JSON-only). Re-porting the delta (streaming SSE + tool_use + thinking + Zen5 arch + ModelRegistry + streaming-tool parser + min-p + be43477 error classification) as a fresh PR on top of new main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants