Merge branch 'songquanpeng' into sync_upstream

This commit is contained in:
Martial BE
2023-12-21 15:36:01 +08:00
41 changed files with 1045 additions and 89 deletions

View File

@@ -19,6 +19,10 @@ func (c *OpenAIProviderImageResponseResponse) ResponseHandler(resp *http.Respons
func (p *OpenAIProvider) ImageGenerationsAction(request *types.ImageRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode) {
if isWithinRange(request.Model, request.N) == false {
return nil, common.StringErrorWrapper("n_not_within_range", "n_not_within_range", http.StatusBadRequest)
}
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
@@ -47,3 +51,13 @@ func (p *OpenAIProvider) ImageGenerationsAction(request *types.ImageRequest, isM
return
}
func isWithinRange(element string, value int) bool {
if _, ok := common.DalleGenerationImageAmounts[element]; !ok {
return false
}
min := common.DalleGenerationImageAmounts[element][0]
max := common.DalleGenerationImageAmounts[element][1]
return value >= min && value <= max
}