Skip to content

Commit bbb2148

Browse files
feat: robust model name filter for DeepSeek
Signed-off-by: Jintao Zhang <[email protected]>
1 parent b3e61a1 commit bbb2148

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/semantic-router/pkg/extproc/reason_mode_selector.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,29 @@ func (r *OpenAIRouter) getReasoningModeAndCategory(query string) (bool, string)
4747
return false, categoryName
4848
}
4949

50+
// hasDeepSeekAlias returns true if the model uses a short alias for DeepSeek (e.g., "ds-*")
51+
// Rules:
52+
// - Accept only when the model string starts with: "ds-", "ds_", "ds:", "ds " or exactly equals "ds"
53+
// - Do NOT match occurrences of "ds" in the middle of the model name (e.g., "foo-ds-1b")
54+
func hasDeepSeekAlias(lower string) bool {
55+
lower = strings.TrimSpace(lower)
56+
if strings.HasPrefix(lower, "ds") {
57+
if len(lower) == 2 { // exactly "ds"
58+
return true
59+
}
60+
sep := lower[2]
61+
return sep == '-' || sep == '_' || sep == ':' || sep == ' '
62+
}
63+
return false
64+
}
65+
5066
// getModelFamilyAndTemplateParam returns a normalized model family name and the template param to be used (if any)
5167
func getModelFamilyAndTemplateParam(model string) (string, string) {
5268
lower := strings.ToLower(strings.TrimSpace(model))
5369
if strings.Contains(lower, "qwen3") {
5470
return "qwen3", "enable_thinking"
5571
}
56-
if strings.Contains(lower, "deepseek") || strings.Contains(lower, "ds") {
72+
if strings.Contains(lower, "deepseek") || hasDeepSeekAlias(lower) {
5773
return "deepseek", "thinking"
5874
}
5975
// GPT-OSS family and generic GPT fall back to using reasoning_effort (OpenAI-compatible field)

src/semantic-router/pkg/extproc/reason_mode_selector_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ func TestGetModelFamilyAndTemplateParam(t *testing.T) {
2323
expectedParam: "thinking",
2424
},
2525
{
26-
name: "DeepSeek alias ds",
26+
name: "DeepSeek alias ds (prefix)",
2727
model: "DS-1.5B",
2828
expectedFamily: "deepseek",
2929
expectedParam: "thinking",
3030
},
31+
{
32+
name: "Non-leading ds should not match DeepSeek",
33+
model: "mistral-ds-1b",
34+
expectedFamily: "unknown",
35+
expectedParam: "",
36+
},
3137
{
3238
name: "GPT-OSS family",
3339
model: "gpt-oss-20b",

0 commit comments

Comments
 (0)