Skip to content

Commit d04fe17

Browse files
committed
ai: enable manual model selection + added deepseek & llama free models; remove forced model override
1 parent c27b0b3 commit d04fe17

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

src/lib/components/panels/GuardianPanel.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
// OpenRouter model selection (dynamic; fallback list shown until fetched)
2525
let modelList: string[] = [
2626
'openai/gpt-oss-120b:free',
27-
'openai/gpt-oss-20b:free',
27+
'deepseek/deepseek-chat-v3.1:free',
28+
'deepseek/deepseek-r1:free',
29+
'meta-llama/llama-3.3-70b-instruct:free',
2830
'mistralai/mixtral-8x7b-instruct:free',
2931
'google/gemma-2-9b-it:free',
3032
'openchat/openchat-7b:free',

src/lib/stores/guardian.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ export const guardianHelpers = {
6868
// Update API key specifically
6969
updateApiKey(apiKey: string) {
7070
guardianStore.update((current) => {
71+
const preservedModel = current.model || 'openai/gpt-oss-120b:free';
7172
const updated = {
7273
...current,
7374
apiKey,
7475
apiKeyValid: true,
75-
model: 'openai/gpt-oss-120b:free',
76+
model: preservedModel,
7677
};
7778
this.save(updated);
7879
return updated;

src/lib/stores/ruixen.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ class Ruixen {
124124
constructor() {
125125
guardianStore.subscribe((g) => {
126126
this.apiKey = g.apiKey || '';
127-
// Hard-enforce free model to avoid non-free calls
128-
this.model = 'openai/gpt-oss-120b:free';
127+
this.model = g.model || 'openai/gpt-oss-120b:free';
129128
this.analyzer = g.apiKey && g.apiKeyValid ? new AIAnalyzer(g.apiKey, this.model) : null;
130129
});
131130
}
@@ -175,12 +174,7 @@ class Ruixen {
175174

176175
async analyzeWeeklyCloud(pet: PetPanelData): Promise<string | null> {
177176
if (!this.analyzer) return null;
178-
try {
179-
return await this.analyzer.analyzeWeeklySummary(pet);
180-
} catch (e) {
181-
console.error('Weekly cloud analysis failed:', e);
182-
return null;
183-
}
177+
return this.tryWeeklyModelsSequentially(pet);
184178
}
185179

186180
private runQueue() {
@@ -292,6 +286,7 @@ class Ruixen {
292286
healthConcerns: concerns,
293287
recommendations: recs,
294288
nextCheckupSuggestion: undefined,
289+
modelUsed: 'offline',
295290
};
296291
}
297292

@@ -414,11 +409,17 @@ class Ruixen {
414409
} catch (e) {
415410
const msg = String((e as Error)?.message || e);
416411
const is429 = /429|Rate limit exceeded/i.test(msg);
412+
const providerUpstream = /temporarily rate-limited upstream/i.test(msg);
417413
if (!is429) {
418414
console.warn('Model attempt failed (non-429), aborting fallbacks:', model, e);
419415
return this.offlineHeuristic(pet, entry);
420416
}
421-
console.warn('Model rate-limited, trying next free model:', model);
417+
console.warn(
418+
providerUpstream
419+
? 'Model upstream-limited, trying next free model:'
420+
: 'Model rate-limited, trying next free model:',
421+
model
422+
);
422423
if (i === this.fallbackModels.length - 1) {
423424
const today = new Date().toDateString();
424425
setExhausted(today);
@@ -430,6 +431,32 @@ class Ruixen {
430431
}
431432
return this.offlineHeuristic(pet, entry);
432433
}
434+
435+
private async tryWeeklyModelsSequentially(pet: PetPanelData): Promise<string | null> {
436+
if (!this.analyzer) return null;
437+
for (let i = 0; i < this.fallbackModels.length; i++) {
438+
const model = this.fallbackModels[i];
439+
try {
440+
const text = await this.analyzer.analyzeWeeklySummary(pet, model);
441+
return `(${model})\n${text}`;
442+
} catch (e) {
443+
const msg = String((e as Error)?.message || e);
444+
const is429 = /429|Rate limit exceeded/i.test(msg);
445+
if (!is429) {
446+
console.warn('Weekly model failed (non-429), aborting fallbacks:', model, e);
447+
return null;
448+
}
449+
if (i === this.fallbackModels.length - 1) {
450+
const today = new Date().toDateString();
451+
setExhausted(today);
452+
saveDailyCount({ date: today, count: DAILY_FREE_LIMIT });
453+
this.dailyUsage.set(DAILY_FREE_LIMIT);
454+
return null;
455+
}
456+
}
457+
}
458+
return null;
459+
}
433460
}
434461

435462
export const ruixen = new Ruixen();
@@ -444,6 +471,10 @@ export const ruixenHelpers = {
444471
analyzeWeeklyCloud(pet: PetPanelData) {
445472
return ruixen.analyzeWeeklyCloud(pet);
446473
},
474+
setModel(model: string) {
475+
guardianStore.update((g) => ({ ...g, model } as any));
476+
return model;
477+
},
447478
weeklySummary(pet: PetPanelData) {
448479
return ruixen.weeklySummary(pet);
449480
},

0 commit comments

Comments
 (0)