Luca448 commited on
Commit
f01fdf1
·
1 Parent(s): b627339

Savestate: Add ZDR and OpenRouter specific routing for DeepSeek models

Browse files
Files changed (3) hide show
  1. index.html +1 -1
  2. src/ai/openai-client.js +10 -7
  3. src/ai/router.js +15 -1
index.html CHANGED
@@ -74,7 +74,7 @@
74
  </head>
75
  <body class="dark-theme in-chat-view" style="visibility: hidden;">
76
 
77
- <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.326</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
 
74
  </head>
75
  <body class="dark-theme in-chat-view" style="visibility: hidden;">
76
 
77
+ <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.327</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/ai/openai-client.js CHANGED
@@ -1,5 +1,5 @@
1
  export class OpenAIClient {
2
- async generateContent(prompt, model, apiKey, systemInstruction, baseUrl, history = []) {
3
  if (!apiKey) throw new Error("API Key fehlt.");
4
 
5
  let messages = [];
@@ -39,6 +39,14 @@ export class OpenAIClient {
39
  messages.push({ role: 'user', content: prompt });
40
  }
41
 
 
 
 
 
 
 
 
 
42
  const response = await fetch(baseUrl, {
43
  method: 'POST',
44
  headers: {
@@ -47,12 +55,7 @@ export class OpenAIClient {
47
  'HTTP-Referer': 'http://localhost:5173', // specific for OpenRouter
48
  'X-Title': 'SchoolMind AI' // specific for OpenRouter
49
  },
50
- body: JSON.stringify({
51
- model: model,
52
- messages: messages,
53
- temperature: 0.7,
54
- max_tokens: 2000
55
- })
56
  });
57
 
58
  if (!response.ok) {
 
1
  export class OpenAIClient {
2
+ async generateContent(prompt, model, apiKey, systemInstruction, baseUrl, history = [], extraBody = {}) {
3
  if (!apiKey) throw new Error("API Key fehlt.");
4
 
5
  let messages = [];
 
39
  messages.push({ role: 'user', content: prompt });
40
  }
41
 
42
+ const body = {
43
+ model: model,
44
+ messages: messages,
45
+ temperature: 0.7,
46
+ max_tokens: 2000,
47
+ ...extraBody
48
+ };
49
+
50
  const response = await fetch(baseUrl, {
51
  method: 'POST',
52
  headers: {
 
55
  'HTTP-Referer': 'http://localhost:5173', // specific for OpenRouter
56
  'X-Title': 'SchoolMind AI' // specific for OpenRouter
57
  },
58
+ body: JSON.stringify(body)
 
 
 
 
 
59
  });
60
 
61
  if (!response.ok) {
src/ai/router.js CHANGED
@@ -194,7 +194,21 @@ Wenn nein (z.B. simple Matheaufgabe, reine Textübersetzung, unwichtiges Thema),
194
  const apiKey = db.getSetting('openrouter_api_key');
195
  if (!apiKey) throw new Error("Kein OpenRouter API Key konfiguriert.");
196
  const modelName = modelStr.replace('openrouter-', '');
197
- responseText = await openAIClient.generateContent(prompt, modelName, apiKey, systemInstruction, 'https://openrouter.ai/api/v1/chat/completions', history);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  } else if (modelStr.startsWith('deepseek')) {
199
  const apiKey = db.getSetting('deepseek_api_key');
200
  if (!apiKey) throw new Error("Kein DeepSeek API Key konfiguriert.");
 
194
  const apiKey = db.getSetting('openrouter_api_key');
195
  if (!apiKey) throw new Error("Kein OpenRouter API Key konfiguriert.");
196
  const modelName = modelStr.replace('openrouter-', '');
197
+
198
+ let extraBody = {
199
+ provider: {
200
+ data_collection: "deny" // Zero Data Retention (ZDR)
201
+ }
202
+ };
203
+
204
+ if (modelName === 'deepseek/deepseek-v4-flash-latest') {
205
+ extraBody.provider.order = ["DeepInfra"];
206
+ } else if (modelName === 'deepseek/deepseek-v4-pro-latest') {
207
+ // Cheapest provider with cache input discount
208
+ extraBody.provider.sort = "price";
209
+ }
210
+
211
+ responseText = await openAIClient.generateContent(prompt, modelName, apiKey, systemInstruction, 'https://openrouter.ai/api/v1/chat/completions', history, extraBody);
212
  } else if (modelStr.startsWith('deepseek')) {
213
  const apiKey = db.getSetting('deepseek_api_key');
214
  if (!apiKey) throw new Error("Kein DeepSeek API Key konfiguriert.");