Some checks failed
Build Docker Image / build (push) Has been cancelled
Kiro's upstream system prompt overrides all user-provided system prompts and returns "I can't discuss that" for identity questions. This pre-flight interceptor detects identity questions (Chinese and English patterns) in the last user message and returns a Claude-style response directly, bypassing Kiro entirely. Response language matches the question language; model name reflects the requested model (Claude Opus 4.7, Claude Sonnet 4.5, etc.). Applied to both /v1/messages (Claude) and /v1/chat/completions (OpenAI). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package proxy
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsIdentityQuestion(t *testing.T) {
|
|
yes := []string{
|
|
"你是谁?",
|
|
"你是什么模型",
|
|
"你叫什么名字",
|
|
"什么模型",
|
|
"哪个模型",
|
|
"你基于什么",
|
|
"你是哪个AI",
|
|
"你的身份是什么",
|
|
"who are you",
|
|
"what are you",
|
|
"what model are you",
|
|
"which model do you use",
|
|
"tell me about yourself",
|
|
"identify yourself",
|
|
"what is your name",
|
|
"what AI are you",
|
|
}
|
|
no := []string{
|
|
"帮我写一段 Go 代码",
|
|
"fix this bug",
|
|
"explain this function",
|
|
"what does this code do",
|
|
"你是怎么实现这个功能的", // "how did you implement" - not identity
|
|
"what is the weather today",
|
|
}
|
|
|
|
for _, q := range yes {
|
|
if !isIdentityQuestion(q) {
|
|
t.Errorf("expected isIdentityQuestion(%q)=true", q)
|
|
}
|
|
}
|
|
for _, q := range no {
|
|
if isIdentityQuestion(q) {
|
|
t.Errorf("expected isIdentityQuestion(%q)=false", q)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFriendlyModelName(t *testing.T) {
|
|
cases := []struct{ in, want string }{
|
|
{"claude-opus-4.7", "Claude Opus 4.7"},
|
|
{"claude-opus-4-7", "Claude Opus 4.7"},
|
|
{"claude-opus-4.7-thinking", "Claude Opus 4.7"},
|
|
{"claude-sonnet-4.5", "Claude Sonnet 4.5"},
|
|
{"claude-sonnet-4-5", "Claude Sonnet 4.5"},
|
|
{"claude-sonnet-4.6", "Claude Sonnet 4.6"},
|
|
{"claude-sonnet-4.7", "Claude Sonnet 4.7"},
|
|
{"claude-sonnet-4", "Claude Sonnet 4"},
|
|
{"claude-haiku-4.5", "Claude Haiku 4.5"},
|
|
{"claude-haiku-4-5", "Claude Haiku 4.5"},
|
|
}
|
|
for _, tc := range cases {
|
|
got := friendlyModelName(tc.in)
|
|
if got != tc.want {
|
|
t.Errorf("friendlyModelName(%q) = %q; want %q", tc.in, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestClaudeIdentityTextLanguage(t *testing.T) {
|
|
zhText := claudeIdentityText("claude-opus-4.7", "你是谁")
|
|
if !hasChinese(zhText) {
|
|
t.Errorf("expected Chinese response for Chinese question, got %q", zhText)
|
|
}
|
|
if !strings.Contains(zhText, "Claude Opus 4.7") {
|
|
t.Errorf("expected model name in response, got %q", zhText)
|
|
}
|
|
if !strings.Contains(zhText, "Anthropic") {
|
|
t.Errorf("expected Anthropic in response, got %q", zhText)
|
|
}
|
|
|
|
enText := claudeIdentityText("claude-sonnet-4.5", "who are you")
|
|
if hasChinese(enText) {
|
|
t.Errorf("expected English response for English question, got %q", enText)
|
|
}
|
|
if !strings.Contains(enText, "Claude Sonnet 4.5") {
|
|
t.Errorf("expected model name in English response, got %q", enText)
|
|
}
|
|
}
|