Luca448 commited on
Commit
d4f2673
·
1 Parent(s): 48ab613

Savestate: Route image intent and fallback to the user-selected model instead of hardcoding gemini-2.5-flash to prevent API limit clashes

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. src/ai/router.js +5 -4
index.html CHANGED
@@ -65,7 +65,7 @@
65
  </head>
66
  <body class="dark-theme in-chat-view">
67
 
68
- <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.186</div>
69
 
70
  <!-- SVG Filters for Liquid Glass Refraction -->
71
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
 
65
  </head>
66
  <body class="dark-theme in-chat-view">
67
 
68
+ <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.187</div>
69
 
70
  <!-- SVG Filters for Liquid Glass Refraction -->
71
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/ai/router.js CHANGED
@@ -61,7 +61,8 @@ export class AIRouter {
61
  const apiKey = db.getSetting('gemini_api_key');
62
  if (apiKey) {
63
  const imageIntentPrompt = `Der Nutzer fragt: "${prompt}".\nErfordert diese Frage zwingend ein generiertes Bild zur visuellen Erklärung oder wurde explizit ein Bild angefragt (z.B. Arbeitsblätter, Diagramme, Szenen)?\nWenn ja, antworte NUR mit dem passenden englischen Midjourney/Flux Bild-Prompt (max 30 Wörter). Wenn nein, antworte NUR mit NEIN.`;
64
- const imageIntent = await gemini.generateContent(imageIntentPrompt, 'gemini-2.5-flash', apiKey);
 
65
  if (imageIntent && !imageIntent.trim().toUpperCase().startsWith('NEIN')) {
66
  const imagePromptText = imageIntent.trim();
67
  if (onStatus) onStatus('Generiere visuelle Unterstützung...');
@@ -109,12 +110,12 @@ export class AIRouter {
109
  return await gemini.generateContent(prompt, modelStr, apiKey, systemInstruction, history, {}, onStatus, options.attachments || [], options.abortSignal);
110
  } catch (apiError) {
111
  if (apiError.message.includes('503') || apiError.message.includes('500') || apiError.message.includes('404')) {
112
- console.warn(`Modell ${modelStr} ist nicht verfügbar oder überlastet. Fallback auf gemini-2.5-flash...`);
113
  // Add a small note to the output so the user knows a fallback happened
114
- const fallbackText = await gemini.generateContent(prompt, 'gemini-2.5-flash', apiKey, systemInstruction, history);
115
  if (typeof window !== 'undefined') {
116
  window.dispatchEvent(new CustomEvent('ai-fallback', {
117
- detail: { originalModel: modelStr, fallbackModel: 'gemini-2.5-flash' }
118
  }));
119
  }
120
  return fallbackText;
 
61
  const apiKey = db.getSetting('gemini_api_key');
62
  if (apiKey) {
63
  const imageIntentPrompt = `Der Nutzer fragt: "${prompt}".\nErfordert diese Frage zwingend ein generiertes Bild zur visuellen Erklärung oder wurde explizit ein Bild angefragt (z.B. Arbeitsblätter, Diagramme, Szenen)?\nWenn ja, antworte NUR mit dem passenden englischen Midjourney/Flux Bild-Prompt (max 30 Wörter). Wenn nein, antworte NUR mit NEIN.`;
64
+ const intentModel = modelStr && modelStr.startsWith('gemini') ? modelStr : 'gemini-3.5-flash';
65
+ const imageIntent = await gemini.generateContent(imageIntentPrompt, intentModel, apiKey);
66
  if (imageIntent && !imageIntent.trim().toUpperCase().startsWith('NEIN')) {
67
  const imagePromptText = imageIntent.trim();
68
  if (onStatus) onStatus('Generiere visuelle Unterstützung...');
 
110
  return await gemini.generateContent(prompt, modelStr, apiKey, systemInstruction, history, {}, onStatus, options.attachments || [], options.abortSignal);
111
  } catch (apiError) {
112
  if (apiError.message.includes('503') || apiError.message.includes('500') || apiError.message.includes('404')) {
113
+ console.warn(`Modell ${modelStr} ist nicht verfügbar oder überlastet. Fallback auf gemini-3.5-flash...`);
114
  // Add a small note to the output so the user knows a fallback happened
115
+ const fallbackText = await gemini.generateContent(prompt, 'gemini-3.5-flash', apiKey, systemInstruction, history);
116
  if (typeof window !== 'undefined') {
117
  window.dispatchEvent(new CustomEvent('ai-fallback', {
118
+ detail: { originalModel: modelStr, fallbackModel: 'gemini-3.5-flash' }
119
  }));
120
  }
121
  return fallbackText;