|
package initialize |
|
|
|
import ( |
|
"aurora/middlewares" |
|
"net/http" |
|
"os" |
|
|
|
"github.com/gin-gonic/gin" |
|
) |
|
|
|
func RegisterRouter() *gin.Engine { |
|
handler := NewHandle( |
|
checkProxy(), |
|
) |
|
|
|
router := gin.Default() |
|
router.Use(middlewares.Cors) |
|
|
|
|
|
|
|
|
|
|
|
|
|
router.GET("/", func(c *gin.Context) { |
|
c.Redirect(http.StatusFound, "/web") |
|
}) |
|
|
|
router.GET("/ping", func(c *gin.Context) { |
|
c.JSON(200, gin.H{ |
|
"message": "pong", |
|
}) |
|
}) |
|
|
|
|
|
prefixGroup := os.Getenv("PREFIX") |
|
if prefixGroup != "" { |
|
registerGroupRoutes(router.Group(prefixGroup), handler) |
|
} |
|
|
|
registerGroupRoutes(router.Group(""), handler) |
|
|
|
return router |
|
} |
|
func registerGroupRoutes(group *gin.RouterGroup, handler *Handler) { |
|
|
|
group.OPTIONS("/v1/chat/completions", optionsHandler) |
|
group.OPTIONS("/v1/chat/models", optionsHandler) |
|
group.OPTIONS("/completions", optionsHandler) |
|
group.OPTIONS("/models", optionsHandler) |
|
group.OPTIONS("/api/v1/chat/completions", optionsHandler) |
|
group.OPTIONS("/api/v1/models", optionsHandler) |
|
group.OPTIONS("/hf/v1/chat/completions", optionsHandler) |
|
group.OPTIONS("/hf/v1/models", optionsHandler) |
|
|
|
|
|
group.POST("/v1/chat/completions", middlewares.Authorization, handler.duckduckgo) |
|
group.POST("/api/v1/chat/completions", middlewares.Authorization, handler.duckduckgo) |
|
group.POST("/completions", middlewares.Authorization, handler.duckduckgo) |
|
group.POST("/hf/v1/chat/completions", middlewares.Authorization, handler.duckduckgo) |
|
|
|
|
|
group.GET("/v1/models", middlewares.Authorization, handler.engines) |
|
group.GET("/api/v1/models", middlewares.Authorization, handler.engines) |
|
group.GET("/models", middlewares.Authorization, handler.engines) |
|
group.GET("/hf/v1/models", middlewares.Authorization, handler.engines) |
|
} |
|
|