Added validation for prompt length in
relayImageHelper function
This commit is contained in:
parent
29fbd12870
commit
cb36192c55
@ -18,12 +18,16 @@ var DalleSizeRatios = map[string]map[string]float64{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Array in values, of maxmium and minimum
|
|
||||||
var DalleGenerationImageAmounts = map[string][2]int{
|
var DalleGenerationImageAmounts = map[string][2]int{
|
||||||
"dall-e-2": {1, 10},
|
"dall-e-2": {1, 10},
|
||||||
"dall-e-3": {1, 1}, // OpenAI allows n=1 currently.
|
"dall-e-3": {1, 1}, // OpenAI allows n=1 currently.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DalleImagePromptLengthLimitations = map[string]int{
|
||||||
|
"dall-e-2": 1000,
|
||||||
|
"dall-e-3": 4000,
|
||||||
|
}
|
||||||
|
|
||||||
// ModelRatio
|
// ModelRatio
|
||||||
// https://platform.openai.com/docs/models/model-endpoint-compatibility
|
// https://platform.openai.com/docs/models/model-endpoint-compatibility
|
||||||
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf
|
// https://cloud.baidu.com/doc/WENXINWORKSHOP/s/Blfmc9dlf
|
||||||
|
@ -65,6 +65,11 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
|
|||||||
return errorWrapper(errors.New("invalud value of n"), "number_of_generated_images_not_within_range", http.StatusBadRequest)
|
return errorWrapper(errors.New("invalud value of n"), "number_of_generated_images_not_within_range", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check prompt length
|
||||||
|
if len(imageRequest.Prompt) > common.DalleImagePromptLengthLimitations[imageModel] {
|
||||||
|
return errorWrapper(errors.New("prompt is too long"), "prompt_too_long", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
// map model name
|
// map model name
|
||||||
modelMapping := c.GetString("model_mapping")
|
modelMapping := c.GetString("model_mapping")
|
||||||
isModelMapped := false
|
isModelMapped := false
|
||||||
|
Loading…
Reference in New Issue
Block a user