Skip to content

fix: normalize reasoning model families - #15612

Merged
xugangqiang merged 10 commits into
infiniflow:mainfrom
bitloi:fix/15611-reasoning-family-normalization
Jun 8, 2026
Merged

xugangqiang merged 10 commits into
infiniflow:mainfrom
bitloi:fix/15611-reasoning-family-normalization

Conversation

@bitloi

@bitloi bitloi commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #15611.

RAGFlow's fallback reasoning parser only recognized the exact model family qwen3. For provider-prefixed Qwen model names such as SiliconFlow's qwen/qwen3-8b, the derived model class can be qwen/qwen3, so inline <think>...</think> content was not split from the visible answer when reasoning_content was absent.

This PR normalizes model-family detection before fallback reasoning extraction, keeps the parser nil-safe, and adds focused tests for Qwen3 variants plus Gitee and SiliconFlow chat responses.

It also makes SiliconFlow propagate ChatConfig.Thinking into the chat request body, matching the existing Gitee behavior, so Qwen thinking mode is actually enabled when requested.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • Refactoring

Validation

  • /root/go/bin/gofmt -l internal/entity/models/common.go internal/entity/models/common_test.go internal/entity/models/reasoning_family_provider_test.go internal/entity/models/siliconflow.go
  • git diff --check
  • /root/go/bin/go test ./internal/entity/models -run 'Test(NormalizeModelFamily|GetThinkingAndAnswer|GiteeChatExtractsQwenThinkingFromInlineContent|SiliconflowChatExtractsProviderPrefixedQwenThinkingFromInlineContent)' -vet=off -count=1

Note: the full package command /root/go/bin/go test ./internal/entity/models -vet=off -count=1 now runs locally, but it currently fails on an unrelated existing TestAstraflowEmbedReturnsNoSuchMethod panic in internal/entity/models/astraflow.go:482.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🐞 bug Something isn't working, pull request that fix bug. labels Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

NormalizeModelFamily canonicalizes provider-prefixed and variant Qwen model names; GetThinkingAndAnswer and extractThinkContent are nil-safe and use the normalized family to consistently extract inline reasoning from provider responses.

Changes

Model-family normalization and reasoning extraction

Layer / File(s) Summary
Model family normalization and nil-safe extraction logic
internal/entity/models/common.go
NormalizeModelFamily normalizes provider-prefixed and case-varied model names by lowercasing, trimming, stripping path prefixes, mapping qwen3* to "qwen3", and truncating at the first -. GetThinkingAndAnswer and extractThinkContent now guard against nil inputs and use normalized family for detection.
Unit tests for normalization and extraction
internal/entity/models/common_test.go
Table-driven tests validate NormalizeModelFamily canonicalization across nil, empty, variant, provider-prefixed, and case-varied inputs. Tests confirm GetThinkingAndAnswer extracts inline reasoning for qwen3-family models, returns original content for unknown families, and handles nil pointers safely.
Gitee and SiliconFlow provider integration tests and wiring
internal/entity/models/reasoning_family_provider_test.go, internal/entity/models/siliconflow.go
Adds httptest helper and two provider tests that assert the request includes a thinking-enabled object and that inline <think> content is parsed into ReasonContent while the remaining text becomes Answer. SiliconFlow client now conditionally includes a thinking field in requests based on config.

Sequence Diagram

sequenceDiagram
  participant TestClient
  participant ReasoningServer
  participant ChatHandler
  participant Parser
  TestClient->>ReasoningServer: POST /chat/completions (JSON, Authorization)
  ReasoningServer->>ChatHandler: deliver request body
  ChatHandler->>Parser: parse response content (contains <think>...</think>\nanswer)
  Parser->>ChatHandler: ReasonContent + Answer
  ChatHandler->>TestClient: return ChatResponse with ReasonContent and Answer
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Haruko386

🐰 I hop through strings both long and small,
Trim prefixes, lowercase them all.
When appears, I softly part
Reason from answer — a tidy art.
nibbles a carrot, tests all green 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix: normalize reasoning model families' directly and concisely summarizes the main change: normalizing model family detection for reasoning extraction in the codebase.
Linked Issues check ✅ Passed Code changes directly address all objectives from #15611: normalization helper added, nil-safety ensured, model family mapping implemented, provider code updated, and comprehensive unit/integration tests provided.
Out of Scope Changes check ✅ Passed All changes are scoped to reasoning extraction logic: NormalizeModelFamily helper, nil-safety improvements in GetThinkingAndAnswer/extractThinkContent, Siliconflow thinking field addition, and targeted tests. No unrelated refactoring or model discovery changes detected.
Description check ✅ Passed The PR description fully matches the template structure with complete sections covering the problem statement, type of change selection, and validation details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/entity/models/reasoning_family_provider_test.go`:
- Around line 119-129: The helper assertThinkingEnabled runs inside HTTP handler
goroutines so replace its t.Fatalf calls with t.Errorf and return to ensure
failures are reported to the main test goroutine; specifically update
assertThinkingEnabled (the checks for ok/type) to call t.Errorf with the same
messages and then return immediately after each error instead of calling
t.Fatalf.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ccee648d-a4ee-41df-b780-0b1f215d515e

📥 Commits

Reviewing files that changed from the base of the PR and between 67c3e73 and ed22de2.

📒 Files selected for processing (3)
  • internal/entity/models/common.go
  • internal/entity/models/common_test.go
  • internal/entity/models/reasoning_family_provider_test.go

@bitloi
bitloi force-pushed the fix/15611-reasoning-family-normalization branch from ed22de2 to 1fd29f1 Compare June 3, 2026 21:52
@bitloi

bitloi commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Ready for review!

@bitloi bitloi changed the title Fix: normalize reasoning model families fix: normalize reasoning model families Jun 3, 2026
@yingfeng
yingfeng requested a review from Lynn-Inf June 4, 2026 13:09
@yingfeng yingfeng added the ci Continue Integration label Jun 4, 2026
@yingfeng
yingfeng marked this pull request as draft June 4, 2026 13:09
@yingfeng
yingfeng marked this pull request as ready for review June 4, 2026 13:09
@codecov

codecov Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (b0a4580) to head (d12dde6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15612   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization looks necessary, but I'm not confident about the Go side. I'll have my colleague @Haruko386 review it.

@Lynn-Inf
Lynn-Inf requested a review from Haruko386 June 5, 2026 02:21

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitloi LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 5, 2026
@bitloi

bitloi commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Hi @wangq8, @JinHai-CN, @KevinHuSh, @yingfeng, @xugangqiang, would you please review my PR and give me your feedback?

@xugangqiang
xugangqiang requested a review from Lynn-Inf June 8, 2026 03:05

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. For context: the Python implementation doesn't pass the thinking parameter to the LLM call, so this issue doesn't apply there. We'll address it in the upcoming Go migration and leave Python unchanged for now.

@xugangqiang
xugangqiang merged commit 220ee9d into infiniflow:main Jun 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer ☯️ refactor Pull request that refactor/refine code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Normalize model-family detection for reasoning extraction

5 participants