25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

61 satır
1.6 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. }
  17. func SupportsMatrixUsageBilling(modelName string, channelType int, mappedModel string) bool {
  18. if mappedModel == "" {
  19. mappedModel = modelName
  20. }
  21. for _, capability := range matrixUsageCapabilities {
  22. if capability.BillingModelName == modelName &&
  23. capability.UpstreamModelName == mappedModel &&
  24. capability.ChannelType == channelType {
  25. return true
  26. }
  27. }
  28. return false
  29. }
  30. func ResolvePricingModelMapping(modelName string, modelMapping string) (string, error) {
  31. if modelMapping == "" || modelMapping == "{}" {
  32. return modelName, nil
  33. }
  34. modelMap := map[string]string{}
  35. if err := commonpkg.Unmarshal([]byte(modelMapping), &modelMap); err != nil {
  36. return "", err
  37. }
  38. current := modelName
  39. visited := map[string]bool{current: true}
  40. for {
  41. next := modelMap[current]
  42. if next == "" {
  43. return current, nil
  44. }
  45. if visited[next] {
  46. if next == current {
  47. return current, nil
  48. }
  49. return "", errors.New("model_mapping_contains_cycle")
  50. }
  51. visited[next] = true
  52. current = next
  53. }
  54. }