MCPcopy
hub / github.com/songquanpeng/one-api / validateImageRequest

Function validateImageRequest

relay/controller/image.go:68–88  ·  view source on GitHub ↗
(imageRequest *relaymodel.ImageRequest, _ *meta.Meta)

Source from the content-addressed store, hash-verified

66}
67
68func 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
90func getImageCostRatio(imageRequest *relaymodel.ImageRequest) (float64, error) {
91 if imageRequest == nil {

Callers 1

RelayImageHelperFunction · 0.85

Calls 4

ErrorWrapperFunction · 0.92
isValidImageSizeFunction · 0.85
isValidImagePromptLengthFunction · 0.85
isWithinRangeFunction · 0.85

Tested by

no test coverage detected