From 62765bb4e761ec89f91aa7d409d4103f7075154e Mon Sep 17 00:00:00 2001 From: lishuangqiang <142634204+lishuangqiang@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:03:38 +0800 Subject: [PATCH] perf(openai): apply the image-intent precheck to the declaration scanners openAIRequestBodyHasImageGenerationDeclaration and openAIRequestBodyImageGenerationToolNeedsNormalization each validate the whole body up front before looking at tools/input/tool_choice. Both branches only match image_gen literals, so the same byte-level necessary condition applies and lets them skip the validation for bodies that cannot match. Refs #8865 --- backend/internal/service/image_generation_intent.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/internal/service/image_generation_intent.go b/backend/internal/service/image_generation_intent.go index 630ed3b229..9593213da3 100644 --- a/backend/internal/service/image_generation_intent.go +++ b/backend/internal/service/image_generation_intent.go @@ -300,7 +300,7 @@ func openAIJSONInputContainsImageGenTool(input gjson.Result) bool { } func openAIRequestBodyHasImageGenerationDeclaration(body []byte) bool { - if len(body) == 0 || !gjson.ValidBytes(body) { + if len(body) == 0 || !openAIBodyMayDeclareImageGeneration(body) || !gjson.ValidBytes(body) { return false } return openAIJSONToolsContainImageGeneration(gjson.GetBytes(body, "tools")) || @@ -309,7 +309,7 @@ func openAIRequestBodyHasImageGenerationDeclaration(body []byte) bool { } func openAIRequestBodyImageGenerationToolNeedsNormalization(body []byte) bool { - if len(body) == 0 || !gjson.ValidBytes(body) { + if len(body) == 0 || !openAIBodyMayDeclareImageGeneration(body) || !gjson.ValidBytes(body) { return false } tools := gjson.GetBytes(body, "tools")