relay_adaptor.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package relay
  2. import (
  3. "one-api/constant"
  4. "one-api/relay/channel"
  5. "one-api/relay/channel/ali"
  6. "one-api/relay/channel/aws"
  7. "one-api/relay/channel/baidu"
  8. "one-api/relay/channel/baidu_v2"
  9. "one-api/relay/channel/claude"
  10. "one-api/relay/channel/cloudflare"
  11. "one-api/relay/channel/cohere"
  12. "one-api/relay/channel/coze"
  13. "one-api/relay/channel/deepseek"
  14. "one-api/relay/channel/dify"
  15. "one-api/relay/channel/gemini"
  16. "one-api/relay/channel/jimeng"
  17. "one-api/relay/channel/jina"
  18. "one-api/relay/channel/mistral"
  19. "one-api/relay/channel/mokaai"
  20. "one-api/relay/channel/moonshot"
  21. "one-api/relay/channel/ollama"
  22. "one-api/relay/channel/openai"
  23. "one-api/relay/channel/palm"
  24. "one-api/relay/channel/perplexity"
  25. "one-api/relay/channel/siliconflow"
  26. taskjimeng "one-api/relay/channel/task/jimeng"
  27. "one-api/relay/channel/task/kling"
  28. "one-api/relay/channel/task/suno"
  29. taskvertex "one-api/relay/channel/task/vertex"
  30. taskVidu "one-api/relay/channel/task/vidu"
  31. "one-api/relay/channel/tencent"
  32. "one-api/relay/channel/vertex"
  33. "one-api/relay/channel/volcengine"
  34. "one-api/relay/channel/xai"
  35. "one-api/relay/channel/xunfei"
  36. "one-api/relay/channel/zhipu"
  37. "one-api/relay/channel/zhipu_4v"
  38. "strconv"
  39. "github.com/gin-gonic/gin"
  40. )
  41. func GetAdaptor(apiType int) channel.Adaptor {
  42. switch apiType {
  43. case constant.APITypeAli:
  44. return &ali.Adaptor{}
  45. case constant.APITypeAnthropic:
  46. return &claude.Adaptor{}
  47. case constant.APITypeBaidu:
  48. return &baidu.Adaptor{}
  49. case constant.APITypeGemini:
  50. return &gemini.Adaptor{}
  51. case constant.APITypeOpenAI:
  52. return &openai.Adaptor{}
  53. case constant.APITypePaLM:
  54. return &palm.Adaptor{}
  55. case constant.APITypeTencent:
  56. return &tencent.Adaptor{}
  57. case constant.APITypeXunfei:
  58. return &xunfei.Adaptor{}
  59. case constant.APITypeZhipu:
  60. return &zhipu.Adaptor{}
  61. case constant.APITypeZhipuV4:
  62. return &zhipu_4v.Adaptor{}
  63. case constant.APITypeOllama:
  64. return &ollama.Adaptor{}
  65. case constant.APITypePerplexity:
  66. return &perplexity.Adaptor{}
  67. case constant.APITypeAws:
  68. return &aws.Adaptor{}
  69. case constant.APITypeCohere:
  70. return &cohere.Adaptor{}
  71. case constant.APITypeDify:
  72. return &dify.Adaptor{}
  73. case constant.APITypeJina:
  74. return &jina.Adaptor{}
  75. case constant.APITypeCloudflare:
  76. return &cloudflare.Adaptor{}
  77. case constant.APITypeSiliconFlow:
  78. return &siliconflow.Adaptor{}
  79. case constant.APITypeVertexAi:
  80. return &vertex.Adaptor{}
  81. case constant.APITypeMistral:
  82. return &mistral.Adaptor{}
  83. case constant.APITypeDeepSeek:
  84. return &deepseek.Adaptor{}
  85. case constant.APITypeMokaAI:
  86. return &mokaai.Adaptor{}
  87. case constant.APITypeVolcEngine:
  88. return &volcengine.Adaptor{}
  89. case constant.APITypeBaiduV2:
  90. return &baidu_v2.Adaptor{}
  91. case constant.APITypeOpenRouter:
  92. return &openai.Adaptor{}
  93. case constant.APITypeXinference:
  94. return &openai.Adaptor{}
  95. case constant.APITypeXai:
  96. return &xai.Adaptor{}
  97. case constant.APITypeCoze:
  98. return &coze.Adaptor{}
  99. case constant.APITypeJimeng:
  100. return &jimeng.Adaptor{}
  101. case constant.APITypeMoonshot:
  102. return &moonshot.Adaptor{} // Moonshot uses Claude API
  103. }
  104. return nil
  105. }
  106. func GetTaskPlatform(c *gin.Context) constant.TaskPlatform {
  107. channelType := c.GetInt("channel_type")
  108. if channelType > 0 {
  109. return constant.TaskPlatform(strconv.Itoa(channelType))
  110. }
  111. return constant.TaskPlatform(c.GetString("platform"))
  112. }
  113. func GetTaskAdaptor(platform constant.TaskPlatform) channel.TaskAdaptor {
  114. switch platform {
  115. //case constant.APITypeAIProxyLibrary:
  116. // return &aiproxy.Adaptor{}
  117. case constant.TaskPlatformSuno:
  118. return &suno.TaskAdaptor{}
  119. }
  120. if channelType, err := strconv.ParseInt(string(platform), 10, 64); err == nil {
  121. switch channelType {
  122. case constant.ChannelTypeKling:
  123. return &kling.TaskAdaptor{}
  124. case constant.ChannelTypeJimeng:
  125. return &taskjimeng.TaskAdaptor{}
  126. case constant.ChannelTypeVertexAi:
  127. return &taskvertex.TaskAdaptor{}
  128. case constant.ChannelTypeVidu:
  129. return &taskVidu.TaskAdaptor{}
  130. }
  131. }
  132. return nil
  133. }