Spaces:
Running
Running
main dot py file added both evaluation and chat
Browse files- app/main.py +267 -83
app/main.py
CHANGED
|
@@ -221,12 +221,11 @@ def health():
|
|
| 221 |
|
| 222 |
@app.get("/", response_class=HTMLResponse)
|
| 223 |
def chat_ui():
|
| 224 |
-
html = """
|
| 225 |
-
<!DOCTYPE html>
|
| 226 |
<html lang="en">
|
| 227 |
<head>
|
| 228 |
<meta charset="UTF-8" />
|
| 229 |
-
<title>RAGBench Chat</title>
|
| 230 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 231 |
<style>
|
| 232 |
* { box-sizing: border-box; }
|
|
@@ -238,42 +237,122 @@ def chat_ui():
|
|
| 238 |
color: #111827;
|
| 239 |
}
|
| 240 |
.app {
|
| 241 |
-
max-width:
|
| 242 |
margin: 0 auto;
|
| 243 |
height: 100vh;
|
| 244 |
display: flex;
|
| 245 |
flex-direction: column;
|
| 246 |
padding: 0.75rem;
|
|
|
|
| 247 |
}
|
| 248 |
header {
|
| 249 |
display: flex;
|
| 250 |
align-items: center;
|
| 251 |
justify-content: space-between;
|
| 252 |
-
|
| 253 |
}
|
| 254 |
header h1 {
|
| 255 |
-
font-size: 1.1rem;
|
| 256 |
margin: 0;
|
|
|
|
| 257 |
}
|
| 258 |
header small {
|
| 259 |
color: #6b7280;
|
| 260 |
-
font-size: 0.75rem;
|
| 261 |
}
|
| 262 |
-
select {
|
| 263 |
-
|
|
|
|
|
|
|
| 264 |
border-radius: 999px;
|
| 265 |
border: 1px solid #d1d5db;
|
| 266 |
-
|
| 267 |
font-size: 0.85rem;
|
|
|
|
| 268 |
}
|
| 269 |
-
.chat-
|
|
|
|
|
|
|
| 270 |
flex: 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
background: white;
|
| 272 |
border-radius: 0.75rem;
|
| 273 |
-
padding: 0.75rem;
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
border: 1px solid #e5e7eb;
|
| 276 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
.message-row {
|
| 278 |
display: flex;
|
| 279 |
margin-bottom: 0.5rem;
|
|
@@ -281,24 +360,26 @@ def chat_ui():
|
|
| 281 |
.message-row.user {
|
| 282 |
justify-content: flex-end;
|
| 283 |
}
|
|
|
|
|
|
|
|
|
|
| 284 |
.bubble {
|
| 285 |
-
max-width:
|
| 286 |
-
padding: 0.
|
| 287 |
border-radius: 0.75rem;
|
| 288 |
-
font-size: 0.
|
| 289 |
-
line-height: 1.35;
|
| 290 |
white-space: pre-wrap;
|
| 291 |
-
|
| 292 |
}
|
| 293 |
.bubble.user {
|
| 294 |
background: #2563eb;
|
| 295 |
color: white;
|
| 296 |
-
border-bottom-right-radius: 0.
|
| 297 |
}
|
| 298 |
.bubble.assistant {
|
| 299 |
background: #e5e7eb;
|
| 300 |
color: #111827;
|
| 301 |
-
border-bottom-left-radius: 0.
|
| 302 |
}
|
| 303 |
.status {
|
| 304 |
margin-top: 0.25rem;
|
|
@@ -306,7 +387,7 @@ def chat_ui():
|
|
| 306 |
color: #6b7280;
|
| 307 |
min-height: 1.1rem;
|
| 308 |
}
|
| 309 |
-
form {
|
| 310 |
margin-top: 0.5rem;
|
| 311 |
display: flex;
|
| 312 |
gap: 0.5rem;
|
|
@@ -330,15 +411,19 @@ def chat_ui():
|
|
| 330 |
font-size: 0.9rem;
|
| 331 |
font-weight: 500;
|
| 332 |
cursor: pointer;
|
|
|
|
| 333 |
}
|
| 334 |
button:disabled {
|
| 335 |
opacity: 0.6;
|
| 336 |
cursor: default;
|
| 337 |
}
|
| 338 |
@media (max-width: 640px) {
|
| 339 |
-
.app {
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
| 343 |
</style>
|
| 344 |
</head>
|
|
@@ -350,6 +435,7 @@ def chat_ui():
|
|
| 350 |
<small>Select a domain, then start chatting.</small>
|
| 351 |
</div>
|
| 352 |
<div>
|
|
|
|
| 353 |
<select id="domain">
|
| 354 |
<option value="biomedical">Biomedical</option>
|
| 355 |
<option value="general_knowledge">General knowledge</option>
|
|
@@ -360,68 +446,166 @@ def chat_ui():
|
|
| 360 |
</div>
|
| 361 |
</header>
|
| 362 |
|
| 363 |
-
<div
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
</div>
|
| 371 |
|
| 372 |
-
<script>
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
const
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
const
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
addMessage(
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
form.querySelector("button").disabled = true;
|
| 402 |
-
|
| 403 |
-
try {
|
| 404 |
-
const resp = await fetch("/chat", {
|
| 405 |
-
method: "POST",
|
| 406 |
-
headers: { "Content-Type": "application/json" },
|
| 407 |
-
body: JSON.stringify({ domain, question }),
|
| 408 |
-
});
|
| 409 |
-
|
| 410 |
-
if (!resp.ok) {
|
| 411 |
-
throw new Error("HTTP " + resp.status);
|
| 412 |
-
}
|
| 413 |
|
| 414 |
-
const
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
}
|
| 422 |
-
|
| 423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
</body>
|
| 425 |
-
</html>
|
| 426 |
-
"""
|
| 427 |
return HTMLResponse(content=html)
|
|
|
|
|
|
| 221 |
|
| 222 |
@app.get("/", response_class=HTMLResponse)
|
| 223 |
def chat_ui():
|
| 224 |
+
html = """<!DOCTYPE html>
|
|
|
|
| 225 |
<html lang="en">
|
| 226 |
<head>
|
| 227 |
<meta charset="UTF-8" />
|
| 228 |
+
<title>RAGBench Chat & Evaluation</title>
|
| 229 |
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 230 |
<style>
|
| 231 |
* { box-sizing: border-box; }
|
|
|
|
| 237 |
color: #111827;
|
| 238 |
}
|
| 239 |
.app {
|
| 240 |
+
max-width: 1040px;
|
| 241 |
margin: 0 auto;
|
| 242 |
height: 100vh;
|
| 243 |
display: flex;
|
| 244 |
flex-direction: column;
|
| 245 |
padding: 0.75rem;
|
| 246 |
+
gap: 0.75rem;
|
| 247 |
}
|
| 248 |
header {
|
| 249 |
display: flex;
|
| 250 |
align-items: center;
|
| 251 |
justify-content: space-between;
|
| 252 |
+
gap: 1rem;
|
| 253 |
}
|
| 254 |
header h1 {
|
|
|
|
| 255 |
margin: 0;
|
| 256 |
+
font-size: 1.3rem;
|
| 257 |
}
|
| 258 |
header small {
|
| 259 |
color: #6b7280;
|
|
|
|
| 260 |
}
|
| 261 |
+
select, input, button, textarea {
|
| 262 |
+
font-family: inherit;
|
| 263 |
+
}
|
| 264 |
+
select, input {
|
| 265 |
border-radius: 999px;
|
| 266 |
border: 1px solid #d1d5db;
|
| 267 |
+
padding: 0.25rem 0.6rem;
|
| 268 |
font-size: 0.85rem;
|
| 269 |
+
background: white;
|
| 270 |
}
|
| 271 |
+
.chat-layout {
|
| 272 |
+
display: flex;
|
| 273 |
+
flex-direction: column;
|
| 274 |
flex: 1;
|
| 275 |
+
min-height: 0;
|
| 276 |
+
gap: 0.75rem;
|
| 277 |
+
}
|
| 278 |
+
.eval-card {
|
| 279 |
background: white;
|
| 280 |
border-radius: 0.75rem;
|
| 281 |
+
padding: 0.75rem 1rem;
|
| 282 |
+
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
|
| 283 |
+
border: 1px solid #e5e7eb;
|
| 284 |
+
}
|
| 285 |
+
.eval-header {
|
| 286 |
+
display: flex;
|
| 287 |
+
justify-content: space-between;
|
| 288 |
+
align-items: baseline;
|
| 289 |
+
gap: 1rem;
|
| 290 |
+
margin-bottom: 0.5rem;
|
| 291 |
+
}
|
| 292 |
+
.eval-header h2 {
|
| 293 |
+
margin: 0;
|
| 294 |
+
font-size: 1rem;
|
| 295 |
+
}
|
| 296 |
+
.eval-header p {
|
| 297 |
+
margin: 0;
|
| 298 |
+
font-size: 0.8rem;
|
| 299 |
+
color: #6b7280;
|
| 300 |
+
}
|
| 301 |
+
.eval-grid {
|
| 302 |
+
display: grid;
|
| 303 |
+
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
| 304 |
+
gap: 0.5rem 0.75rem;
|
| 305 |
+
align-items: end;
|
| 306 |
+
margin-bottom: 0.5rem;
|
| 307 |
+
}
|
| 308 |
+
.field {
|
| 309 |
+
display: flex;
|
| 310 |
+
flex-direction: column;
|
| 311 |
+
gap: 0.15rem;
|
| 312 |
+
font-size: 0.8rem;
|
| 313 |
+
}
|
| 314 |
+
.field label {
|
| 315 |
+
color: #4b5563;
|
| 316 |
+
}
|
| 317 |
+
.eval-actions {
|
| 318 |
+
display: flex;
|
| 319 |
+
align-items: center;
|
| 320 |
+
gap: 0.75rem;
|
| 321 |
+
flex-wrap: wrap;
|
| 322 |
+
font-size: 0.8rem;
|
| 323 |
+
}
|
| 324 |
+
.eval-status {
|
| 325 |
+
color: #6b7280;
|
| 326 |
+
min-height: 1.1rem;
|
| 327 |
+
}
|
| 328 |
+
.eval-output {
|
| 329 |
+
margin-top: 0.35rem;
|
| 330 |
+
max-height: 180px;
|
| 331 |
+
overflow: auto;
|
| 332 |
+
background: #f9fafb;
|
| 333 |
+
border-radius: 0.5rem;
|
| 334 |
+
padding: 0.5rem 0.75rem;
|
| 335 |
+
font-size: 0.75rem;
|
| 336 |
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
| 337 |
border: 1px solid #e5e7eb;
|
| 338 |
}
|
| 339 |
+
.chat-card {
|
| 340 |
+
background: white;
|
| 341 |
+
border-radius: 0.75rem;
|
| 342 |
+
padding: 0.75rem 1rem;
|
| 343 |
+
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
|
| 344 |
+
border: 1px solid #e5e7eb;
|
| 345 |
+
display: flex;
|
| 346 |
+
flex-direction: column;
|
| 347 |
+
flex: 1;
|
| 348 |
+
min-height: 0;
|
| 349 |
+
}
|
| 350 |
+
.chat-window {
|
| 351 |
+
flex: 1;
|
| 352 |
+
min-height: 0;
|
| 353 |
+
overflow-y: auto;
|
| 354 |
+
padding-right: 0.25rem;
|
| 355 |
+
}
|
| 356 |
.message-row {
|
| 357 |
display: flex;
|
| 358 |
margin-bottom: 0.5rem;
|
|
|
|
| 360 |
.message-row.user {
|
| 361 |
justify-content: flex-end;
|
| 362 |
}
|
| 363 |
+
.message-row.assistant {
|
| 364 |
+
justify-content: flex-start;
|
| 365 |
+
}
|
| 366 |
.bubble {
|
| 367 |
+
max-width: 80%;
|
| 368 |
+
padding: 0.45rem 0.7rem;
|
| 369 |
border-radius: 0.75rem;
|
| 370 |
+
font-size: 0.85rem;
|
|
|
|
| 371 |
white-space: pre-wrap;
|
| 372 |
+
line-height: 1.35;
|
| 373 |
}
|
| 374 |
.bubble.user {
|
| 375 |
background: #2563eb;
|
| 376 |
color: white;
|
| 377 |
+
border-bottom-right-radius: 0.25rem;
|
| 378 |
}
|
| 379 |
.bubble.assistant {
|
| 380 |
background: #e5e7eb;
|
| 381 |
color: #111827;
|
| 382 |
+
border-bottom-left-radius: 0.25rem;
|
| 383 |
}
|
| 384 |
.status {
|
| 385 |
margin-top: 0.25rem;
|
|
|
|
| 387 |
color: #6b7280;
|
| 388 |
min-height: 1.1rem;
|
| 389 |
}
|
| 390 |
+
form.chat-form {
|
| 391 |
margin-top: 0.5rem;
|
| 392 |
display: flex;
|
| 393 |
gap: 0.5rem;
|
|
|
|
| 411 |
font-size: 0.9rem;
|
| 412 |
font-weight: 500;
|
| 413 |
cursor: pointer;
|
| 414 |
+
white-space: nowrap;
|
| 415 |
}
|
| 416 |
button:disabled {
|
| 417 |
opacity: 0.6;
|
| 418 |
cursor: default;
|
| 419 |
}
|
| 420 |
@media (max-width: 640px) {
|
| 421 |
+
.app {
|
| 422 |
+
padding: 0.75rem 0.5rem;
|
| 423 |
+
}
|
| 424 |
+
.bubble {
|
| 425 |
+
max-width: 100%;
|
| 426 |
+
}
|
| 427 |
}
|
| 428 |
</style>
|
| 429 |
</head>
|
|
|
|
| 435 |
<small>Select a domain, then start chatting.</small>
|
| 436 |
</div>
|
| 437 |
<div>
|
| 438 |
+
<label for="domain" style="font-size:0.8rem;color:#4b5563;margin-right:0.25rem;">Domain</label>
|
| 439 |
<select id="domain">
|
| 440 |
<option value="biomedical">Biomedical</option>
|
| 441 |
<option value="general_knowledge">General knowledge</option>
|
|
|
|
| 446 |
</div>
|
| 447 |
</header>
|
| 448 |
|
| 449 |
+
<div class="chat-layout">
|
| 450 |
+
<section class="eval-card">
|
| 451 |
+
<form id="eval-form">
|
| 452 |
+
<div class="eval-header">
|
| 453 |
+
<div>
|
| 454 |
+
<h2>RAGBench RAG Evaluation</h2>
|
| 455 |
+
<p>Use this interface to run /run_domain evaluations against the RAGBench dataset.</p>
|
| 456 |
+
</div>
|
| 457 |
+
</div>
|
| 458 |
+
<div class="eval-grid">
|
| 459 |
+
<div class="field">
|
| 460 |
+
<label for="eval-domain">Domain</label>
|
| 461 |
+
<select id="eval-domain">
|
| 462 |
+
<option value="biomedical">Biomedical</option>
|
| 463 |
+
<option value="general_knowledge">General knowledge</option>
|
| 464 |
+
<option value="customer_support">Customer support</option>
|
| 465 |
+
<option value="finance">Finance</option>
|
| 466 |
+
<option value="legal">Legal</option>
|
| 467 |
+
</select>
|
| 468 |
+
</div>
|
| 469 |
+
<div class="field">
|
| 470 |
+
<label for="eval-k">Top-k documents</label>
|
| 471 |
+
<input id="eval-k" type="number" min="1" max="10" value="3" />
|
| 472 |
+
</div>
|
| 473 |
+
<div class="field">
|
| 474 |
+
<label for="eval-max-examples">Max examples</label>
|
| 475 |
+
<input id="eval-max-examples" type="number" min="1" value="5" />
|
| 476 |
+
</div>
|
| 477 |
+
<div class="field">
|
| 478 |
+
<label for="eval-split">Dataset split</label>
|
| 479 |
+
<input id="eval-split" type="text" value="validation" />
|
| 480 |
+
</div>
|
| 481 |
+
</div>
|
| 482 |
+
<div class="eval-actions">
|
| 483 |
+
<button type="submit">Run Domain Evaluation</button>
|
| 484 |
+
<div id="eval-status" class="eval-status"></div>
|
| 485 |
+
</div>
|
| 486 |
+
<pre id="eval-output" class="eval-output"></pre>
|
| 487 |
+
</form>
|
| 488 |
+
</section>
|
| 489 |
+
|
| 490 |
+
<section class="chat-card">
|
| 491 |
+
<div id="chat" class="chat-window"></div>
|
| 492 |
+
<div id="status" class="status"></div>
|
| 493 |
+
|
| 494 |
+
<form id="chat-form" class="chat-form">
|
| 495 |
+
<textarea id="question" placeholder="Ask a question..."></textarea>
|
| 496 |
+
<button type="submit">Send</button>
|
| 497 |
+
</form>
|
| 498 |
+
</section>
|
| 499 |
+
</div>
|
| 500 |
</div>
|
| 501 |
|
| 502 |
+
<script>
|
| 503 |
+
const form = document.getElementById("chat-form");
|
| 504 |
+
const questionEl = document.getElementById("question");
|
| 505 |
+
const domainEl = document.getElementById("domain");
|
| 506 |
+
const chatEl = document.getElementById("chat");
|
| 507 |
+
const statusEl = document.getElementById("status");
|
| 508 |
+
|
| 509 |
+
const evalForm = document.getElementById("eval-form");
|
| 510 |
+
const evalDomainEl = document.getElementById("eval-domain");
|
| 511 |
+
const evalKEl = document.getElementById("eval-k");
|
| 512 |
+
const evalMaxExamplesEl = document.getElementById("eval-max-examples");
|
| 513 |
+
const evalSplitEl = document.getElementById("eval-split");
|
| 514 |
+
const evalStatusEl = document.getElementById("eval-status");
|
| 515 |
+
const evalOutputEl = document.getElementById("eval-output");
|
| 516 |
+
|
| 517 |
+
// Keep evaluation domain and chat domain in sync
|
| 518 |
+
function syncDomains(from, to) {
|
| 519 |
+
if (!from || !to) return;
|
| 520 |
+
to.value = from.value;
|
| 521 |
+
}
|
| 522 |
+
syncDomains(domainEl, evalDomainEl);
|
| 523 |
+
if (domainEl && evalDomainEl) {
|
| 524 |
+
domainEl.addEventListener("change", () => syncDomains(domainEl, evalDomainEl));
|
| 525 |
+
evalDomainEl.addEventListener("change", () => syncDomains(evalDomainEl, domainEl));
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
function addMessage(role, text) {
|
| 529 |
+
const row = document.createElement("div");
|
| 530 |
+
row.className = "message-row " + role;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
|
| 532 |
+
const bubble = document.createElement("div");
|
| 533 |
+
bubble.className = "bubble " + role;
|
| 534 |
+
bubble.textContent = text;
|
| 535 |
+
|
| 536 |
+
row.appendChild(bubble);
|
| 537 |
+
chatEl.appendChild(row);
|
| 538 |
+
chatEl.scrollTop = chatEl.scrollHeight;
|
| 539 |
}
|
| 540 |
+
|
| 541 |
+
form.addEventListener("submit", async (event) => {
|
| 542 |
+
event.preventDefault();
|
| 543 |
+
const question = questionEl.value.trim();
|
| 544 |
+
if (!question) return;
|
| 545 |
+
|
| 546 |
+
addMessage("user", question);
|
| 547 |
+
questionEl.value = "";
|
| 548 |
+
statusEl.textContent = "Thinking...";
|
| 549 |
+
form.querySelector("button").disabled = true;
|
| 550 |
+
|
| 551 |
+
try {
|
| 552 |
+
const payload = {
|
| 553 |
+
question: question,
|
| 554 |
+
domain: domainEl.value || "biomedical",
|
| 555 |
+
};
|
| 556 |
+
|
| 557 |
+
const resp = await fetch("/chat", {
|
| 558 |
+
method: "POST",
|
| 559 |
+
headers: { "Content-Type": "application/json" },
|
| 560 |
+
body: JSON.stringify(payload),
|
| 561 |
+
});
|
| 562 |
+
|
| 563 |
+
if (!resp.ok) {
|
| 564 |
+
throw new Error("HTTP " + resp.status);
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
const data = await resp.json();
|
| 568 |
+
addMessage("assistant", data.answer || "[No answer returned]");
|
| 569 |
+
statusEl.textContent = "";
|
| 570 |
+
} catch (err) {
|
| 571 |
+
statusEl.textContent = "Error: " + err;
|
| 572 |
+
} finally {
|
| 573 |
+
form.querySelector("button").disabled = false;
|
| 574 |
+
}
|
| 575 |
+
});
|
| 576 |
+
|
| 577 |
+
evalForm.addEventListener("submit", async (event) => {
|
| 578 |
+
event.preventDefault();
|
| 579 |
+
evalStatusEl.textContent = "Running evaluation...";
|
| 580 |
+
evalOutputEl.textContent = "";
|
| 581 |
+
|
| 582 |
+
const payload = {
|
| 583 |
+
domain: evalDomainEl.value || "biomedical",
|
| 584 |
+
k: parseInt(evalKEl.value || "3", 10),
|
| 585 |
+
max_examples: parseInt(evalMaxExamplesEl.value || "5", 10),
|
| 586 |
+
split: evalSplitEl.value || "validation",
|
| 587 |
+
};
|
| 588 |
+
|
| 589 |
+
try {
|
| 590 |
+
const resp = await fetch("/run_domain", {
|
| 591 |
+
method: "POST",
|
| 592 |
+
headers: { "Content-Type": "application/json" },
|
| 593 |
+
body: JSON.stringify(payload),
|
| 594 |
+
});
|
| 595 |
+
|
| 596 |
+
if (!resp.ok) {
|
| 597 |
+
throw new Error("HTTP " + resp.status);
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
const data = await resp.json();
|
| 601 |
+
evalStatusEl.textContent = "Done.";
|
| 602 |
+
evalOutputEl.textContent = JSON.stringify(data, null, 2);
|
| 603 |
+
} catch (err) {
|
| 604 |
+
evalStatusEl.textContent = "Error: " + err;
|
| 605 |
+
}
|
| 606 |
+
});
|
| 607 |
+
</script>
|
| 608 |
</body>
|
| 609 |
+
</html>"""
|
|
|
|
| 610 |
return HTMLResponse(content=html)
|
| 611 |
+
|