MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / updatePricing

Function updatePricing

model/pricing.go:61–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59}
60
61func updatePricing() {
62 //modelRatios := common.GetModelRatios()
63 enableAbilities, err := GetAllEnableAbilityWithChannels()
64 if err != nil {
65 common.SysError(fmt.Sprintf("GetAllEnableAbilityWithChannels error: %v", err))
66 return
67 }
68 modelGroupsMap := make(map[string]*types.Set[string])
69
70 for _, ability := range enableAbilities {
71 groups, ok := modelGroupsMap[ability.Model]
72 if !ok {
73 groups = types.NewSet[string]()
74 modelGroupsMap[ability.Model] = groups
75 }
76 groups.Add(ability.Group)
77 }
78
79 //这里使用切片而不是Set,因为一个模型可能支持多个端点类型,并且第一个端点是优先使用端点
80 modelSupportEndpointsStr := make(map[string][]string)
81
82 for _, ability := range enableAbilities {
83 endpoints, ok := modelSupportEndpointsStr[ability.Model]
84 if !ok {
85 endpoints = make([]string, 0)
86 modelSupportEndpointsStr[ability.Model] = endpoints
87 }
88 channelTypes := common.GetEndpointTypesByChannelType(ability.ChannelType, ability.Model)
89 for _, channelType := range channelTypes {
90 if !common.StringsContains(endpoints, string(channelType)) {
91 endpoints = append(endpoints, string(channelType))
92 }
93 }
94 modelSupportEndpointsStr[ability.Model] = endpoints
95 }
96
97 modelSupportEndpointTypes = make(map[string][]constant.EndpointType)
98 for model, endpoints := range modelSupportEndpointsStr {
99 supportedEndpoints := make([]constant.EndpointType, 0)
100 for _, endpointStr := range endpoints {
101 endpointType := constant.EndpointType(endpointStr)
102 supportedEndpoints = append(supportedEndpoints, endpointType)
103 }
104 modelSupportEndpointTypes[model] = supportedEndpoints
105 }
106
107 pricingMap = make([]Pricing, 0)
108 for model, groups := range modelGroupsMap {
109 pricing := Pricing{
110 ModelName: model,
111 EnableGroup: groups.Items(),
112 SupportedEndpointTypes: modelSupportEndpointTypes[model],
113 }
114 modelPrice, findPrice := ratio_setting.GetModelPrice(model, false)
115 if findPrice {
116 pricing.ModelPrice = modelPrice
117 pricing.QuotaType = 1
118 } else {

Callers 1

GetPricingFunction · 0.85

Calls 10

SysErrorFunction · 0.92
StringsContainsFunction · 0.92
EndpointTypeTypeAlias · 0.92
GetModelPriceFunction · 0.92
GetModelRatioFunction · 0.92
GetCompletionRatioFunction · 0.92
AddMethod · 0.80
ItemsMethod · 0.80

Tested by

no test coverage detected