Spaces:
Sleeping
Sleeping
Update src/api.js
Browse files- src/api.js +26 -4
src/api.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
| 1 |
// src/api.js
|
| 2 |
|
|
|
|
| 3 |
export const API_BASE = "https://deepthoughtai-prolog-gateway.hf.space";
|
| 4 |
|
| 5 |
-
export async function
|
| 6 |
-
const res = await fetch(`${API_BASE}/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
method: "POST",
|
| 8 |
headers: {
|
| 9 |
"Content-Type": "application/json",
|
|
|
|
| 10 |
},
|
| 11 |
body: JSON.stringify({
|
| 12 |
-
message,
|
| 13 |
strict_mode: strictMode,
|
| 14 |
history,
|
| 15 |
}),
|
|
@@ -25,5 +47,5 @@ export async function sendChat(message, strictMode = true, history = []) {
|
|
| 25 |
throw new Error(json.error || "Chat failed");
|
| 26 |
}
|
| 27 |
|
| 28 |
-
return json;
|
| 29 |
}
|
|
|
|
| 1 |
// src/api.js
|
| 2 |
|
| 3 |
+
// src/api.js
|
| 4 |
export const API_BASE = "https://deepthoughtai-prolog-gateway.hf.space";
|
| 5 |
|
| 6 |
+
export async function login(username, password) {
|
| 7 |
+
const res = await fetch(`${API_BASE}/login`, {
|
| 8 |
+
method: "POST",
|
| 9 |
+
headers: { "Content-Type": "application/json" },
|
| 10 |
+
body: JSON.stringify({ username, password }),
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
if (!res.ok) {
|
| 14 |
+
const text = await res.text().catch(() => "");
|
| 15 |
+
throw new Error(`Login failed: ${text || res.status}`);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const json = await res.json();
|
| 19 |
+
if (!json.ok || !json.token) {
|
| 20 |
+
throw new Error(json.error || "Login failed");
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
return json; // { ok, token }
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
export async function sendChat(message, strictMode = true, history = [], token) {
|
| 27 |
+
const res = await fetch(`${API_BASE}/chat`, {
|
| 28 |
method: "POST",
|
| 29 |
headers: {
|
| 30 |
"Content-Type": "application/json",
|
| 31 |
+
Authorization: `Bearer ${token}`, // 🟢 send JWT
|
| 32 |
},
|
| 33 |
body: JSON.stringify({
|
| 34 |
+
message,
|
| 35 |
strict_mode: strictMode,
|
| 36 |
history,
|
| 37 |
}),
|
|
|
|
| 47 |
throw new Error(json.error || "Chat failed");
|
| 48 |
}
|
| 49 |
|
| 50 |
+
return json;
|
| 51 |
}
|