Files
azure-openai-proxy/cmd/router.go
Xinhao Zhuang c40e27c3b4 feat: ability to mimic /v1/models/ api (#68)
* add: ability to mimic `/v1/models/` api

* fix: missing json dependency

* fix: accidentally remove dependency

* fix: linter error caught by gh workflow
2023-09-27 19:20:26 +08:00

30 lines
1.0 KiB
Go

package main
import (
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"github.com/stulzq/azure-openai-proxy/azure"
)
// registerRoute registers all routes
func registerRoute(r *gin.Engine) {
// https://platform.openai.com/docs/api-reference
r.HEAD("/", func(c *gin.Context) {
c.Status(200)
})
r.Any("/health", func(c *gin.Context) {
c.Status(200)
})
apiBase := viper.GetString("api_base")
stripPrefixConverter := azure.NewStripPrefixConverter(apiBase)
r.GET(stripPrefixConverter.Prefix+"/models", azure.ModelProxy)
templateConverter := azure.NewTemplateConverter("/openai/deployments/{{.DeploymentName}}/embeddings")
apiBasedRouter := r.Group(apiBase)
{
apiBasedRouter.Any("/engines/:model/embeddings", azure.ProxyWithConverter(templateConverter))
apiBasedRouter.Any("/completions", azure.ProxyWithConverter(stripPrefixConverter))
apiBasedRouter.Any("/chat/completions", azure.ProxyWithConverter(stripPrefixConverter))
apiBasedRouter.Any("/embeddings", azure.ProxyWithConverter(stripPrefixConverter))
}
}