Repository navigation
feat(anthropic): /v1/messages SSE streaming + tool_use/tool_result blocks - #5
Merged
Merged
Conversation
Expands the Anthropic /v1/messages handler from a non-streaming text-only stub into a full Claude Code-compatible endpoint: - Streaming: when stream=true, returns an SSE response that emits the documented Anthropic event sequence (message_start, ping, content_block_start, content_block_delta(text_delta|input_json_delta), content_block_stop, message_delta, message_stop). Builds on the existing chat-pipeline response channel, translating each ChatCompletionChunkResponse / Done into Anthropic events via a state machine that tracks open text and tool_use blocks. - Tool_use blocks: AnthropicContentBlock now has ToolUse and ToolResult variants. The request translator splits each Anthropic message into the appropriate OpenAI messages (assistant w/ tool_calls, separate `tool` role messages with tool_call_id). The response builder emits tool_use blocks whenever the OpenAI message has tool_calls (streaming and non-streaming). - Anthropic tools schema (name/description/input_schema) is translated to the OpenAI function-tool shape so existing tool plumbing applies as-is. 7 colocated unit tests cover the translation, content block construction, and the streaming event sequence (text-only and tool_use). End-to-end SSE was verified against a live Qwen3-0.6B server on :36901: full message_start...message_stop sequence emitted correctly.
Code Metrics Report━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Language Files Lines Code Comments Blanks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ C Header 5 305 210 52 43 CSS 5 1462 1288 39 135 CUDA 60 20622 16570 1656 2396 Dockerfile 1 38 21 8 9 JavaScript 19 3972 3089 488 395 Jinja2 7 694 656 5 33 JSON 27 9400 9397 0 3 Makefile 1 6 5 0 1 MDX 1 147 0 132 15 Metal Shading Lan| 34 13466 10542 1117 1807 PowerShell 1 300 227 30 43 Python 131 10161 8357 462 1342 Shell 4 948 765 106 77 Plain Text 3 3723 0 2413 1310 TOML 30 1427 1237 46 144 TypeScript 11 1607 1371 66 170 YAML 4 41 39 2 0 ───────────────────────────────────────────────────────────────────────────────── HTML 4 782 695 38 49 |- CSS 1 578 544 14 20 |- JavaScript 1 24 23 0 1 (Total) 1384 1262 52 70 ───────────────────────────────────────────────────────────────────────────────── 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 210 19178 0 13456 5722 |- BASH 123 1399 1090 190 119 |- Dockerfile 3 6 6 0 0 |- JSON 35 1175 1175 0 0 |- PowerShell 5 7 7 0 0 |- Python 45 1717 1459 65 193 |- Rust 64 2423 2048 56 319 |- TOML 16 318 250 4 64 |- YAML 3 18 17 1 0 (Total) 26241 6052 13772 6417 ───────────────────────────────────────────────────────────────────────────────── Rust 602 259959 229293 6654 24012 |- Markdown 400 9599 454 7977 1168 (Total) 269558 229747 14631 25180 ───────────────────────────────────────────────────────────────────────────────── Svelte 18 1831 1696 50 85 |- CSS 1 4 4 0 0 |- JavaScript 18 876 727 24 125 (Total) 2711 2427 74 210 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Total 1181 368517 293488 35197 39832 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ |
hanzo-dev
added a commit
that referenced
this pull request
Jul 10, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
hanzo-dev
added a commit
that referenced
this pull request
Jul 16, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
zeekay
pushed a commit
that referenced
this pull request
Jul 26, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
hanzo-dev
added a commit
that referenced
this pull request
Jul 27, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
zeekay
added a commit
that referenced
this pull request
Sep 15, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
zeekay
added a commit
that referenced
this pull request
Sep 15, 2026
…fall #5) Hoist Tensor::arange (timestep freqs) and Tensor::from_vec (causal mask) out of the per-forward hot loop to model init, eliminating a CPU-GPU sync per DiT forward (~310 per 10-step rollout). Parity preserved bit-exact (DiT cosine 1.000000). Also: example now reports per-stage timing (vae-enc/dit/vae-dec). This is also the precondition for capturing the fixed-shape denoise step as a CUDA graph.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/v1/messages:message_start,content_block_start,content_block_delta/text_delta,content_block_stop,message_delta,message_stopToolUse/ToolResultvariants added toAnthropicContentBlockanthropic_tools_to_openaimaps Anthropic{name, description, input_schema}-> OpenAI function-tool shapetranslate_messageexpands mixed Anthropic content (text + tool_use + tool_result) into OpenAI messages: assistant withtool_calls, separaterole:toolmessages withtool_call_idtool_useblocks viabuild_content_blockswhenchoices[0].message.tool_callsis non-emptyinput_json_deltawith prefix-stripping inhandle_tool_callsTests
7/7 unit tests in
mistralrs-server-core::anthropicpass (translation, streaming sequence, tool_use, event framing). End-to-end SSE verified againstQwen3-0.6Bon a temporary:36901server — full event sequence observed.Gaps (deferred)
message_idusesmsg_<seq>rather than Anthropic-style UUIDBuilds on the non-streaming Anthropic path landed earlier in 76af347.