-
Notifications
You must be signed in to change notification settings - Fork 178
fix(reasoning): arm the reasoning parser from the rendered prompt #2538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
|
|
||
| use llm_tokenizer::traits::Tokenizer; | ||
| use openai_protocol::chat::ChatCompletionRequest; | ||
| use smg::routers::grpc::utils::chat_reasoning_starts_in_prefill; | ||
| use smg::routers::grpc::utils::chat_reasoning_prefill; | ||
| use uuid::Uuid; | ||
|
|
||
| /// Helper function to generate tool call ID (matches router implementation) | ||
|
|
@@ -26,10 +26,18 @@ pub fn generate_tool_call_id( | |
| } | ||
|
|
||
| /// Determine whether the SGLang gRPC request should ask the backend to count | ||
| /// reasoning tokens for this chat request. | ||
| /// reasoning tokens for this chat request, rendered as `prompt`. | ||
| pub(crate) fn chat_requires_reasoning( | ||
| request: &ChatCompletionRequest, | ||
| prompt: &str, | ||
| tokenizer: &dyn Tokenizer, | ||
| ) -> bool { | ||
| chat_reasoning_starts_in_prefill(request, tokenizer) | ||
| chat_reasoning_prefill( | ||
| request, | ||
| prompt, | ||
| &super::runtime::REASONING_PARSER_FACTORY, | ||
| None, | ||
| tokenizer, | ||
| ) | ||
| .expects_reasoning | ||
|
Comment on lines
+35
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
fd -t f '(_test\.go|tests?\.rs)$' bindings/golang |
xargs -r rg -n -C 4 \
'ChatRequiresReasoningWithTokenizer|chat_requires_reasoning|RequireReasoning|<think>|reasoning'Repository: smg-project/smg Length of output: 157 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- cited helper ---'
cat -n bindings/golang/src/utils.rs | sed -n '1,90p'
printf '%s\n' '--- exact symbols and reasoning paths ---'
rg -n -C 5 'chat_reasoning_prefill|ChatRequiresReasoningWithTokenizer|chat_requires_reasoning|RequireReasoning|expects_reasoning|REASONING_PARSER_FACTORY|<think>|reasoning' bindings/golang --glob '*.rs' --glob '*.go' --glob '*_test.go' --glob 'tests/**' || true
printf '%s\n' '--- candidate test files ---'
fd -t f . bindings/golang | rg '(_test\\.go|tests?\\.rs)$' || trueRepository: smg-project/smg Length of output: 40825 🏁 Script executed: #!/bin/bash
set -u
printf '%s\n' '--- chat_reasoning_prefill definition and references ---'
rg -n -C 12 'fn chat_reasoning_prefill|chat_reasoning_prefill' . --glob '*.rs' --glob '*.toml' --glob '*.md' || true
printf '%s\n' '--- reasoning-related tests repository-wide ---'
rg -n -C 8 '#\\[test\\]|#\\[tokio::test\\]|chat_reasoning|expects_reasoning|require_reasoning|<think>|reasoning_content' . --glob '*_test.go' --glob '*.rs' --glob '*.go' --glob '*.py' --glob '*.md' | head -n 500 || true
printf '%s\n' '--- Go test files repository-wide ---'
fd -t f '(_test\\.go)$' . | head -n 200 || trueRepository: smg-project/smg Length of output: 41699 🏁 Script executed: set -u
printf '%s\n' '--- helper definition ---'
rg -n -C 20 'fn chat_reasoning_prefill|chat_reasoning_prefill' . --glob '*.rs' --glob '*.toml' --glob '*.md' || true
printf '%s\n' '--- relevant tests ---'
rg -n -C 8 'chat_reasoning_prefill|expects_reasoning|require_reasoning|<think>|reasoning_content' . --glob '*_test.go' --glob '*.rs' --glob '*.go' --glob '*.py' --glob '*.md' | head -n 500 || true
printf '%s\n' '--- Go test files ---'
fd -t f '(_test\.go)$' . | head -n 200 || trueRepository: smg-project/smg Length of output: 41991 🏁 Script executed: set -u
printf '%s\n' '--- all Go tests ---'
fd -t f '(_test\.go)$' . || true
printf '%s\n' '--- tests mentioning the FFI reasoning API ---'
rg -n -C 6 'ChatRequiresReasoningWithTokenizer|sgl_chat_requires_reasoning_with_tokenizer|RequireReasoning|require_reasoning' . --glob '*_test.go' --glob '*.rs' --glob '*.go' || true
printf '%s\n' '--- helper and FFI contract ---'
cat -n bindings/golang/src/preprocessor.rs | sed -n '358,418p'
cat -n bindings/golang/internal/ffi/preprocessor.go | sed -n '226,265p'
cat -n bindings/golang/internal/grpc/client_grpc.go | sed -n '125,158p'Repository: smg-project/smg Length of output: 41633 🟡 Nit Add Go FFI regression coverage for the prompt/request cross-product. When reasoning is disabled but the rendered prompt ends with 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: smg-project/smg
Length of output: 38078
🤖 get_repo_knowledge executed:
get_repo_knowledge smg-project/smg /tmp/coderabbit-repo-knowledge/smg-project-smg-52a73283/conventions /tmp/coderabbit-repo-knowledge/smg-project-smg-52a73283/learningsLength of output: 4781
🏁 Script executed:
Repository: smg-project/smg
Length of output: 42328
🏁 Script executed:
Repository: smg-project/smg
Length of output: 39785
🟡 Important Carry
starts_in_reasoninginto the response converter. If the rendered prompt ends with an open<think>marker, pass the prefill state to all three converters. The current paths retain onlyexpects_reasoning, while the converter decodes generated tokens directly intocontentand does not track reasoning state. GLM-5.3 reasoning tokens can therefore appear in response content.📍 Affects 3 files
bindings/golang/internal/grpc/client_grpc.go#L135-L135(this comment)bindings/golang/src/client.rs#L218-L219bindings/golang/src/policy.rs#L647-L648🤖 Prompt for AI Agents