You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
2.5 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. {BillingModelName: "cdance2.0-0611", UpstreamModelName: "cdance2.0-0611", ChannelType: constant.ChannelTypeDoubaoVideoCompatibleTianyiYun},
  21. {BillingModelName: "cdance2.0-fast-0611", UpstreamModelName: "cdance2.0-fast-0611", ChannelType: constant.ChannelTypeDoubaoVideoCompatibleTianyiYun},
  22. }
  23. func SupportsMatrixUsageBilling(modelName string, channelType int, mappedModel string) bool {
  24. if mappedModel == "" {
  25. mappedModel = modelName
  26. }
  27. for _, capability := range matrixUsageCapabilities {
  28. if capability.BillingModelName == modelName &&
  29. capability.UpstreamModelName == mappedModel &&
  30. capability.ChannelType == channelType {
  31. return true
  32. }
  33. }
  34. return false
  35. }
  36. func ResolvePricingModelMapping(modelName string, modelMapping string) (string, error) {
  37. if modelMapping == "" || modelMapping == "{}" {
  38. return modelName, nil
  39. }
  40. modelMap := map[string]string{}
  41. if err := commonpkg.Unmarshal([]byte(modelMapping), &modelMap); err != nil {
  42. return "", err
  43. }
  44. current := modelName
  45. visited := map[string]bool{current: true}
  46. for {
  47. next := modelMap[current]
  48. if next == "" {
  49. return current, nil
  50. }
  51. if visited[next] {
  52. if next == current {
  53. return current, nil
  54. }
  55. return "", errors.New("model_mapping_contains_cycle")
  56. }
  57. visited[next] = true
  58. current = next
  59. }
  60. }