Spaces:
Sleeping
Sleeping
Update web/src/lib/api.ts
Browse files- web/src/lib/api.ts +43 -0
web/src/lib/api.ts
CHANGED
|
@@ -102,6 +102,49 @@ export async function apiChat(payload: ApiChatReq): Promise<ApiChatResp> {
|
|
| 102 |
return data as ApiChatResp;
|
| 103 |
}
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
// --------------------
|
| 106 |
// /api/upload
|
| 107 |
// --------------------
|
|
|
|
| 102 |
return data as ApiChatResp;
|
| 103 |
}
|
| 104 |
|
| 105 |
+
|
| 106 |
+
// --------------------
|
| 107 |
+
// /api/quiz/start
|
| 108 |
+
// --------------------
|
| 109 |
+
export type ApiQuizStartReq = {
|
| 110 |
+
user_id: string;
|
| 111 |
+
language_preference?: string; // "Auto" | "English" | "中文"
|
| 112 |
+
doc_type?: string; // default: "Literature Review / Paper" (backend default ok)
|
| 113 |
+
learning_mode?: string; // default: "quiz"
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
export type ApiQuizStartResp = {
|
| 117 |
+
reply: string;
|
| 118 |
+
session_status_md: string;
|
| 119 |
+
refs: ApiChatRef[];
|
| 120 |
+
latency_ms: number;
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
export async function apiQuizStart(payload: ApiQuizStartReq): Promise<ApiQuizStartResp> {
|
| 124 |
+
const base = getBaseUrl();
|
| 125 |
+
const res = await fetchWithTimeout(
|
| 126 |
+
`${base}/api/quiz/start`,
|
| 127 |
+
{
|
| 128 |
+
method: "POST",
|
| 129 |
+
headers: { "Content-Type": "application/json" },
|
| 130 |
+
body: JSON.stringify({
|
| 131 |
+
language_preference: "Auto",
|
| 132 |
+
doc_type: "Literature Review / Paper",
|
| 133 |
+
learning_mode: "quiz",
|
| 134 |
+
...payload,
|
| 135 |
+
}),
|
| 136 |
+
},
|
| 137 |
+
60000
|
| 138 |
+
);
|
| 139 |
+
|
| 140 |
+
const data = await parseJsonSafe(res);
|
| 141 |
+
if (!res.ok) throw new Error(errMsg(data, `apiQuizStart failed (${res.status})`));
|
| 142 |
+
return data as ApiQuizStartResp;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
|
| 148 |
// --------------------
|
| 149 |
// /api/upload
|
| 150 |
// --------------------
|