MCPcopy Index your code
hub / github.com/Doorman11991/smallcode / selectModel

Method selectModel

src/model/adaptive_router.js:68–103  ·  view source on GitHub ↗

* Select the best model given current failure rates. * Returns the strong or medium model if the primary has poor reliability. * * Thresholds: * > 0.6 failure rate → use SMALLCODE_MODEL_STRONG (if set) * > 0.3 failure rate → use SMALLCODE_MODEL_MEDIUM (if set) * otherwise

(config)

Source from the content-addressed store, hash-verified

66 * @returns {{ model: string, url: string }}
67 */
68 selectModel(config) {
69 const primaryModel = config?.model?.name || '';
70 const primaryUrl = config?.model?.baseUrl || '';
71
72 if (!primaryModel) return { model: primaryModel, url: primaryUrl };
73
74 const entry = this.failureRates.get(primaryModel);
75 // Not enough data yet — use primary
76 if (!entry || entry.calls < 3) return { model: primaryModel, url: primaryUrl };
77
78 const rate = entry.fails / entry.calls;
79
80 if (rate > 0.6) {
81 const strong = config?.models?.strong?.name || process.env.SMALLCODE_MODEL_STRONG;
82 if (strong && strong !== primaryModel) {
83 return {
84 model: strong,
85 url: config?.models?.strong?.baseUrl || process.env.SMALLCODE_BASE_URL_STRONG || primaryUrl,
86 tier: 'strong',
87 };
88 }
89 }
90
91 if (rate > 0.3) {
92 const medium = config?.models?.medium?.name || process.env.SMALLCODE_MODEL_MEDIUM;
93 if (medium && medium !== primaryModel) {
94 return {
95 model: medium,
96 url: config?.models?.medium?.baseUrl || process.env.SMALLCODE_BASE_URL_MEDIUM || primaryUrl,
97 tier: 'medium',
98 };
99 }
100 }
101
102 return { model: primaryModel, url: primaryUrl };
103 }
104
105 /**
106 * Reset all tracked failure rates (called on new agent session or test runs).

Callers 2

chatCompletionFunction · 0.80

Calls 1

getMethod · 0.65

Tested by

no test coverage detected