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

Function buildDifferences

controller/ratio_sync.go:271–445  ·  view source on GitHub ↗
(localData map[string]any, successfulChannels []struct {
    name string
    data map[string]any
})

Source from the content-addressed store, hash-verified

269}
270
271func buildDifferences(localData map[string]any, successfulChannels []struct {
272 name string
273 data map[string]any
274}) map[string]map[string]dto.DifferenceItem {
275 differences := make(map[string]map[string]dto.DifferenceItem)
276
277 allModels := make(map[string]struct{})
278
279 for _, ratioType := range ratioTypes {
280 if localRatioAny, ok := localData[ratioType]; ok {
281 if localRatio, ok := localRatioAny.(map[string]float64); ok {
282 for modelName := range localRatio {
283 allModels[modelName] = struct{}{}
284 }
285 }
286 }
287 }
288
289 for _, channel := range successfulChannels {
290 for _, ratioType := range ratioTypes {
291 if upstreamRatio, ok := channel.data[ratioType].(map[string]any); ok {
292 for modelName := range upstreamRatio {
293 allModels[modelName] = struct{}{}
294 }
295 }
296 }
297 }
298
299 confidenceMap := make(map[string]map[string]bool)
300
301 // 预处理阶段:检查pricing接口的可信度
302 for _, channel := range successfulChannels {
303 confidenceMap[channel.name] = make(map[string]bool)
304
305 modelRatios, hasModelRatio := channel.data["model_ratio"].(map[string]any)
306 completionRatios, hasCompletionRatio := channel.data["completion_ratio"].(map[string]any)
307
308 if hasModelRatio && hasCompletionRatio {
309 // 遍历所有模型,检查是否满足不可信条件
310 for modelName := range allModels {
311 // 默认为可信
312 confidenceMap[channel.name][modelName] = true
313
314 // 检查是否满足不可信条件:model_ratio为37.5且completion_ratio为1
315 if modelRatioVal, ok := modelRatios[modelName]; ok {
316 if completionRatioVal, ok := completionRatios[modelName]; ok {
317 // 转换为float64进行比较
318 if modelRatioFloat, ok := modelRatioVal.(float64); ok {
319 if completionRatioFloat, ok := completionRatioVal.(float64); ok {
320 if modelRatioFloat == 37.5 && completionRatioFloat == 1.0 {
321 confidenceMap[channel.name][modelName] = false
322 }
323 }
324 }
325 }
326 }
327 }
328 } else {

Callers 1

FetchUpstreamRatiosFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected