-
Notifications
You must be signed in to change notification settings - Fork 11.2k
1 #3475
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
1 #3475
Changes from all commits
680271d
988b297
9db210d
f5b1a79
6658556
d31fbb6
8446231
90063cb
2186b57
8e89b09
989f667
37f5126
e20c678
629be09
b69a41e
8e19212
2933917
df6cb95
37f727c
b1b647d
b1a56ec
8671548
3ca517d
ca554ba
5a65dc4
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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/QuantumNous/new-api/constant" | ||
| ) | ||
|
|
||
| func TestGetEndpointTypesByChannelTypeRecognizesGrokImagineImageModels(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| channel int | ||
| model string | ||
| expected constant.EndpointType | ||
| }{ | ||
| { | ||
| name: "grok imagine 1.0 generation", | ||
| channel: constant.ChannelTypeXai, | ||
| model: "grok-imagine-1.0", | ||
| expected: constant.EndpointTypeImageGeneration, | ||
| }, | ||
| { | ||
| name: "grok imagine 1.0 fast generation", | ||
| channel: constant.ChannelTypeXai, | ||
| model: "grok-imagine-1.0-fast", | ||
| expected: constant.EndpointTypeImageGeneration, | ||
| }, | ||
| { | ||
| name: "grok imagine 1.0 edit", | ||
| channel: constant.ChannelTypeXai, | ||
| model: "grok-imagine-1.0-edit", | ||
| expected: constant.EndpointTypeImageEdit, | ||
| }, | ||
| { | ||
| name: "grok imagine video stays video", | ||
| channel: constant.ChannelTypeSora, | ||
| model: "grok-imagine-1.0-video", | ||
| expected: constant.EndpointTypeOpenAIVideo, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := GetEndpointTypesByChannelType(tt.channel, tt.model) | ||
| if len(got) == 0 { | ||
| t.Fatalf("expected endpoint types for %s", tt.model) | ||
| } | ||
| if got[0] != tt.expected { | ||
| t.Fatalf("expected first endpoint %s, got %s", tt.expected, got[0]) | ||
| } | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,8 +81,8 @@ func Distribute() func(c *gin.Context) { | |
| } | ||
| var selectGroup string | ||
| usingGroup := common.GetContextKeyString(c, constant.ContextKeyUsingGroup) | ||
| // check path is /pg/chat/completions | ||
| if strings.HasPrefix(c.Request.URL.Path, "/pg/chat/completions") { | ||
| // playground requests may override group in body | ||
| if strings.HasPrefix(c.Request.URL.Path, "/pg/") { | ||
|
Comment on lines
+84
to
+85
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.
After broadening to 🔧 Suggested direction (normalize path once for getModelRequest decisions)func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
+ pathForMatch := c.Request.URL.Path
+ if strings.HasPrefix(pathForMatch, "/pg/") {
+ pathForMatch = "/v1" + strings.TrimPrefix(pathForMatch, "/pg")
+ }
var modelRequest ModelRequest
shouldSelectChannel := true
var err error
- if strings.Contains(c.Request.URL.Path, "/v1/video/generations") {
+ if strings.Contains(pathForMatch, "/v1/video/generations") {
...
}
- if strings.HasPrefix(c.Request.URL.Path, "/v1/images/generations") {
+ if strings.HasPrefix(pathForMatch, "/v1/images/generations") {
...
- } else if strings.HasPrefix(c.Request.URL.Path, "/v1/images/edits") {
+ } else if strings.HasPrefix(pathForMatch, "/v1/images/edits") {
...
}
}🤖 Prompt for AI Agents |
||
| playgroundRequest := &dto.PlayGroundRequest{} | ||
| err = common.UnmarshalBodyReusable(c, playgroundRequest) | ||
| if err != 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.
Reject access-token flows in video playground handlers for parity with
Playground.PlaygroundVideoSubmitandPlaygroundVideoFetchcurrently miss theuse_access_tokenguard thatPlaygroundenforces. This introduces inconsistent auth behavior for/pg/video/*.🔧 Suggested fix
func PlaygroundVideoSubmit(c *gin.Context) { var newAPIError *types.NewAPIError defer func() { if newAPIError != nil { c.JSON(newAPIError.StatusCode, gin.H{ "error": newAPIError.ToOpenAIError(), }) } }() + if c.GetBool("use_access_token") { + newAPIError = types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied, types.ErrOptionWithSkipRetry()) + return + } if newAPIError = setupPlaygroundTokenContext(c, "playground-video", c.GetString("group")); newAPIError != nil { return } RelayTask(c) } func PlaygroundVideoFetch(c *gin.Context) { var newAPIError *types.NewAPIError defer func() { if newAPIError != nil { c.JSON(newAPIError.StatusCode, gin.H{ "error": newAPIError.ToOpenAIError(), }) } }() + if c.GetBool("use_access_token") { + newAPIError = types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied, types.ErrOptionWithSkipRetry()) + return + } if newAPIError = setupPlaygroundTokenContext(c, "playground-video-fetch", c.GetString("group")); newAPIError != nil { return } RelayTaskFetch(c) }📝 Committable suggestion
🤖 Prompt for AI Agents