()
| 7 | ) |
| 8 | |
| 9 | func RegisterRouter() *gin.Engine { |
| 10 | handler := NewHandle( |
| 11 | checkProxy(), |
| 12 | readAccessToken(), |
| 13 | ) |
| 14 | |
| 15 | // 初始化基础前置参数 |
| 16 | handler.InitBasicConfigForChatGPT() |
| 17 | |
| 18 | router := gin.Default() |
| 19 | router.Use(middlewares.Cors) |
| 20 | |
| 21 | router.GET("/", func(c *gin.Context) { |
| 22 | c.JSON(200, gin.H{ |
| 23 | "message": "Hello, world!", |
| 24 | }) |
| 25 | }) |
| 26 | |
| 27 | router.GET("/ping", func(c *gin.Context) { |
| 28 | c.JSON(200, gin.H{ |
| 29 | "message": "pong", |
| 30 | }) |
| 31 | }) |
| 32 | |
| 33 | router.POST("/auth/session", handler.session) |
| 34 | router.POST("/auth/refresh", handler.refresh) |
| 35 | router.OPTIONS("/v1/chat/completions", optionsHandler) |
| 36 | router.OPTIONS("/v1/responses", optionsHandler) |
| 37 | router.OPTIONS("/v1/images/generations", optionsHandler) |
| 38 | router.OPTIONS("/v1/images/edits", optionsHandler) |
| 39 | router.OPTIONS("/v1/images/variations", optionsHandler) |
| 40 | router.OPTIONS("/v1/files", optionsHandler) |
| 41 | |
| 42 | authGroup := router.Group("").Use(middlewares.Authorization) |
| 43 | authGroup.POST("/v1/chat/completions", handler.nightmare) |
| 44 | authGroup.POST("/v1/responses", handler.responses) |
| 45 | authGroup.POST("/v1/files", handler.files) |
| 46 | authGroup.GET("/v1/models", handler.engines) |
| 47 | authGroup.POST("/backend-api/conversation", handler.chatgptConversation) |
| 48 | authGroup.POST("/v1/images/generations", handler.imageGenerations) |
| 49 | // 改图 + 图生图(变体)统一入口: |
| 50 | // - 传 prompt → 按 prompt 改图 |
| 51 | // - 不传 prompt → 自动注入默认指令,生成图像变体(图生图) |
| 52 | authGroup.POST("/v1/images/edits", handler.imageEdits) |
| 53 | authGroup.POST("/v1/images/variations", handler.imageVariations) |
| 54 | authGroup.OPTIONS("/v1/audio/speech", optionsHandler) |
| 55 | authGroup.POST("/v1/audio/speech", handler.tts) |
| 56 | authGroup.OPTIONS("/v1/audio/transcriptions", optionsHandler) |
| 57 | authGroup.POST("/v1/audio/transcriptions", handler.transcriptions) |
| 58 | authGroup.OPTIONS("/v1/audio/translations", optionsHandler) |
| 59 | authGroup.POST("/v1/audio/translations", handler.translations) |
| 60 | |
| 61 | return router |
| 62 | } |
no test coverage detected