Spaces:
Running
Running
tmgdlof commited on
Commit ·
da7d934
1
Parent(s): edb87bf
Update AI assistant to use OpenAI and support multiple API keys
Browse filesReplace Puter.js AI with OpenAI API integration in assistant and developer tools, enabling multi-key rotation and streaming responses.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 11305e0b-1f7f-4c74-8f4e-3202abfc6ecc
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: d13a69d4-0298-464c-85f0-6e1f8d7c1257
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6bad4f2d-41a1-4455-a72d-85e59438c6af/11305e0b-1f7f-4c74-8f4e-3202abfc6ecc/Nb3xGTK
Replit-Helium-Checkpoint-Created: true
- dev-assistant.html +49 -30
- replit.md +2 -2
- requirements.txt +1 -0
dev-assistant.html
CHANGED
|
@@ -1133,23 +1133,31 @@
|
|
| 1133 |
fynBalance = chargeData.newBalance;
|
| 1134 |
document.getElementById('fynBalance').textContent = Math.floor(fynBalance);
|
| 1135 |
|
| 1136 |
-
const response = await
|
| 1137 |
-
|
| 1138 |
-
|
| 1139 |
-
|
| 1140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1141 |
|
| 1142 |
-
|
| 1143 |
-
1. Syntax errors
|
| 1144 |
-
2. Logic bugs
|
| 1145 |
-
3. Security issues
|
| 1146 |
-
4. Performance problems
|
| 1147 |
-
5. Best practice violations
|
| 1148 |
|
| 1149 |
-
|
|
|
|
|
|
|
| 1150 |
|
| 1151 |
-
|
| 1152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1153 |
} catch(e) {
|
| 1154 |
hideTypingIndicator();
|
| 1155 |
addAIMessage('assistant', `Error: ${e.message}. Make sure you're signed in to use AI features.`);
|
|
@@ -1222,25 +1230,36 @@ Provide fixes for each issue found.`);
|
|
| 1222 |
fynBalance = chargeData.newBalance;
|
| 1223 |
document.getElementById('fynBalance').textContent = Math.floor(fynBalance);
|
| 1224 |
|
| 1225 |
-
const response = await
|
| 1226 |
-
|
| 1227 |
-
|
| 1228 |
-
|
| 1229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1230 |
|
| 1231 |
-
|
| 1232 |
|
| 1233 |
-
|
| 1234 |
-
|
|
|
|
| 1235 |
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
}
|
| 1245 |
} catch(e) {
|
| 1246 |
hideTypingIndicator();
|
|
|
|
| 1133 |
fynBalance = chargeData.newBalance;
|
| 1134 |
document.getElementById('fynBalance').textContent = Math.floor(fynBalance);
|
| 1135 |
|
| 1136 |
+
const response = await fetch('/api/ai/chat', {
|
| 1137 |
+
method: 'POST',
|
| 1138 |
+
headers: { 'Content-Type': 'application/json' },
|
| 1139 |
+
body: JSON.stringify({
|
| 1140 |
+
messages: [
|
| 1141 |
+
{ role: 'system', content: 'You are a code review assistant. Analyze this code for bugs, errors, and improvements. Be specific about line numbers and file names.' },
|
| 1142 |
+
{ role: 'user', content: `App: ${selectedApp.name}\nFiles:\n${allCode}\n\nFind: 1. Syntax errors 2. Logic bugs 3. Security issues 4. Performance problems 5. Best practice violations\nProvide fixes for each issue found.` }
|
| 1143 |
+
],
|
| 1144 |
+
model: 'gpt-4o-mini'
|
| 1145 |
+
})
|
| 1146 |
+
});
|
| 1147 |
|
| 1148 |
+
if (!response.ok) throw new Error('AI analysis failed');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1149 |
|
| 1150 |
+
const reader = response.body.getReader();
|
| 1151 |
+
const decoder = new TextDecoder();
|
| 1152 |
+
let fullResponse = '';
|
| 1153 |
|
| 1154 |
+
while (true) {
|
| 1155 |
+
const { done, value } = await reader.read();
|
| 1156 |
+
if (done) break;
|
| 1157 |
+
fullResponse += decoder.decode(value);
|
| 1158 |
+
hideTypingIndicator(); // Only once or replace indicator with content
|
| 1159 |
+
addAIMessage('assistant', formatAIResponse(fullResponse));
|
| 1160 |
+
}
|
| 1161 |
} catch(e) {
|
| 1162 |
hideTypingIndicator();
|
| 1163 |
addAIMessage('assistant', `Error: ${e.message}. Make sure you're signed in to use AI features.`);
|
|
|
|
| 1230 |
fynBalance = chargeData.newBalance;
|
| 1231 |
document.getElementById('fynBalance').textContent = Math.floor(fynBalance);
|
| 1232 |
|
| 1233 |
+
const response = await fetch('/api/ai/chat', {
|
| 1234 |
+
method: 'POST',
|
| 1235 |
+
headers: { 'Content-Type': 'application/json' },
|
| 1236 |
+
body: JSON.stringify({
|
| 1237 |
+
messages: [
|
| 1238 |
+
{ role: 'system', content: 'You are LunAI, a helpful coding assistant.' },
|
| 1239 |
+
{ role: 'user', content: `Current file: ${filename}\nCode:\n${code}\n\nUser request: ${message}\n\nIf suggesting code changes, format them clearly with the corrected code in a code block. If this is a bug fix, explain what was wrong and provide the fixed code.` }
|
| 1240 |
+
],
|
| 1241 |
+
model: 'gpt-4o-mini'
|
| 1242 |
+
})
|
| 1243 |
+
});
|
| 1244 |
|
| 1245 |
+
if (!response.ok) throw new Error('AI request failed');
|
| 1246 |
|
| 1247 |
+
const reader = response.body.getReader();
|
| 1248 |
+
const decoder = new TextDecoder();
|
| 1249 |
+
let fullResponse = '';
|
| 1250 |
|
| 1251 |
+
while (true) {
|
| 1252 |
+
const { done, value } = await reader.read();
|
| 1253 |
+
if (done) break;
|
| 1254 |
+
fullResponse += decoder.decode(value);
|
| 1255 |
+
hideTypingIndicator();
|
| 1256 |
+
|
| 1257 |
+
const formattedResponse = formatAIResponse(fullResponse);
|
| 1258 |
+
if (isBugFix && code) {
|
| 1259 |
+
addAIMessageWithFix(formattedResponse, fullResponse);
|
| 1260 |
+
} else {
|
| 1261 |
+
addAIMessage('assistant', formattedResponse);
|
| 1262 |
+
}
|
| 1263 |
}
|
| 1264 |
} catch(e) {
|
| 1265 |
hideTypingIndicator();
|
replit.md
CHANGED
|
@@ -28,8 +28,8 @@ The emulator is built as a single `index.html` file, containing all HTML, CSS, a
|
|
| 28 |
- **LunOS Account System (LunID)**: First-party account system with secure authentication (PBKDF2-SHA256, JWT), session management, auto-login, and cloud sync for data (emails, documents, calendar, notes, files).
|
| 29 |
- **Stream App**: Video streaming application with a custom player, multi-service support (YouTube, Dailymotion, PeerTube), unified feed, discover/clips/trending tabs, collections, and search.
|
| 30 |
- **FynPay (Internal Wallet App)**: Internal platform currency (FYN) for LunOS, with wallet management, send/receive, earning/spending sections, and developer mode protection via Ed25519 cryptographic signatures.
|
| 31 |
-
- **FynNX Assistant**: AI-powered assistant using
|
| 32 |
-
- **LunAI Developer (dev-assistant.html)**: AI-powered bug fixer and code assistant using
|
| 33 |
|
| 34 |
**Real Browser API Integrations**:
|
| 35 |
- Battery API, Network Information API, Geolocation API, Notifications API, Web Audio API, Vibration API, Storage API, Web Bluetooth API, Screen Wake Lock API, Device Motion/Orientation API, Fullscreen API, Web Share API, Picture-in-Picture API, Gamepad API, Clipboard API, Screen Orientation API.
|
|
|
|
| 28 |
- **LunOS Account System (LunID)**: First-party account system with secure authentication (PBKDF2-SHA256, JWT), session management, auto-login, and cloud sync for data (emails, documents, calendar, notes, files).
|
| 29 |
- **Stream App**: Video streaming application with a custom player, multi-service support (YouTube, Dailymotion, PeerTube), unified feed, discover/clips/trending tabs, collections, and search.
|
| 30 |
- **FynPay (Internal Wallet App)**: Internal platform currency (FYN) for LunOS, with wallet management, send/receive, earning/spending sections, and developer mode protection via Ed25519 cryptographic signatures.
|
| 31 |
+
- **FynNX Assistant**: AI-powered assistant using OpenAI API with multi-key rotation and gpt-4o-mini, featuring chat interface, web/image search, app launcher, command system, voice input (SpeechRecognition API) and text-to-speech (Web Speech API), integration with Nexa browser for searches.
|
| 32 |
+
- **LunAI Developer (dev-assistant.html)**: AI-powered bug fixer and code assistant using OpenAI API. Features include: bug analysis and auto-fix, code explanation, refactoring suggestions, comment generation, cloud file storage, multi-key rotation, side-by-side code comparison, and example code with intentional bugs for testing.
|
| 33 |
|
| 34 |
**Real Browser API Integrations**:
|
| 35 |
- Battery API, Network Information API, Geolocation API, Notifications API, Web Audio API, Vibration API, Storage API, Web Bluetooth API, Screen Wake Lock API, Device Motion/Orientation API, Fullscreen API, Web Share API, Picture-in-Picture API, Gamepad API, Clipboard API, Screen Orientation API.
|
requirements.txt
CHANGED
|
@@ -16,3 +16,4 @@ huggingface_hub
|
|
| 16 |
pandas
|
| 17 |
pyarrow
|
| 18 |
openai
|
|
|
|
|
|
| 16 |
pandas
|
| 17 |
pyarrow
|
| 18 |
openai
|
| 19 |
+
openai
|