mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
Merge pull request #6668 from ssharkkky/fix/channel-monitor-gemini-role
fix(monitors): send explicit user role in Gemini monitor probes
This commit is contained in:
@@ -198,7 +198,7 @@ var providerAdapters = map[string]providerAdapter{
|
||||
buildBody: func(_, prompt string) ([]byte, error) {
|
||||
return json.Marshal(map[string]any{
|
||||
"contents": []map[string]any{
|
||||
{"parts": []map[string]any{{"text": prompt}}},
|
||||
{"role": "user", "parts": []map[string]any{{"text": prompt}}},
|
||||
},
|
||||
"generationConfig": map[string]any{"maxOutputTokens": monitorChallengeMaxTokens},
|
||||
})
|
||||
|
||||
@@ -498,3 +498,26 @@ func TestValidateChallenge_AnthropicTextAfterThinking(t *testing.T) {
|
||||
t.Fatalf("validateChallenge(%q, %q) = false, want true", respText, "2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeminiMonitorBodyIncludesExplicitUserRole(t *testing.T) {
|
||||
adapter := providerAdapters[MonitorProviderGemini]
|
||||
body, err := adapter.buildBody("gemini-3.6-flash", "Reply with only 7.")
|
||||
if err != nil {
|
||||
t.Fatalf("buildBody() error = %v", err)
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Contents []struct {
|
||||
Role string `json:"role"`
|
||||
} `json:"contents"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &payload); err != nil {
|
||||
t.Fatalf("Unmarshal() error = %v", err)
|
||||
}
|
||||
if len(payload.Contents) != 1 {
|
||||
t.Fatalf("contents length = %d, want 1", len(payload.Contents))
|
||||
}
|
||||
if payload.Contents[0].Role != "user" {
|
||||
t.Fatalf("contents[0].role = %q, want user", payload.Contents[0].Role)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user