api_type.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package constant
  2. import (
  3. "one-api/common"
  4. )
  5. const (
  6. APITypeOpenAI = iota
  7. APITypeAnthropic
  8. APITypePaLM
  9. APITypeBaidu
  10. APITypeZhipu
  11. APITypeAli
  12. APITypeXunfei
  13. APITypeAIProxyLibrary
  14. APITypeTencent
  15. APITypeGemini
  16. APITypeZhipuV4
  17. APITypeOllama
  18. APITypePerplexity
  19. APITypeAws
  20. APITypeCohere
  21. APITypeDify
  22. APITypeJina
  23. APITypeCloudflare
  24. APITypeSiliconFlow
  25. APITypeDummy // this one is only for count, do not add any channel after this
  26. )
  27. func ChannelType2APIType(channelType int) (int, bool) {
  28. apiType := -1
  29. switch channelType {
  30. case common.ChannelTypeOpenAI:
  31. apiType = APITypeOpenAI
  32. case common.ChannelTypeAnthropic:
  33. apiType = APITypeAnthropic
  34. case common.ChannelTypeBaidu:
  35. apiType = APITypeBaidu
  36. case common.ChannelTypePaLM:
  37. apiType = APITypePaLM
  38. case common.ChannelTypeZhipu:
  39. apiType = APITypeZhipu
  40. case common.ChannelTypeAli:
  41. apiType = APITypeAli
  42. case common.ChannelTypeXunfei:
  43. apiType = APITypeXunfei
  44. case common.ChannelTypeAIProxyLibrary:
  45. apiType = APITypeAIProxyLibrary
  46. case common.ChannelTypeTencent:
  47. apiType = APITypeTencent
  48. case common.ChannelTypeGemini:
  49. apiType = APITypeGemini
  50. case common.ChannelTypeZhipu_v4:
  51. apiType = APITypeZhipuV4
  52. case common.ChannelTypeOllama:
  53. apiType = APITypeOllama
  54. case common.ChannelTypePerplexity:
  55. apiType = APITypePerplexity
  56. case common.ChannelTypeAws:
  57. apiType = APITypeAws
  58. case common.ChannelTypeCohere:
  59. apiType = APITypeCohere
  60. case common.ChannelTypeDify:
  61. apiType = APITypeDify
  62. case common.ChannelTypeJina:
  63. apiType = APITypeJina
  64. case common.ChannelCloudflare:
  65. apiType = APITypeCloudflare
  66. case common.ChannelTypeSiliconFlow:
  67. apiType = APITypeSiliconFlow
  68. }
  69. if apiType == -1 {
  70. return APITypeOpenAI, false
  71. }
  72. return apiType, true
  73. }