Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

65 righe
2.3 KiB

  1. package helper
  2. import (
  3. "errors"
  4. commonpkg "github.com/QuantumNous/new-api/common"
  5. "github.com/QuantumNous/new-api/constant"
  6. )
  7. type MatrixUsageCapability struct {
  8. BillingModelName string
  9. UpstreamModelName string
  10. ChannelType int
  11. }
  12. var matrixUsageCapabilities = []MatrixUsageCapability{
  13. {BillingModelName: "seedance-2", UpstreamModelName: "seedance-2", ChannelType: constant.ChannelTypeDoubaoVideo},
  14. {BillingModelName: "doubao-video", UpstreamModelName: "doubao-video", ChannelType: constant.ChannelTypeDoubaoVideo},
  15. {BillingModelName: "doubao-video-seedance", UpstreamModelName: "doubao-video-seedance", ChannelType: constant.ChannelTypeDoubaoVideo},
  16. {BillingModelName: "doubao-seedance-2-0-260128", UpstreamModelName: "doubao-seedance-2-0-260128", ChannelType: constant.ChannelTypeDoubaoVideo},
  17. {BillingModelName: "doubao-seedance-2-0-fast-260128", UpstreamModelName: "doubao-seedance-2-0-fast-260128", ChannelType: constant.ChannelTypeDoubaoVideo},
  18. {BillingModelName: "doubao-seedance-2-0-260128", UpstreamModelName: "doubao-seedance-2-0-260128", ChannelType: constant.ChannelTypeDoubaoVideoCompatibleAiping},
  19. {BillingModelName: "doubao-seedance-2-0-fast-260128", UpstreamModelName: "doubao-seedance-2-0-fast-260128", ChannelType: constant.ChannelTypeDoubaoVideoCompatibleAiping},
  20. }
  21. func SupportsMatrixUsageBilling(modelName string, channelType int, mappedModel string) bool {
  22. if mappedModel == "" {
  23. mappedModel = modelName
  24. }
  25. for _, capability := range matrixUsageCapabilities {
  26. if capability.BillingModelName == modelName &&
  27. capability.UpstreamModelName == mappedModel &&
  28. capability.ChannelType == channelType {
  29. return true
  30. }
  31. }
  32. return false
  33. }
  34. func ResolvePricingModelMapping(modelName string, modelMapping string) (string, error) {
  35. if modelMapping == "" || modelMapping == "{}" {
  36. return modelName, nil
  37. }
  38. modelMap := map[string]string{}
  39. if err := commonpkg.Unmarshal([]byte(modelMapping), &modelMap); err != nil {
  40. return "", err
  41. }
  42. current := modelName
  43. visited := map[string]bool{current: true}
  44. for {
  45. next := modelMap[current]
  46. if next == "" {
  47. return current, nil
  48. }
  49. if visited[next] {
  50. if next == current {
  51. return current, nil
  52. }
  53. return "", errors.New("model_mapping_contains_cycle")
  54. }
  55. visited[next] = true
  56. current = next
  57. }
  58. }