Luca448 commited on
Commit
5b4dc91
·
1 Parent(s): 6cfa424

Savestate: Add Vision API support to openAIClient.js to allow OpenRouter models to see images

Browse files
Files changed (2) hide show
  1. index.html +1 -1
  2. src/ai/openai-client.js +22 -1
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.208</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.209</div>
69
 
70
  <!-- SVG Filters for Liquid Glass Refraction -->
71
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/ai/openai-client.js CHANGED
@@ -16,7 +16,28 @@ export class OpenAIClient {
16
  });
17
  }
18
 
19
- messages.push({ role: 'user', content: prompt });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  const response = await fetch(baseUrl, {
22
  method: 'POST',
 
16
  });
17
  }
18
 
19
+ if (prompt.includes('![') && prompt.includes('](data:image/')) {
20
+ const contentArray = [];
21
+ let textPart = prompt;
22
+
23
+ // Extract all images
24
+ const imgRegex = /!\[.*?\]\((data:image\/[^;]+;base64,[^)]+)\)/g;
25
+ let match;
26
+ while ((match = imgRegex.exec(prompt)) !== null) {
27
+ contentArray.push({
28
+ type: "image_url",
29
+ image_url: { url: match[1] }
30
+ });
31
+ textPart = textPart.replace(match[0], '');
32
+ }
33
+
34
+ if (textPart.trim()) {
35
+ contentArray.unshift({ type: "text", text: textPart.trim() });
36
+ }
37
+ messages.push({ role: 'user', content: contentArray });
38
+ } else {
39
+ messages.push({ role: 'user', content: prompt });
40
+ }
41
 
42
  const response = await fetch(baseUrl, {
43
  method: 'POST',