MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / getModelRequest

Function getModelRequest

middleware/distributor.go:132–251  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

130}
131
132func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
133 var modelRequest ModelRequest
134 shouldSelectChannel := true
135 var err error
136 if strings.Contains(c.Request.URL.Path, "/mj/") {
137 relayMode := relayconstant.Path2RelayModeMidjourney(c.Request.URL.Path)
138 if relayMode == relayconstant.RelayModeMidjourneyTaskFetch ||
139 relayMode == relayconstant.RelayModeMidjourneyTaskFetchByCondition ||
140 relayMode == relayconstant.RelayModeMidjourneyNotify ||
141 relayMode == relayconstant.RelayModeMidjourneyTaskImageSeed {
142 shouldSelectChannel = false
143 } else {
144 midjourneyRequest := dto.MidjourneyRequest{}
145 err = common.UnmarshalBodyReusable(c, &midjourneyRequest)
146 if err != nil {
147 return nil, false, err
148 }
149 midjourneyModel, mjErr, success := service.GetMjRequestModel(relayMode, &midjourneyRequest)
150 if mjErr != nil {
151 return nil, false, fmt.Errorf(mjErr.Description)
152 }
153 if midjourneyModel == "" {
154 if !success {
155 return nil, false, fmt.Errorf("无效的请求, 无法解析模型")
156 } else {
157 // task fetch, task fetch by condition, notify
158 shouldSelectChannel = false
159 }
160 }
161 modelRequest.Model = midjourneyModel
162 }
163 c.Set("relay_mode", relayMode)
164 } else if strings.Contains(c.Request.URL.Path, "/suno/") {
165 relayMode := relayconstant.Path2RelaySuno(c.Request.Method, c.Request.URL.Path)
166 if relayMode == relayconstant.RelayModeSunoFetch ||
167 relayMode == relayconstant.RelayModeSunoFetchByID {
168 shouldSelectChannel = false
169 } else {
170 modelName := service.CoverTaskActionToModelName(constant.TaskPlatformSuno, c.Param("action"))
171 modelRequest.Model = modelName
172 }
173 c.Set("platform", string(constant.TaskPlatformSuno))
174 c.Set("relay_mode", relayMode)
175 } else if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
176 err = common.UnmarshalBodyReusable(c, &modelRequest)
177 var platform string
178 var relayMode int
179 if strings.HasPrefix(modelRequest.Model, "jimeng") {
180 platform = string(constant.TaskPlatformJimeng)
181 relayMode = relayconstant.Path2RelayJimeng(c.Request.Method, c.Request.URL.Path)
182 if relayMode == relayconstant.RelayModeJimengFetchByID {
183 shouldSelectChannel = false
184 }
185 } else {
186 platform = string(constant.TaskPlatformKling)
187 relayMode = relayconstant.Path2RelayKling(c.Request.Method, c.Request.URL.Path)
188 if relayMode == relayconstant.RelayModeKlingFetchByID {
189 shouldSelectChannel = false

Callers 1

DistributeFunction · 0.85

Calls 8

UnmarshalBodyReusableFunction · 0.92
GetMjRequestModelFunction · 0.92
GetStringIfEmptyFunction · 0.92
SetContextKeyFunction · 0.92
ContainsMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected