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
This commit is contained in:
lishuangqiang committed 2026-11-16 23:03:38 +08:00
1 parent 487d42c964
commit 62765bb4e7
1 file changed
+2 -2
@@ -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")