fix(providers): xAI generation models bypass chat verification

grok-imagine-video and grok-2-image were not in the isNonChatModel()
allowlist, causing verify to call Chat API which fails with malformed
error. Also fix friendlyVerifyError() fallback splitting inside JSON
values via LastIndex.
This commit is contained in:
viettranx committed 2026-03-31 14:35:57 +07:00
1 parent a565ad8402
commit 8372298fba
1 file changed
+16 -4
+16 -4
View File
@@ -166,6 +166,8 @@ func isNonChatModel(model string) bool {
"veo-", "google/veo-",
"dall-e-", "imagen-", "google/imagen-",
"gemini-2.5-flash-image", "google/gemini-2.5-flash-image",
"grok-imagine", // xAI video generation (grok-imagine-video)
"grok-2-image", // xAI image generation
}
m := strings.ToLower(model)
for _, prefix := range nonChatPrefixes {
@@ -209,14 +211,24 @@ func friendlyVerifyError(err error) string {
}
}
// Fallback: strip "HTTP NNN: provider: " prefix for cleaner display
if idx := strings.LastIndex(msg, ": "); idx >= 0 && idx < len(msg)-2 {
// Fallback: strip "HTTP NNN: provider: " prefix for cleaner display.
// Use the FIRST ": " after "HTTP NNN" to avoid splitting inside JSON values.
if idx := strings.Index(msg, ": "); idx >= 0 && idx < len(msg)-2 {
suffix := msg[idx+2:]
// If the remainder still looks like JSON, just say "invalid model"
// Skip one more ": " to strip "provider: " prefix (e.g. "xai: {...}")
if idx2 := strings.Index(suffix, ": "); idx2 >= 0 && idx2 < 30 {
suffix = suffix[idx2+2:]
}
// If the remainder looks like JSON, say "invalid model"
if strings.HasPrefix(suffix, "{") {
return "Model not recognized by provider"
}
return suffix
// Strip leaked JSON quotes/braces from partial extraction
suffix = strings.TrimRight(suffix, "{}[]")
suffix = strings.Trim(suffix, `"`)
if suffix != "" {
return suffix
}
}
return msg