MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / ImageHelper

Function ImageHelper

relay/image_handler.go:111–247  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

109}
110
111func ImageHelper(c *gin.Context) (newAPIError *types.NewAPIError) {
112 relayInfo := relaycommon.GenRelayInfoImage(c)
113
114 imageRequest, err := getAndValidImageRequest(c, relayInfo)
115 if err != nil {
116 common.LogError(c, fmt.Sprintf("getAndValidImageRequest failed: %s", err.Error()))
117 return types.NewError(err, types.ErrorCodeInvalidRequest)
118 }
119
120 err = helper.ModelMappedHelper(c, relayInfo, imageRequest)
121 if err != nil {
122 return types.NewError(err, types.ErrorCodeChannelModelMappedError)
123 }
124
125 priceData, err := helper.ModelPriceHelper(c, relayInfo, len(imageRequest.Prompt), 0)
126 if err != nil {
127 return types.NewError(err, types.ErrorCodeModelPriceError)
128 }
129 var preConsumedQuota int
130 var quota int
131 var userQuota int
132 if !priceData.UsePrice {
133 // modelRatio 16 = modelPrice $0.04
134 // per 1 modelRatio = $0.04 / 16
135 // priceData.ModelPrice = 0.0025 * priceData.ModelRatio
136 preConsumedQuota, userQuota, newAPIError = preConsumeQuota(c, priceData.ShouldPreConsumedQuota, relayInfo)
137 if newAPIError != nil {
138 return newAPIError
139 }
140 defer func() {
141 if newAPIError != nil {
142 returnPreConsumedQuota(c, relayInfo, userQuota, preConsumedQuota)
143 }
144 }()
145
146 } else {
147 sizeRatio := 1.0
148 qualityRatio := 1.0
149
150 if strings.HasPrefix(imageRequest.Model, "dall-e") {
151 // Size
152 if imageRequest.Size == "256x256" {
153 sizeRatio = 0.4
154 } else if imageRequest.Size == "512x512" {
155 sizeRatio = 0.45
156 } else if imageRequest.Size == "1024x1024" {
157 sizeRatio = 1
158 } else if imageRequest.Size == "1024x1792" || imageRequest.Size == "1792x1024" {
159 sizeRatio = 2
160 }
161
162 if imageRequest.Model == "dall-e-3" && imageRequest.Quality == "hd" {
163 qualityRatio = 2.0
164 if imageRequest.Size == "1024x1792" || imageRequest.Size == "1792x1024" {
165 qualityRatio = 1.5
166 }
167 }
168 }

Callers 1

relayHandlerFunction · 0.92

Calls 15

NewErrorFunction · 0.92
ModelMappedHelperFunction · 0.92
ModelPriceHelperFunction · 0.92
GetUserQuotaFunction · 0.92
NewOpenAIErrorFunction · 0.92
RelayErrorHandlerFunction · 0.92
ResetStatusCodeFunction · 0.92
getAndValidImageRequestFunction · 0.85
preConsumeQuotaFunction · 0.85
returnPreConsumedQuotaFunction · 0.85
GetAdaptorFunction · 0.85
postConsumeQuotaFunction · 0.85

Tested by

no test coverage detected