Luca448 Claude Sonnet 5 commited on
Commit
6615fc5
·
1 Parent(s): 8ee7a26

fix: pass client-chosen model/fallback chain through Notes proxy

Browse files

Proxy ignored the app's model selection and always routed to DeepSeek
via the cheapest provider, so switching models in the app UI had no
effect on the actual request. Now the chosen model and its fallback
chain (limited to the 6 allow-listed IDs) go to OpenRouter; price
stays the sort priority.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. server.js +20 -3
server.js CHANGED
@@ -202,11 +202,28 @@ app.post('/api/notes/chat/completions', async (req, res) => {
202
  Array.isArray(message.content) &&
203
  message.content.some((part) => part?.type === 'image_url'),
204
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  const models = process.env.NOTES_MODEL
206
  ? [process.env.NOTES_MODEL]
207
- : hasImage
208
- ? [NOTES_VISION_MODEL]
209
- : NOTES_TEXT_MODELS;
 
 
210
 
211
  try {
212
  const upstream = await fetch('https://openrouter.ai/api/v1/chat/completions', {
 
202
  Array.isArray(message.content) &&
203
  message.content.some((part) => part?.type === 'image_url'),
204
  );
205
+ // Die App schickt ihr gewähltes Modell samt Fallback-Kette mit. Nur freigegebene
206
+ // IDs durchlassen, damit niemand über den Proxy teure Modelle auf unsere Kosten ruft.
207
+ const NOTES_ALLOWED_MODELS = new Set([
208
+ 'google/gemini-3.8-flash',
209
+ 'google/gemini-3.7-flash',
210
+ 'google/gemini-3.6-flash',
211
+ 'google/gemini-3.5-flash-lite',
212
+ 'google/gemini-3.1-flash-lite',
213
+ 'deepseek/deepseek-v4-flash',
214
+ ]);
215
+ const requested = [req.body.model, ...(Array.isArray(req.body.models) ? req.body.models : [])]
216
+ .filter((id) => NOTES_ALLOWED_MODELS.has(id));
217
+ const clientModels = [...new Set(requested)].slice(0, 3);
218
+ // Gemini kann Bilder, DeepSeek V4 Flash nicht — dort bleibt das Vision-Modell.
219
+ const clientCanSee = clientModels.length > 0 && clientModels[0].startsWith('google/');
220
  const models = process.env.NOTES_MODEL
221
  ? [process.env.NOTES_MODEL]
222
+ : clientModels.length > 0 && (!hasImage || clientCanSee)
223
+ ? clientModels
224
+ : hasImage
225
+ ? [NOTES_VISION_MODEL]
226
+ : NOTES_TEXT_MODELS;
227
 
228
  try {
229
  const upstream = await fetch('https://openrouter.ai/api/v1/chat/completions', {