Commit 04d525e3 by CaIon

馃殌 feat(auth): support new model API paths in authentication and routing

- Updated TokenAuth middleware to handle requests for both `/v1beta/models/` and `/v1/models/`.
- Adjusted distributor middleware to recognize the new model path.
- Enhanced relay mode determination to include the new model path.
- Added route for handling POST requests to `/models/*path`.

These changes ensure compatibility with the new model API structure, improving the overall routing and authentication flow.
parent 6220b3ee
...@@ -184,7 +184,7 @@ func TokenAuth() func(c *gin.Context) { ...@@ -184,7 +184,7 @@ func TokenAuth() func(c *gin.Context) {
} }
} }
// gemini api 浠巕uery涓幏鍙杒ey // gemini api 浠巕uery涓幏鍙杒ey
if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") { if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") || strings.HasPrefix(c.Request.URL.Path, "/v1/models/") {
skKey := c.Query("key") skKey := c.Query("key")
if skKey != "" { if skKey != "" {
c.Request.Header.Set("Authorization", "Bearer "+skKey) c.Request.Header.Set("Authorization", "Bearer "+skKey)
......
...@@ -179,7 +179,7 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) { ...@@ -179,7 +179,7 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) {
} }
c.Set("platform", string(constant.TaskPlatformKling)) c.Set("platform", string(constant.TaskPlatformKling))
c.Set("relay_mode", relayMode) c.Set("relay_mode", relayMode)
} else if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") { } else if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models/") || strings.HasPrefix(c.Request.URL.Path, "/v1/models/") {
// Gemini API 璺緞澶勭悊: /v1beta/models/gemini-2.0-flash:generateContent // Gemini API 璺緞澶勭悊: /v1beta/models/gemini-2.0-flash:generateContent
relayMode := relayconstant.RelayModeGemini relayMode := relayconstant.RelayModeGemini
modelName := extractModelNameFromGeminiPath(c.Request.URL.Path) modelName := extractModelNameFromGeminiPath(c.Request.URL.Path)
......
...@@ -80,7 +80,7 @@ func Path2RelayMode(path string) int { ...@@ -80,7 +80,7 @@ func Path2RelayMode(path string) int {
relayMode = RelayModeRerank relayMode = RelayModeRerank
} else if strings.HasPrefix(path, "/v1/realtime") { } else if strings.HasPrefix(path, "/v1/realtime") {
relayMode = RelayModeRealtime relayMode = RelayModeRealtime
} else if strings.HasPrefix(path, "/v1beta/models") { } else if strings.HasPrefix(path, "/v1beta/models") || strings.HasPrefix(path, "/v1/models") {
relayMode = RelayModeGemini relayMode = RelayModeGemini
} }
return relayMode return relayMode
......
...@@ -63,6 +63,7 @@ func SetRelayRouter(router *gin.Engine) { ...@@ -63,6 +63,7 @@ func SetRelayRouter(router *gin.Engine) {
httpRouter.DELETE("/models/:model", controller.RelayNotImplemented) httpRouter.DELETE("/models/:model", controller.RelayNotImplemented)
httpRouter.POST("/moderations", controller.Relay) httpRouter.POST("/moderations", controller.Relay)
httpRouter.POST("/rerank", controller.Relay) httpRouter.POST("/rerank", controller.Relay)
httpRouter.POST("/models/*path", controller.Relay)
} }
relayMjRouter := router.Group("/mj") relayMjRouter := router.Group("/mj")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment