relay_utils.go 832 B

1234567891011121314151617181920212223242526272829303132
  1. package common
  2. import (
  3. "fmt"
  4. "one-api/constant"
  5. "strings"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func GetFullRequestURL(baseURL string, requestURL string, channelType int) string {
  9. fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
  10. if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
  11. switch channelType {
  12. case constant.ChannelTypeOpenAI:
  13. fullRequestURL = fmt.Sprintf("%s%s", baseURL, strings.TrimPrefix(requestURL, "/v1"))
  14. case constant.ChannelTypeAzure:
  15. fullRequestURL = fmt.Sprintf("%s%s", baseURL, strings.TrimPrefix(requestURL, "/openai/deployments"))
  16. }
  17. }
  18. return fullRequestURL
  19. }
  20. func GetAPIVersion(c *gin.Context) string {
  21. query := c.Request.URL.Query()
  22. apiVersion := query.Get("api-version")
  23. if apiVersion == "" {
  24. apiVersion = c.GetString("api_version")
  25. }
  26. return apiVersion
  27. }