File size: 1,745 Bytes
6390363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2224f03
6390363
 
 
 
2224f03
 
 
 
 
 
6390363
 
 
 
 
 
2224f03
 
6390363
2224f03
 
 
6390363
2224f03
 
 
6390363
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package initialize

import (
	"aurora/middlewares"
	"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.JSON(200, gin.H{
			"message": "Hello, world!",
		})
	})

	router.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})

	prefixGroup := os.Getenv("PREFIX")
	if prefixGroup != "" {
		prefixRouter := router.Group(prefixGroup)
		{
			// ηŽ°ζœ‰ηš„θ·―η”±
			prefixRouter.OPTIONS("/v1/chat/completions", optionsHandler)
			prefixRouter.OPTIONS("/v1/chat/models", optionsHandler)
			prefixRouter.POST("/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
			prefixRouter.GET("/v1/models", middlewares.Authorization, handler.engines)

			// ζ–°ε’žηš„θ·―η”±
			prefixRouter.POST("/api/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
			prefixRouter.POST("/completions", middlewares.Authorization, handler.duckduckgo)
			prefixRouter.GET("/api/v1/models", middlewares.Authorization, handler.engines)
			prefixRouter.GET("/models", middlewares.Authorization, handler.engines)
		}
	}

	router.OPTIONS("/v1/chat/completions", optionsHandler)
	router.OPTIONS("/v1/chat/models", optionsHandler)
	authGroup := router.Group("").Use(middlewares.Authorization)

	// authGroup δΈ‹ηš„θ·―η”±
	authGroup.POST("/v1/chat/completions", handler.duckduckgo)
	authGroup.POST("/api/v1/chat/completions", handler.duckduckgo)
	authGroup.POST("/completions", handler.duckduckgo)

	authGroup.GET("/v1/models", handler.engines)
	authGroup.GET("/api/v1/models", handler.engines)
	authGroup.GET("/models", handler.engines)

	return router
}