Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -46,21 +46,28 @@ form.onsubmit = async (e) => {
|
|
46 |
e.preventDefault();
|
47 |
const msg = input.value.trim();
|
48 |
if (!msg) return;
|
49 |
-
|
50 |
addBubble(msg, 'user');
|
51 |
input.value = '';
|
52 |
|
53 |
try {
|
54 |
-
const
|
55 |
method: 'POST',
|
56 |
headers: { 'Content-Type': 'application/json' },
|
57 |
body: JSON.stringify({ message: msg })
|
58 |
});
|
59 |
-
const { text, audio_url } = await response.json();
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
streamText(text, () => {
|
62 |
if (audio_url) playAudio(audio_url);
|
63 |
});
|
|
|
64 |
} catch (err) {
|
65 |
streamText("❌ SHODAN encountered an error.", null);
|
66 |
console.error(err);
|
|
|
46 |
e.preventDefault();
|
47 |
const msg = input.value.trim();
|
48 |
if (!msg) return;
|
|
|
49 |
addBubble(msg, 'user');
|
50 |
input.value = '';
|
51 |
|
52 |
try {
|
53 |
+
const res = await fetch('/chat', {
|
54 |
method: 'POST',
|
55 |
headers: { 'Content-Type': 'application/json' },
|
56 |
body: JSON.stringify({ message: msg })
|
57 |
});
|
|
|
58 |
|
59 |
+
if (!res.ok) {
|
60 |
+
// log the actual payload for debugging:
|
61 |
+
const text = await res.text();
|
62 |
+
console.error('Chat error:', res.status, text);
|
63 |
+
throw new Error(`Status ${res.status}`);
|
64 |
+
}
|
65 |
+
|
66 |
+
const { response: text, audio_url } = await res.json();
|
67 |
streamText(text, () => {
|
68 |
if (audio_url) playAudio(audio_url);
|
69 |
});
|
70 |
+
|
71 |
} catch (err) {
|
72 |
streamText("❌ SHODAN encountered an error.", null);
|
73 |
console.error(err);
|