feat: support image quality control
This commit is contained in:
@@ -378,3 +378,64 @@ func (imageCountProcessor) Process(params map[string]any, modelType string, cont
|
||||
params["n"] = count
|
||||
return true
|
||||
}
|
||||
|
||||
type imageQualityProcessor struct{}
|
||||
|
||||
func (imageQualityProcessor) Name() string { return "ImageQualityProcessor" }
|
||||
|
||||
var openAICompatibleImageQualities = map[string]struct{}{
|
||||
"low": {},
|
||||
"medium": {},
|
||||
"high": {},
|
||||
"auto": {},
|
||||
}
|
||||
|
||||
func (imageQualityProcessor) ShouldProcess(params map[string]any, modelType string, context *paramProcessContext) bool {
|
||||
if modelType != "image_generate" && modelType != "image_edit" {
|
||||
return false
|
||||
}
|
||||
_, ok := params["quality"]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (imageQualityProcessor) Process(params map[string]any, modelType string, context *paramProcessContext) bool {
|
||||
capability := capabilityForType(context.modelCapability, modelType)
|
||||
quality := stringFromAny(params["quality"])
|
||||
if supportsImageQualityControl(capability) && isOpenAICompatibleImageQuality(quality) {
|
||||
return true
|
||||
}
|
||||
|
||||
before := params["quality"]
|
||||
delete(params, "quality")
|
||||
context.recordChange(
|
||||
"ImageQualityProcessor",
|
||||
"remove",
|
||||
"quality",
|
||||
before,
|
||||
nil,
|
||||
"模型能力未开启生成质量控制,已移除 quality 参数。",
|
||||
capabilityPath(modelType, "support_quality_control"),
|
||||
capabilityValue(context.modelCapability, modelType, "support_quality_control"),
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
func supportsImageQualityControl(capability map[string]any) bool {
|
||||
if capability == nil {
|
||||
return false
|
||||
}
|
||||
for _, key := range []string{"support_quality_control", "supportQualityControl", "quality_control", "qualityControl", "quality"} {
|
||||
if boolFromAny(capability[key]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isOpenAICompatibleImageQuality(value string) bool {
|
||||
if value == "" {
|
||||
return false
|
||||
}
|
||||
_, ok := openAICompatibleImageQualities[value]
|
||||
return ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user