Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(googlegenai): map remaining safety finish reasons to content_filter (#4592)
alexcastgonz9a3f80c6daf3
diff --git a/internal/models/api/googlegenai/client.go b/internal/models/api/googlegenai/client.goindex 14081189b..a7043d8ed 100644--- a/internal/models/api/googlegenai/client.go+++ b/internal/models/api/googlegenai/client.go@@ -276,7 +276,8 @@ func mapFinishReason(reason string, hasToolCalls bool) string {return "stop"case "MAX_TOKENS":return "length"- case "SAFETY", "RECITATION", "BLOCKLIST", "PROHIBITED_CONTENT":+ case "SAFETY", "RECITATION", "LANGUAGE", "BLOCKLIST", "PROHIBITED_CONTENT", "SPII",+ "IMAGE_SAFETY", "IMAGE_PROHIBITED_CONTENT", "IMAGE_RECITATION":return "content_filter"default:return strings.ToLower(reason)diff --git a/internal/models/api/googlegenai/googlegenai_test.go b/internal/models/api/googlegenai/googlegenai_test.goindex 18b60184c..034aa4dc0 100644--- a/internal/models/api/googlegenai/googlegenai_test.go+++ b/internal/models/api/googlegenai/googlegenai_test.go@@ -729,3 +729,34 @@ func TestChatStreamEOFWithoutFinishReasonIsIncomplete(t *testing.T) {})}}++func TestMapFinishReason(t *testing.T) {+ tests := []struct {+ reason string+ hasToolCalls bool+ want string+ }{+ {"", false, ""},+ {"STOP", false, "stop"},+ {"STOP", true, "tool_calls"},+ {"MAX_TOKENS", false, "length"},+ {"SAFETY", false, "content_filter"},+ {"RECITATION", false, "content_filter"},+ {"LANGUAGE", false, "content_filter"},+ {"BLOCKLIST", false, "content_filter"},+ {"PROHIBITED_CONTENT", false, "content_filter"},+ {"SPII", false, "content_filter"},+ {"IMAGE_SAFETY", false, "content_filter"},+ {"IMAGE_PROHIBITED_CONTENT", false, "content_filter"},+ {"IMAGE_RECITATION", false, "content_filter"},+ {"OTHER", false, "other"},+ {"MALFORMED_FUNCTION_CALL", false, "malformed_function_call"},+ }+ for _, tt := range tests {+ t.Run(tt.reason, func(t *testing.T) {+ if got := mapFinishReason(tt.reason, tt.hasToolCalls); got != tt.want {+ t.Fatalf("mapFinishReason(%q, %v) = %q, want %q", tt.reason, tt.hasToolCalls, got, tt.want)+ }+ })+ }+}