sanbo commited on
Commit
672ba88
1 Parent(s): 5d3c2a3

update sth. at 2024-12-02 20:26:33

Browse files
Files changed (1) hide show
  1. initialize/router.go +27 -33
initialize/router.go CHANGED
@@ -27,42 +27,36 @@ func RegisterRouter() *gin.Engine {
27
  })
28
  })
29
 
 
30
  prefixGroup := os.Getenv("PREFIX")
31
  if prefixGroup != "" {
32
- prefixRouter := router.Group(prefixGroup)
33
- {
34
- // 现有的路由, hf not support v1
35
- prefixRouter.OPTIONS("/v1/chat/completions", optionsHandler)
36
- prefixRouter.OPTIONS("/v1/chat/models", optionsHandler)
37
- prefixRouter.POST("/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
38
- prefixRouter.GET("/v1/models", middlewares.Authorization, handler.engines)
39
-
40
- // 新增的路由
41
- prefixRouter.POST("/completions", middlewares.Authorization, handler.duckduckgo)
42
- prefixRouter.GET("/models", middlewares.Authorization, handler.engines)
43
-
44
- // 新增的路由
45
- prefixRouter.POST("/api/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
46
- prefixRouter.GET("/api/v1/models", middlewares.Authorization, handler.engines)
47
-
48
- // 新增的路由
49
- prefixRouter.POST("/hf/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
50
- prefixRouter.GET("/hf/v1/models", middlewares.Authorization, handler.engines)
51
- }
52
  }
53
-
54
- router.OPTIONS("/v1/chat/completions", optionsHandler)
55
- router.OPTIONS("/v1/chat/models", optionsHandler)
56
- authGroup := router.Group("").Use(middlewares.Authorization)
57
-
58
- // authGroup 下的路由
59
- authGroup.POST("/v1/chat/completions", handler.duckduckgo)
60
- authGroup.POST("/api/v1/chat/completions", handler.duckduckgo)
61
- authGroup.POST("/completions", handler.duckduckgo)
62
-
63
- authGroup.GET("/v1/models", handler.engines)
64
- authGroup.GET("/api/v1/models", handler.engines)
65
- authGroup.GET("/models", handler.engines)
66
 
67
  return router
68
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  })
28
  })
29
 
30
+ // 注册 prefixGroup 路由
31
  prefixGroup := os.Getenv("PREFIX")
32
  if prefixGroup != "" {
33
+ registerGroupRoutes(router.Group(prefixGroup), handler)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
+ // 注册无前缀的路由
36
+ registerGroupRoutes(router.Group(""), handler)
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  return router
39
  }
40
+ func registerGroupRoutes(group *gin.RouterGroup, handler *Handler) {
41
+ // OPTIONS 路由
42
+ group.OPTIONS("/v1/chat/completions", optionsHandler)
43
+ group.OPTIONS("/v1/chat/models", optionsHandler)
44
+ group.OPTIONS("/completions", optionsHandler)
45
+ group.OPTIONS("/models", optionsHandler)
46
+ group.OPTIONS("/api/v1/chat/completions", optionsHandler)
47
+ group.OPTIONS("/api/v1/models", optionsHandler)
48
+ group.OPTIONS("/hf/v1/chat/completions", optionsHandler)
49
+ group.OPTIONS("/hf/v1/models", optionsHandler)
50
+
51
+ // POST 路由
52
+ group.POST("/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
53
+ group.POST("/api/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
54
+ group.POST("/completions", middlewares.Authorization, handler.duckduckgo)
55
+ group.POST("/hf/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
56
+
57
+ // GET 路由
58
+ group.GET("/v1/models", middlewares.Authorization, handler.engines)
59
+ group.GET("/api/v1/models", middlewares.Authorization, handler.engines)
60
+ group.GET("/models", middlewares.Authorization, handler.engines)
61
+ group.GET("/hf/v1/models", middlewares.Authorization, handler.engines)
62
+ }