-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrouter.go
38 lines (35 loc) · 1.31 KB
/
router.go
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
package router
import (
"github.com/gin-gonic/gin"
"github.com/soulteary/amazing-openai-api/models/azure"
"github.com/soulteary/amazing-openai-api/models/gemini"
"github.com/soulteary/amazing-openai-api/models/yi"
)
func RegisterModelRoute(r *gin.Engine, serviceType string) {
// https://platform.openai.com/docs/api-reference
apiBase := "/v1"
switch serviceType {
case "azure":
stripPrefixConverter := azure.NewStripPrefixConverter(apiBase)
r.GET(stripPrefixConverter.Prefix+"/models", azure.ModelProxy)
apiBasedRouter := r.Group(apiBase)
{
apiBasedRouter.Any("/completions", azure.ProxyWithConverter(stripPrefixConverter))
apiBasedRouter.Any("/chat/completions", azure.ProxyWithConverter(stripPrefixConverter))
}
case "yi":
stripPrefixConverter := yi.NewStripPrefixConverter(apiBase)
apiBasedRouter := r.Group(apiBase)
{
apiBasedRouter.Any("/completions", yi.ProxyWithConverter(stripPrefixConverter))
apiBasedRouter.Any("/chat/completions", yi.ProxyWithConverter(stripPrefixConverter))
}
case "gemini":
stripPrefixConverter := gemini.NewStripPrefixConverter(apiBase)
apiBasedRouter := r.Group(apiBase)
{
apiBasedRouter.Any("/completions", gemini.ProxyWithConverter(stripPrefixConverter))
apiBasedRouter.Any("/chat/completions", gemini.ProxyWithConverter(stripPrefixConverter))
}
}
}