Files
ragflow/internal/entity/models/common_test.go

103 lines
3.0 KiB
Go
Raw Normal View History

fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
package models
import "testing"
func TestNormalizeModelFamily(t *testing.T) {
tests := []struct {
name string
input *string
want string
}{
{name: "nil", input: nil, want: ""},
{name: "empty", input: modelFamilyTestString(""), want: ""},
{name: "qwen3", input: modelFamilyTestString("qwen3"), want: "qwen3"},
{name: "qwen3 hyphen variant", input: modelFamilyTestString("qwen3-8b"), want: "qwen3"},
{name: "qwen3 dot variant", input: modelFamilyTestString("qwen3.5-4b"), want: "qwen3"},
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
{name: "provider-prefixed qwen3", input: modelFamilyTestString("qwen/qwen3-8b"), want: "qwen3"},
{name: "case-varied qwen3", input: modelFamilyTestString("Qwen/Qwen3.5-4B"), want: "qwen3"},
{name: "provider-prefixed non-qwen", input: modelFamilyTestString("deepseek/deepseek-r1"), want: "deepseek"},
{name: "qwen plus not qwen3", input: modelFamilyTestString("qwen-plus"), want: "qwen"},
{name: "provider-prefixed qwen2.5 not qwen3", input: modelFamilyTestString("qwen/qwen2.5-32b-instruct"), want: "qwen2.5"},
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NormalizeModelFamily(tt.input); got != tt.want {
t.Fatalf("NormalizeModelFamily()=%q, want %q", got, tt.want)
}
})
}
}
func TestGetThinkingAndAnswerExtractsQwenThinking(t *testing.T) {
content := "<think>\nplan</think>\nanswer"
for _, modelType := range []string{
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
"qwen3",
"qwen3-8b",
"qwen/qwen3",
"qwen/qwen3-8b",
"Qwen/Qwen3.5-4B",
} {
t.Run(modelType, func(t *testing.T) {
thinking, answer := GetThinkingAndAnswer(&modelType, &content)
if thinking == nil || *thinking != "plan" {
t.Fatalf("thinking=%v, want plan", thinking)
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
if answer == nil || *answer != "answer" {
t.Fatalf("answer=%v, want answer", answer)
}
})
}
}
func TestGetThinkingAndAnswerLeavesUnknownModelFamiliesUnchanged(t *testing.T) {
content := "<think>\nplan</think>\nanswer"
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
for _, modelType := range []string{
"deepseek",
"deepseek/deepseek-r1",
"qwen-plus",
"qwen/qwen2.5-32b-instruct",
} {
t.Run(modelType, func(t *testing.T) {
thinking, answer := GetThinkingAndAnswer(&modelType, &content)
if thinking != nil {
t.Fatalf("thinking=%v, want nil", thinking)
}
if answer != &content {
t.Fatalf("answer pointer changed")
}
})
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
}
func TestGetThinkingAndAnswerHandlesNilInputs(t *testing.T) {
thinking, answer := GetThinkingAndAnswer(nil, nil)
if thinking != nil || answer != nil {
t.Fatalf("GetThinkingAndAnswer(nil, nil)=(%v, %v), want nils", thinking, answer)
}
content := "<think>\nplan</think>\nanswer"
thinking, answer = GetThinkingAndAnswer(nil, &content)
if thinking != nil {
t.Fatalf("thinking=%v, want nil", thinking)
}
if answer != &content {
t.Fatalf("answer pointer changed")
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
modelType := "qwen3"
thinking, answer = GetThinkingAndAnswer(&modelType, nil)
if thinking != nil {
t.Fatalf("thinking=%v, want nil", thinking)
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
if answer != nil {
t.Fatalf("answer=%v, want nil", answer)
fix: normalize reasoning model families (#15612) ### 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 - [x] Bug Fix (non-breaking change which fixes an issue) - [x] 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`.
2026-06-08 02:32:52 -03:00
}
}
func modelFamilyTestString(value string) *string {
return &value
}