relay_utils.go 902 B

123456789101112131415161718192021222324252627282930313233343536
  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/common"
  9. "strings"
  10. )
  11. var StopFinishReason = "stop"
  12. func GetFullRequestURL(baseURL string, requestURL string, channelType int) string {
  13. fullRequestURL := fmt.Sprintf("%s%s", baseURL, requestURL)
  14. if strings.HasPrefix(baseURL, "https://gateway.ai.cloudflare.com") {
  15. switch channelType {
  16. case common.ChannelTypeOpenAI:
  17. fullRequestURL = fmt.Sprintf("%s%s", baseURL, strings.TrimPrefix(requestURL, "/v1"))
  18. case common.ChannelTypeAzure:
  19. fullRequestURL = fmt.Sprintf("%s%s", baseURL, strings.TrimPrefix(requestURL, "/openai/deployments"))
  20. }
  21. }
  22. return fullRequestURL
  23. }
  24. func GetAPIVersion(c *gin.Context) string {
  25. query := c.Request.URL.Query()
  26. apiVersion := query.Get("api-version")
  27. if apiVersion == "" {
  28. apiVersion = c.GetString("api_version")
  29. }
  30. return apiVersion
  31. }