MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / DiffOpenAICompatibility

Function DiffOpenAICompatibility

internal/watcher/diff/openai_compat.go:14–61  ·  view source on GitHub ↗

DiffOpenAICompatibility produces human-readable change descriptions.

(oldList, newList []config.OpenAICompatibility)

Source from the content-addressed store, hash-verified

12
13// DiffOpenAICompatibility produces human-readable change descriptions.
14func DiffOpenAICompatibility(oldList, newList []config.OpenAICompatibility) []string {
15 changes := make([]string, 0)
16 oldMap := make(map[string]config.OpenAICompatibility, len(oldList))
17 oldLabels := make(map[string]string, len(oldList))
18 for idx, entry := range oldList {
19 key, label := openAICompatKey(entry, idx)
20 oldMap[key] = entry
21 oldLabels[key] = label
22 }
23 newMap := make(map[string]config.OpenAICompatibility, len(newList))
24 newLabels := make(map[string]string, len(newList))
25 for idx, entry := range newList {
26 key, label := openAICompatKey(entry, idx)
27 newMap[key] = entry
28 newLabels[key] = label
29 }
30 keySet := make(map[string]struct{}, len(oldMap)+len(newMap))
31 for key := range oldMap {
32 keySet[key] = struct{}{}
33 }
34 for key := range newMap {
35 keySet[key] = struct{}{}
36 }
37 orderedKeys := make([]string, 0, len(keySet))
38 for key := range keySet {
39 orderedKeys = append(orderedKeys, key)
40 }
41 sort.Strings(orderedKeys)
42 for _, key := range orderedKeys {
43 oldEntry, oldOk := oldMap[key]
44 newEntry, newOk := newMap[key]
45 label := oldLabels[key]
46 if label == "" {
47 label = newLabels[key]
48 }
49 switch {
50 case !oldOk:
51 changes = append(changes, fmt.Sprintf("provider added: %s (api-keys=%d, models=%d)", label, countAPIKeys(newEntry), countOpenAIModels(newEntry.Models)))
52 case !newOk:
53 changes = append(changes, fmt.Sprintf("provider removed: %s (api-keys=%d, models=%d)", label, countAPIKeys(oldEntry), countOpenAIModels(oldEntry.Models)))
54 default:
55 if detail := describeOpenAICompatibilityUpdate(oldEntry, newEntry); detail != "" {
56 changes = append(changes, fmt.Sprintf("provider updated: %s %s", label, detail))
57 }
58 }
59 }
60 return changes
61}
62
63func describeOpenAICompatibilityUpdate(oldEntry, newEntry config.OpenAICompatibility) string {
64 oldKeyCount := countAPIKeys(oldEntry)

Calls 4

openAICompatKeyFunction · 0.85
countAPIKeysFunction · 0.85
countOpenAIModelsFunction · 0.85