relay_utils.go 877 B

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