-
Notifications
You must be signed in to change notification settings - Fork 11.1k
feat: sora 增加参数校验与计费 #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: sora 增加参数校验与计费 #2006
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| "github.com/gin-gonic/gin" | ||||||||||||||||||||||||||
| "github.com/samber/lo" | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| type HasPrompt interface { | ||||||||||||||||||||||||||
|
|
@@ -128,6 +129,34 @@ func ValidateMultipartDirect(c *gin.Context, info *RelayInfo) *dto.TaskError { | |||||||||||||||||||||||||
| action = constant.TaskActionGenerate | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| info.Action = action | ||||||||||||||||||||||||||
| model := form.Value["model"][0] | ||||||||||||||||||||||||||
| if strings.HasPrefix(model, "sora-2") { | ||||||||||||||||||||||||||
| seconds := 4 | ||||||||||||||||||||||||||
| size := "720x1280" | ||||||||||||||||||||||||||
| if ss, ok := form.Value["seconds"]; ok { | ||||||||||||||||||||||||||
| sInt := common.String2Int(ss[0]) | ||||||||||||||||||||||||||
| if sInt > seconds { | ||||||||||||||||||||||||||
| seconds = common.String2Int(ss[0]) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if s, ok := form.Value["size"]; ok { | ||||||||||||||||||||||||||
| size = s[0] | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if model == "sora-2" && !lo.Contains([]string{"720x1280", "1280x720"}, size) { | ||||||||||||||||||||||||||
| return createTaskError(fmt.Errorf("sora-2 size is invalid"), "invalid_size", http.StatusBadRequest, true) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if model == "sora-2-pro" && !lo.Contains([]string{"720x1280", "1280x720", "1792x1024", "1024x1792"}, size) { | ||||||||||||||||||||||||||
| return createTaskError(fmt.Errorf("sora-2 size is invalid"), "invalid_size", http.StatusBadRequest, true) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+146
to
+151
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Differentiate error messages per model. Both sora-2 and sora-2-pro return the same error message "sora-2 size is invalid". For clarity, specify which model's size constraint was violated. Apply this diff: if model == "sora-2" && !lo.Contains([]string{"720x1280", "1280x720"}, size) {
- return createTaskError(fmt.Errorf("sora-2 size is invalid"), "invalid_size", http.StatusBadRequest, true)
+ return createTaskError(fmt.Errorf("sora-2 size must be 720x1280 or 1280x720"), "invalid_size", http.StatusBadRequest, true)
}
if model == "sora-2-pro" && !lo.Contains([]string{"720x1280", "1280x720", "1792x1024", "1024x1792"}, size) {
- return createTaskError(fmt.Errorf("sora-2 size is invalid"), "invalid_size", http.StatusBadRequest, true)
+ return createTaskError(fmt.Errorf("sora-2-pro size must be one of: 720x1280, 1280x720, 1792x1024, 1024x1792"), "invalid_size", http.StatusBadRequest, true)
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| info.PriceData.OtherRatios = map[string]float64{ | ||||||||||||||||||||||||||
| "seconds": float64(seconds), | ||||||||||||||||||||||||||
| "size": 1, | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if lo.Contains([]string{"1792x1024", "1024x1792"}, size) { | ||||||||||||||||||||||||||
| info.PriceData.OtherRatios["size"] = 1.666667 | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+133
to
+159
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify maximum duration limits for sora models. The code validates size but not the upper bound for Run the following query to check the official documentation: 🌐 Web query: 💡 Result:
Note: the Sora product/app/interface can generate videos up to 20 seconds in some UIs, but the API model parameters for sora-2 / sora-2‑pro accept seconds values of 4, 8, or 12. [3][1] Sources: Enforce maximum duration limit for Sora models 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify seconds override logic.
The current logic only updates
secondsif the form value is greater than the default (4). This means a user cannot explicitly request a shorter duration (e.g., 3 seconds) even if valid.If the intent is to enforce a minimum of 4 seconds, consider:
if ss, ok := form.Value["seconds"]; ok { sInt := common.String2Int(ss[0]) - if sInt > seconds { + if sInt >= 4 { seconds = common.String2Int(ss[0]) + } else { + return createTaskError(fmt.Errorf("seconds must be at least 4"), "invalid_seconds", http.StatusBadRequest, true) } }Or, if any positive value should be allowed, simply:
if ss, ok := form.Value["seconds"]; ok { sInt := common.String2Int(ss[0]) - if sInt > seconds { - seconds = common.String2Int(ss[0]) + if sInt > 0 { + seconds = sInt } }