mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-24 19:04:25 +08:00
fix(codex): allow hosted image_generation injection on standard Responses without reasoning
- gate automatic image_generation tool injection for use_responses_lite catalog models on actual Responses-Lite routing (including credential and model header overrides) or presence of reasoning effort - retract untouched auto-injected image_generation tools during single-pass payload finalization when user payload rules configure reasoning effort or switch to an incompatible route - update Codex executor and payload barrier regression tests across HTTP and WebSocket streaming and non-streaming paths Closes: #7384 Co-authored-by: Dylan <1990016@gmail.com>
This commit is contained in:
@@ -808,29 +808,61 @@ func ensureImageGenerationTool(body []byte, baseModel string, auth *cliproxyauth
|
||||
return doc.Bytes()
|
||||
}
|
||||
|
||||
func ensureImageGenerationToolDoc(doc *ojson.Doc, baseModel string, auth *cliproxyauth.Auth, headers http.Header) bool {
|
||||
if doc == nil || isCodexResponsesLiteRequestDoc(doc, headers) || isCodexResponsesLiteModel(baseModel) {
|
||||
return false
|
||||
}
|
||||
if strings.HasSuffix(baseModel, "spark") {
|
||||
return false
|
||||
}
|
||||
if isCodexFreePlanAuth(auth) {
|
||||
return false
|
||||
}
|
||||
func codexRequestHasReasoningForHostedImageDoc(doc *ojson.Doc, model string) bool {
|
||||
return helps.CodexRequestHasReasoningForHostedImageDoc(doc, model)
|
||||
}
|
||||
|
||||
func isCodexResponsesLiteRequestForAuthDoc(doc *ojson.Doc, modelName string, auth *cliproxyauth.Auth, headers http.Header) bool {
|
||||
return helps.CodexResponsesLiteRequestForAuthDoc(doc, modelName, auth, headers)
|
||||
}
|
||||
|
||||
func codexToolsAlreadyContainImageGenDoc(doc *ojson.Doc) bool {
|
||||
if doc == nil {
|
||||
return false
|
||||
}
|
||||
tools := doc.Get("tools")
|
||||
if !tools.Exists() || !tools.IsArray() {
|
||||
return false
|
||||
}
|
||||
for _, t := range tools.Array() {
|
||||
if t.Get("type").String() == "image_generation" || isImageGenerationFunctionTool(t) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func appendImageGenerationToolDoc(doc *ojson.Doc) bool {
|
||||
if doc == nil {
|
||||
return false
|
||||
}
|
||||
tools := doc.Get("tools")
|
||||
if !tools.Exists() || !tools.IsArray() {
|
||||
return doc.SetRawBytes("tools", imageGenToolArrayJSON) == nil
|
||||
}
|
||||
for _, t := range tools.Array() {
|
||||
if t.Get("type").String() == "image_generation" || isImageGenerationFunctionTool(t) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return doc.SetRawBytes("tools.-1", imageGenToolJSON) == nil
|
||||
}
|
||||
|
||||
func ensureImageGenerationToolDoc(doc *ojson.Doc, baseModel string, auth *cliproxyauth.Auth, headers http.Header) bool {
|
||||
if doc == nil || isCodexFreePlanAuth(auth) || codexToolsAlreadyContainImageGenDoc(doc) {
|
||||
return false
|
||||
}
|
||||
modelName := strings.TrimSpace(thinking.ParseSuffix(baseModel).ModelName)
|
||||
if modelName == "" {
|
||||
modelName = strings.TrimSpace(thinking.ParseSuffix(doc.Get("model").String()).ModelName)
|
||||
}
|
||||
if isCodexResponsesLiteRequestForAuthDoc(doc, modelName, auth, headers) {
|
||||
return false
|
||||
}
|
||||
if isCodexResponsesLiteModel(modelName) && codexRequestHasReasoningForHostedImageDoc(doc, baseModel) {
|
||||
return false
|
||||
}
|
||||
if strings.HasSuffix(strings.ToLower(modelName), "spark") {
|
||||
return false
|
||||
}
|
||||
return appendImageGenerationToolDoc(doc)
|
||||
}
|
||||
|
||||
func resolveCodexGPTImage2BaseModel(cfg *config.Config) string {
|
||||
if cfg == nil {
|
||||
return codexOpenAIImagesMainModel
|
||||
|
||||
Reference in New Issue
Block a user