Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +10 -18
static/index.html
CHANGED
|
@@ -80,9 +80,9 @@
|
|
| 80 |
}
|
| 81 |
|
| 82 |
// OpenAI API Call for private mode
|
| 83 |
-
async function callOpenAI(prompt) {
|
| 84 |
console.log('prompt:', prompt)
|
| 85 |
-
|
| 86 |
// Récupérer la clé API depuis l'input
|
| 87 |
const apiKey = document.getElementById('apiKey').value.trim();
|
| 88 |
if (!apiKey) {
|
|
@@ -97,14 +97,13 @@
|
|
| 97 |
'Authorization': `Bearer ${apiKey}`
|
| 98 |
},
|
| 99 |
body: JSON.stringify({
|
| 100 |
-
model:
|
| 101 |
messages: [
|
| 102 |
{
|
| 103 |
role: 'user',
|
| 104 |
content: prompt
|
| 105 |
}
|
| 106 |
-
]
|
| 107 |
-
temperature: 0.7
|
| 108 |
})
|
| 109 |
});
|
| 110 |
|
|
@@ -134,23 +133,16 @@
|
|
| 134 |
addLog('Connexion WebSocket établie.');
|
| 135 |
};
|
| 136 |
|
| 137 |
-
// CORRECTION PRINCIPALE : Rendre onmessage async et ajouter gestion d'erreur
|
| 138 |
ws.onmessage = async function(event) {
|
| 139 |
-
const messageFromServer = event.data;
|
| 140 |
-
console.log(`Message reçu du serveur : "${messageFromServer}"`)
|
| 141 |
-
addLog(`Message reçu du serveur : "${messageFromServer}"`);
|
| 142 |
-
|
| 143 |
try {
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
return;
|
| 148 |
-
}
|
| 149 |
|
| 150 |
-
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
-
const responsePhrase = await callOpenAI(messageFromServer);
|
| 154 |
|
| 155 |
// Vérifier à nouveau que la connexion est ouverte
|
| 156 |
if (ws.readyState === WebSocket.OPEN) {
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
// OpenAI API Call for private mode
|
| 83 |
+
async function callOpenAI(prompt, model = 'gemini-2.5-pro') {
|
| 84 |
console.log('prompt:', prompt)
|
| 85 |
+
console.log('model:', model)
|
| 86 |
// Récupérer la clé API depuis l'input
|
| 87 |
const apiKey = document.getElementById('apiKey').value.trim();
|
| 88 |
if (!apiKey) {
|
|
|
|
| 97 |
'Authorization': `Bearer ${apiKey}`
|
| 98 |
},
|
| 99 |
body: JSON.stringify({
|
| 100 |
+
model: model,
|
| 101 |
messages: [
|
| 102 |
{
|
| 103 |
role: 'user',
|
| 104 |
content: prompt
|
| 105 |
}
|
| 106 |
+
]
|
|
|
|
| 107 |
})
|
| 108 |
});
|
| 109 |
|
|
|
|
| 133 |
addLog('Connexion WebSocket établie.');
|
| 134 |
};
|
| 135 |
|
|
|
|
| 136 |
ws.onmessage = async function(event) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
try {
|
| 138 |
+
const messageData = JSON.parse(event.data);
|
| 139 |
+
const prompt = messageData.prompt;
|
| 140 |
+
const model = messageData.model;
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
console.log(`Message reçu - Prompt: "${prompt}", Modèle: "${model}"`);
|
| 143 |
+
addLog(`Message reçu - Prompt: "${prompt}", Modèle: "${model}"`);
|
| 144 |
|
| 145 |
+
const responsePhrase = await callOpenAI(prompt, model);
|
|
|
|
| 146 |
|
| 147 |
// Vérifier à nouveau que la connexion est ouverte
|
| 148 |
if (ws.readyState === WebSocket.OPEN) {
|