C2MV commited on
Commit
2d01ac4
Β·
verified Β·
1 Parent(s): c773a01

Upload lib/models.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. lib/models.ts +18 -36
lib/models.ts CHANGED
@@ -153,8 +153,9 @@ export function parseModelValue(value: string): { modelId: string; provider: str
153
  return { modelId: value.substring(0, lastColon), provider: value.substring(lastColon + 1) };
154
  }
155
 
156
- export function getModelLabel(value: string): string {
157
- for (const group of AI_MODELS) {
 
158
  for (const opt of group.options) {
159
  if (opt.value === value) return opt.label;
160
  }
@@ -192,47 +193,28 @@ export function formatTokens(tokens: number): string {
192
  }
193
 
194
  // ─── Merge synced models into the static list ───────────────────
 
 
195
 
196
  export function mergeModels(staticModels: ModelGroup[], syncedModels: ModelGroup[]): ModelGroup[] {
197
- // Precompute all values available in the live sync response
198
- const liveValues = new Set<string>();
199
  for (const group of syncedModels) {
200
- for (const opt of group.options) {
201
- liveValues.add(opt.value);
202
- }
203
  }
204
 
205
- // Clone static models, applying verification flags
206
- const result: ModelGroup[] = staticModels.map(g => {
207
- // Determine if this specific provider was successfully synced in this batch
208
- // (If a provider isn't in syncedModels at all, its API key might be missing, so we won't mark them as red blindly, just undefined.)
209
- const providerWasSynced = syncedModels.some(s => s.provider === g.provider);
210
-
211
- return {
212
- ...g,
213
- options: g.options.map(opt => ({
214
- ...opt,
215
- verified: providerWasSynced ? liveValues.has(opt.value) : undefined
216
- }))
217
- };
218
- });
219
-
220
- const seenValues = new Set<string>();
221
- for (const g of result) {
222
- for (const opt of g.options) seenValues.add(opt.value);
223
- }
224
 
225
- // Add any new models discovered from the sync that were not in static
226
- for (const synced of syncedModels) {
227
- const existing = result.find(g => g.provider === synced.provider && g.label === synced.label);
228
- const newOpts = synced.options.filter(o => !seenValues.has(o.value)).map(o => ({ ...o, verified: true }));
229
- newOpts.forEach(o => seenValues.add(o.value));
230
-
231
- if (existing) {
232
- existing.options.push(...newOpts);
233
- } else if (newOpts.length > 0) {
234
- result.push({ ...synced, options: newOpts });
235
  }
236
  }
 
 
 
 
 
 
237
  return result;
238
  }
 
153
  return { modelId: value.substring(0, lastColon), provider: value.substring(lastColon + 1) };
154
  }
155
 
156
+ export function getModelLabel(value: string, allModels?: ModelGroup[]): string {
157
+ const searchGroups = allModels || AI_MODELS;
158
+ for (const group of searchGroups) {
159
  for (const opt of group.options) {
160
  if (opt.value === value) return opt.label;
161
  }
 
193
  }
194
 
195
  // ─── Merge synced models into the static list ───────────────────
196
+ // Strategy: For providers that were synced, use ONLY synced models.
197
+ // For providers without sync (azure, anthropic, huggingface, modal), keep static models.
198
 
199
  export function mergeModels(staticModels: ModelGroup[], syncedModels: ModelGroup[]): ModelGroup[] {
200
+ const syncedProviders = new Set<string>();
 
201
  for (const group of syncedModels) {
202
+ syncedProviders.add(group.provider);
 
 
203
  }
204
 
205
+ const result: ModelGroup[] = [];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
 
207
+ // Keep static models ONLY for providers that were NOT synced
208
+ for (const group of staticModels) {
209
+ if (!syncedProviders.has(group.provider)) {
210
+ result.push(group);
 
 
 
 
 
 
211
  }
212
  }
213
+
214
+ // Add all synced groups (these replace the static ones for their provider)
215
+ for (const group of syncedModels) {
216
+ result.push({ ...group, options: group.options.map(o => ({ ...o, verified: true })) });
217
+ }
218
+
219
  return result;
220
  }