(imageRequest *relaymodel.ImageRequest, _ *meta.Meta)
| 66 | } |
| 67 | |
| 68 | func validateImageRequest(imageRequest *relaymodel.ImageRequest, _ *meta.Meta) *relaymodel.ErrorWithStatusCode { |
| 69 | // check prompt length |
| 70 | if imageRequest.Prompt == "" { |
| 71 | return openai.ErrorWrapper(errors.New("prompt is required"), "prompt_missing", http.StatusBadRequest) |
| 72 | } |
| 73 | |
| 74 | // model validation |
| 75 | if !isValidImageSize(imageRequest.Model, imageRequest.Size) { |
| 76 | return openai.ErrorWrapper(errors.New("size not supported for this image model"), "size_not_supported", http.StatusBadRequest) |
| 77 | } |
| 78 | |
| 79 | if !isValidImagePromptLength(imageRequest.Model, len(imageRequest.Prompt)) { |
| 80 | return openai.ErrorWrapper(errors.New("prompt is too long"), "prompt_too_long", http.StatusBadRequest) |
| 81 | } |
| 82 | |
| 83 | // Number of generated images validation |
| 84 | if !isWithinRange(imageRequest.Model, imageRequest.N) { |
| 85 | return openai.ErrorWrapper(errors.New("invalid value of n"), "n_not_within_range", http.StatusBadRequest) |
| 86 | } |
| 87 | return nil |
| 88 | } |
| 89 | |
| 90 | func getImageCostRatio(imageRequest *relaymodel.ImageRequest) (float64, error) { |
| 91 | if imageRequest == nil { |
no test coverage detected