🧱 update router

This commit is contained in:
warjiang
2023-06-15 12:19:13 +08:00
parent 932eefebfd
commit 9ba3a1e89e
2 changed files with 54 additions and 31 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"github.com/stulzq/azure-openai-proxy/azure"
)
@@ -14,7 +15,14 @@ func registerRoute(r *gin.Engine) {
r.Any("/health", func(c *gin.Context) {
c.Status(200)
})
r.Any("/v1/*path", azure.Proxy)
apiBase := viper.GetString("api_base")
stripPrefixConverter := azure.NewStripPrefixConverter(apiBase)
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))
}
}