@@ -108,6 +108,7 @@ type TaskAdaptor struct {
108108 ChannelType int
109109 apiKey string
110110 baseURL string
111+ aliReq * AliVideoRequest
111112}
112113
113114func (a * TaskAdaptor ) Init (info * relaycommon.RelayInfo ) {
@@ -118,6 +119,11 @@ func (a *TaskAdaptor) Init(info *relaycommon.RelayInfo) {
118119
119120func (a * TaskAdaptor ) ValidateRequestAndSetAction (c * gin.Context , info * relaycommon.RelayInfo ) (taskErr * dto.TaskError ) {
120121 // 阿里通义万相支持 JSON 格式,不使用 multipart
122+ var taskReq relaycommon.TaskSubmitReq
123+ if err := common .UnmarshalBodyReusable (c , & taskReq ); err != nil {
124+ return service .TaskErrorWrapper (err , "unmarshal_task_request_failed" , http .StatusBadRequest )
125+ }
126+ a .aliReq = a .convertToAliRequest (info , taskReq )
121127 return relaycommon .ValidateMultipartDirect (c , info )
122128}
123129
@@ -134,21 +140,39 @@ func (a *TaskAdaptor) BuildRequestHeader(c *gin.Context, req *http.Request, info
134140}
135141
136142func (a * TaskAdaptor ) BuildRequestBody (c * gin.Context , info * relaycommon.RelayInfo ) (io.Reader , error ) {
137- var taskReq relaycommon.TaskSubmitReq
138- if err := common .UnmarshalBodyReusable (c , & taskReq ); err != nil {
139- return nil , errors .Wrap (err , "unmarshal_task_request_failed" )
140- }
141- aliReq := a .convertToAliRequest (taskReq )
142-
143- bodyBytes , err := common .Marshal (aliReq )
143+ bodyBytes , err := common .Marshal (a .aliReq )
144144 if err != nil {
145145 return nil , errors .Wrap (err , "marshal_ali_request_failed" )
146146 }
147147
148148 return bytes .NewReader (bodyBytes ), nil
149149}
150150
151- func (a * TaskAdaptor ) convertToAliRequest (req relaycommon.TaskSubmitReq ) * AliVideoRequest {
151+ func (a * TaskAdaptor ) convertToAliRequest (info * relaycommon.RelayInfo , req relaycommon.TaskSubmitReq ) * AliVideoRequest {
152+ otherRatios := map [string ]map [string ]float64 {
153+ "wan2.5-i2v-preview" : {
154+ "480P" : 1 ,
155+ "720P" : 2 ,
156+ "1080P" : 1 / 0.3 ,
157+ },
158+ "wan2.2-i2v-plus" : {
159+ "480P" : 1 ,
160+ "1080P" : 0.7 / 0.14 ,
161+ },
162+ "wan2.2-kf2v-flash" : {
163+ "480P" : 1 ,
164+ "720P" : 2 ,
165+ "1080P" : 4.8 ,
166+ },
167+ "wan2.2-i2v-flash" : {
168+ "480P" : 1 ,
169+ "720P" : 2 ,
170+ },
171+ "wan2.2-s2v" : {
172+ "480P" : 1 ,
173+ "720P" : 0.9 / 0.5 ,
174+ },
175+ }
152176 aliReq := & AliVideoRequest {
153177 Model : req .Model ,
154178 Input : AliVideoInput {
@@ -196,6 +220,19 @@ func (a *TaskAdaptor) convertToAliRequest(req relaycommon.TaskSubmitReq) *AliVid
196220 }
197221 }
198222
223+ info .PriceData .OtherRatios = map [string ]float64 {
224+ "seconds" : float64 (aliReq .Parameters .Duration ),
225+ //"size": 1,
226+ }
227+
228+ if otherRatio , ok := otherRatios [req .Model ]; ok {
229+ if ratio , ok := otherRatio [aliReq .Parameters .Resolution ]; ok {
230+ info .PriceData .OtherRatios [fmt .Sprintf ("resolution-%s" , aliReq .Parameters .Resolution )] = ratio
231+ }
232+ }
233+
234+ // println(fmt.Sprintf("other ratios: %v", info.PriceData.OtherRatios))
235+
199236 return aliReq
200237}
201238
0 commit comments