Upload 2 files
Browse files- app.py +2 -0
- index.html +800 -795
app.py
CHANGED
|
@@ -185,6 +185,8 @@ async def stream_tokens(prompt: str, max_tokens: int, temperature: float, tools:
|
|
| 185 |
# Yield SSE event immediately (no buffering)
|
| 186 |
data = json.dumps({"type": "token", "content": new_text})
|
| 187 |
yield f"data: {data}\n\n"
|
|
|
|
|
|
|
| 188 |
logger.debug(f"Token {token_count}: {repr(new_text[:20])}...")
|
| 189 |
|
| 190 |
# Log generation stats
|
|
|
|
| 185 |
# Yield SSE event immediately (no buffering)
|
| 186 |
data = json.dumps({"type": "token", "content": new_text})
|
| 187 |
yield f"data: {data}\n\n"
|
| 188 |
+
# let the event loop schedule a send/flush so proxies don't buffer
|
| 189 |
+
await asyncio.sleep(0)
|
| 190 |
logger.debug(f"Token {token_count}: {repr(new_text[:20])}...")
|
| 191 |
|
| 192 |
# Log generation stats
|
index.html
CHANGED
|
@@ -1,796 +1,801 @@
|
|
| 1 |
-
<!
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
<
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
--
|
| 19 |
-
--
|
| 20 |
-
--
|
| 21 |
-
--
|
| 22 |
-
--
|
| 23 |
-
--
|
| 24 |
-
--
|
| 25 |
-
--
|
| 26 |
-
--
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
border
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
border
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
border
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
<
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
<
|
| 493 |
-
|
| 494 |
-
<div class="
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
<
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
<
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
<
|
| 509 |
-
|
| 510 |
-
<
|
| 511 |
-
|
| 512 |
-
<
|
| 513 |
-
|
| 514 |
-
<
|
| 515 |
-
|
| 516 |
-
<
|
| 517 |
-
|
| 518 |
-
<
|
| 519 |
-
|
| 520 |
-
<
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
<
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
<
|
| 533 |
-
|
| 534 |
-
<
|
| 535 |
-
|
| 536 |
-
<
|
| 537 |
-
|
| 538 |
-
<
|
| 539 |
-
|
| 540 |
-
<
|
| 541 |
-
|
| 542 |
-
<
|
| 543 |
-
|
| 544 |
-
<
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
const
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
dot.className = 'status-dot';
|
| 587 |
-
text.textContent = '
|
| 588 |
-
}
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
}
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
<
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
const
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
`;
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
}
|
| 768 |
-
|
| 769 |
-
function
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
//
|
| 776 |
-
text = text.replace(/
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
text = text.replace(/\
|
| 782 |
-
text = text.replace(/
|
| 783 |
-
|
| 784 |
-
//
|
| 785 |
-
text = text.replace(/\
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
}
|
| 794 |
-
|
| 795 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
</html>
|
|
|
|
| 1 |
+
<!-- this is a test chat for app.py in space to test the response and
|
| 2 |
+
streaming capabilities of the app.py return response and llm -->
|
| 3 |
+
|
| 4 |
+
<!DOCTYPE html>
|
| 5 |
+
<html lang="en">
|
| 6 |
+
<head>
|
| 7 |
+
<meta charset="UTF-8">
|
| 8 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 9 |
+
<title>Nanbeige4.1-3B Chat</title>
|
| 10 |
+
<style>
|
| 11 |
+
* {
|
| 12 |
+
margin: 0;
|
| 13 |
+
padding: 0;
|
| 14 |
+
box-sizing: border-box;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
:root {
|
| 18 |
+
--bg-primary: #0f0f0f;
|
| 19 |
+
--bg-secondary: #1a1a1a;
|
| 20 |
+
--bg-tertiary: #252525;
|
| 21 |
+
--accent: #00d4aa;
|
| 22 |
+
--accent-hover: #00b894;
|
| 23 |
+
--text-primary: #ffffff;
|
| 24 |
+
--text-secondary: #a0a0a0;
|
| 25 |
+
--border: #333333;
|
| 26 |
+
--user-msg: #1a3d35;
|
| 27 |
+
--assistant-msg: #252525;
|
| 28 |
+
--error: #ff4757;
|
| 29 |
+
--shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
body {
|
| 33 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
| 34 |
+
background: var(--bg-primary);
|
| 35 |
+
color: var(--text-primary);
|
| 36 |
+
height: 100vh;
|
| 37 |
+
display: flex;
|
| 38 |
+
flex-direction: column;
|
| 39 |
+
overflow: hidden;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* Header */
|
| 43 |
+
.header {
|
| 44 |
+
background: var(--bg-secondary);
|
| 45 |
+
border-bottom: 1px solid var(--border);
|
| 46 |
+
padding: 1rem 1.5rem;
|
| 47 |
+
display: flex;
|
| 48 |
+
align-items: center;
|
| 49 |
+
justify-content: space-between;
|
| 50 |
+
box-shadow: var(--shadow);
|
| 51 |
+
z-index: 10;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.logo {
|
| 55 |
+
display: flex;
|
| 56 |
+
align-items: center;
|
| 57 |
+
gap: 0.75rem;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.logo-icon {
|
| 61 |
+
width: 36px;
|
| 62 |
+
height: 36px;
|
| 63 |
+
background: linear-gradient(135deg, var(--accent), var(--accent-hover));
|
| 64 |
+
border-radius: 10px;
|
| 65 |
+
display: flex;
|
| 66 |
+
align-items: center;
|
| 67 |
+
justify-content: center;
|
| 68 |
+
font-weight: bold;
|
| 69 |
+
font-size: 1.2rem;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.logo-text {
|
| 73 |
+
font-size: 1.25rem;
|
| 74 |
+
font-weight: 600;
|
| 75 |
+
letter-spacing: -0.5px;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.logo-text span {
|
| 79 |
+
color: var(--accent);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.status {
|
| 83 |
+
display: flex;
|
| 84 |
+
align-items: center;
|
| 85 |
+
gap: 0.5rem;
|
| 86 |
+
font-size: 0.875rem;
|
| 87 |
+
color: var(--text-secondary);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.status-dot {
|
| 91 |
+
width: 8px;
|
| 92 |
+
height: 8px;
|
| 93 |
+
border-radius: 50%;
|
| 94 |
+
background: var(--text-secondary);
|
| 95 |
+
transition: background 0.3s ease;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.status-dot.online {
|
| 99 |
+
background: var(--accent);
|
| 100 |
+
box-shadow: 0 0 10px var(--accent);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.status-dot.error {
|
| 104 |
+
background: var(--error);
|
| 105 |
+
box-shadow: 0 0 10px var(--error);
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/* Main Chat Area */
|
| 109 |
+
.chat-container {
|
| 110 |
+
flex: 1;
|
| 111 |
+
overflow-y: auto;
|
| 112 |
+
padding: 2rem;
|
| 113 |
+
display: flex;
|
| 114 |
+
flex-direction: column;
|
| 115 |
+
gap: 1.5rem;
|
| 116 |
+
scroll-behavior: smooth;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.chat-container::-webkit-scrollbar {
|
| 120 |
+
width: 8px;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.chat-container::-webkit-scrollbar-track {
|
| 124 |
+
background: transparent;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.chat-container::-webkit-scrollbar-thumb {
|
| 128 |
+
background: var(--border);
|
| 129 |
+
border-radius: 4px;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.chat-container::-webkit-scrollbar-thumb:hover {
|
| 133 |
+
background: var(--text-secondary);
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.welcome-message {
|
| 137 |
+
text-align: center;
|
| 138 |
+
padding: 3rem 1rem;
|
| 139 |
+
color: var(--text-secondary);
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.welcome-message h2 {
|
| 143 |
+
color: var(--text-primary);
|
| 144 |
+
margin-bottom: 0.5rem;
|
| 145 |
+
font-size: 1.5rem;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.message {
|
| 149 |
+
display: flex;
|
| 150 |
+
gap: 1rem;
|
| 151 |
+
max-width: 900px;
|
| 152 |
+
margin: 0 auto;
|
| 153 |
+
width: 100%;
|
| 154 |
+
animation: fadeIn 0.3s ease;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
@keyframes fadeIn {
|
| 158 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 159 |
+
to { opacity: 1; transform: translateY(0); }
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.message-avatar {
|
| 163 |
+
width: 36px;
|
| 164 |
+
height: 36px;
|
| 165 |
+
border-radius: 50%;
|
| 166 |
+
display: flex;
|
| 167 |
+
align-items: center;
|
| 168 |
+
justify-content: center;
|
| 169 |
+
font-size: 1rem;
|
| 170 |
+
flex-shrink: 0;
|
| 171 |
+
font-weight: 600;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.user-message .message-avatar {
|
| 175 |
+
background: var(--accent);
|
| 176 |
+
color: var(--bg-primary);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.assistant-message .message-avatar {
|
| 180 |
+
background: var(--bg-tertiary);
|
| 181 |
+
border: 1px solid var(--border);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.message-content {
|
| 185 |
+
flex: 1;
|
| 186 |
+
padding: 1rem 1.25rem;
|
| 187 |
+
border-radius: 12px;
|
| 188 |
+
line-height: 1.6;
|
| 189 |
+
font-size: 0.95rem;
|
| 190 |
+
white-space: pre-wrap;
|
| 191 |
+
word-wrap: break-word;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.user-message .message-content {
|
| 195 |
+
background: var(--user-msg);
|
| 196 |
+
border: 1px solid rgba(0, 212, 170, 0.2);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
.assistant-message .message-content {
|
| 200 |
+
background: var(--assistant-msg);
|
| 201 |
+
border: 1px solid var(--border);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.message-content.loading {
|
| 205 |
+
display: flex;
|
| 206 |
+
align-items: center;
|
| 207 |
+
gap: 0.5rem;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.typing-indicator {
|
| 211 |
+
display: flex;
|
| 212 |
+
gap: 4px;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
.typing-indicator span {
|
| 216 |
+
width: 6px;
|
| 217 |
+
height: 6px;
|
| 218 |
+
background: var(--text-secondary);
|
| 219 |
+
border-radius: 50%;
|
| 220 |
+
animation: bounce 1.4s infinite ease-in-out both;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
|
| 224 |
+
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
|
| 225 |
+
|
| 226 |
+
@keyframes bounce {
|
| 227 |
+
0%, 80%, 100% { transform: scale(0); }
|
| 228 |
+
40% { transform: scale(1); }
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
/* Input Area */
|
| 232 |
+
.input-container {
|
| 233 |
+
background: var(--bg-secondary);
|
| 234 |
+
border-top: 1px solid var(--border);
|
| 235 |
+
padding: 1.5rem;
|
| 236 |
+
display: flex;
|
| 237 |
+
justify-content: center;
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
.input-wrapper {
|
| 241 |
+
max-width: 900px;
|
| 242 |
+
width: 100%;
|
| 243 |
+
position: relative;
|
| 244 |
+
display: flex;
|
| 245 |
+
gap: 0.75rem;
|
| 246 |
+
align-items: flex-end;
|
| 247 |
+
background: var(--bg-tertiary);
|
| 248 |
+
border: 1px solid var(--border);
|
| 249 |
+
border-radius: 16px;
|
| 250 |
+
padding: 0.75rem;
|
| 251 |
+
transition: border-color 0.2s ease, box-shadow 0.2s ease;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.input-wrapper:focus-within {
|
| 255 |
+
border-color: var(--accent);
|
| 256 |
+
box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.1);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
textarea {
|
| 260 |
+
flex: 1;
|
| 261 |
+
background: transparent;
|
| 262 |
+
border: none;
|
| 263 |
+
color: var(--text-primary);
|
| 264 |
+
font-size: 0.95rem;
|
| 265 |
+
resize: none;
|
| 266 |
+
max-height: 200px;
|
| 267 |
+
min-height: 24px;
|
| 268 |
+
font-family: inherit;
|
| 269 |
+
line-height: 1.5;
|
| 270 |
+
padding: 0.25rem 0.5rem;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
textarea:focus {
|
| 274 |
+
outline: none;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
textarea::placeholder {
|
| 278 |
+
color: var(--text-secondary);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.send-btn {
|
| 282 |
+
background: var(--accent);
|
| 283 |
+
color: var(--bg-primary);
|
| 284 |
+
border: none;
|
| 285 |
+
width: 36px;
|
| 286 |
+
height: 36px;
|
| 287 |
+
border-radius: 10px;
|
| 288 |
+
cursor: pointer;
|
| 289 |
+
display: flex;
|
| 290 |
+
align-items: center;
|
| 291 |
+
justify-content: center;
|
| 292 |
+
transition: all 0.2s ease;
|
| 293 |
+
flex-shrink: 0;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.send-btn:hover:not(:disabled) {
|
| 297 |
+
background: var(--accent-hover);
|
| 298 |
+
transform: scale(1.05);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
.send-btn:disabled {
|
| 302 |
+
opacity: 0.5;
|
| 303 |
+
cursor: not-allowed;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.send-btn svg {
|
| 307 |
+
width: 18px;
|
| 308 |
+
height: 18px;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
/* Settings Panel */
|
| 312 |
+
.settings-btn {
|
| 313 |
+
background: transparent;
|
| 314 |
+
border: 1px solid var(--border);
|
| 315 |
+
color: var(--text-secondary);
|
| 316 |
+
padding: 0.5rem 1rem;
|
| 317 |
+
border-radius: 8px;
|
| 318 |
+
cursor: pointer;
|
| 319 |
+
font-size: 0.875rem;
|
| 320 |
+
transition: all 0.2s ease;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.settings-btn:hover {
|
| 324 |
+
border-color: var(--accent);
|
| 325 |
+
color: var(--accent);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.settings-panel {
|
| 329 |
+
position: fixed;
|
| 330 |
+
top: 50%;
|
| 331 |
+
left: 50%;
|
| 332 |
+
transform: translate(-50%, -50%) scale(0.95);
|
| 333 |
+
background: var(--bg-secondary);
|
| 334 |
+
border: 1px solid var(--border);
|
| 335 |
+
border-radius: 16px;
|
| 336 |
+
padding: 1.5rem;
|
| 337 |
+
width: 90%;
|
| 338 |
+
max-width: 400px;
|
| 339 |
+
box-shadow: var(--shadow);
|
| 340 |
+
opacity: 0;
|
| 341 |
+
visibility: hidden;
|
| 342 |
+
transition: all 0.2s ease;
|
| 343 |
+
z-index: 100;
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
.settings-panel.active {
|
| 347 |
+
opacity: 1;
|
| 348 |
+
visibility: visible;
|
| 349 |
+
transform: translate(-50%, -50%) scale(1);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
.settings-overlay {
|
| 353 |
+
position: fixed;
|
| 354 |
+
top: 0;
|
| 355 |
+
left: 0;
|
| 356 |
+
right: 0;
|
| 357 |
+
bottom: 0;
|
| 358 |
+
background: rgba(0, 0, 0, 0.7);
|
| 359 |
+
opacity: 0;
|
| 360 |
+
visibility: hidden;
|
| 361 |
+
transition: all 0.2s ease;
|
| 362 |
+
z-index: 99;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
.settings-overlay.active {
|
| 366 |
+
opacity: 1;
|
| 367 |
+
visibility: visible;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
.settings-header {
|
| 371 |
+
display: flex;
|
| 372 |
+
justify-content: space-between;
|
| 373 |
+
align-items: center;
|
| 374 |
+
margin-bottom: 1.5rem;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
.settings-title {
|
| 378 |
+
font-size: 1.25rem;
|
| 379 |
+
font-weight: 600;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
.close-settings {
|
| 383 |
+
background: none;
|
| 384 |
+
border: none;
|
| 385 |
+
color: var(--text-secondary);
|
| 386 |
+
cursor: pointer;
|
| 387 |
+
font-size: 1.5rem;
|
| 388 |
+
line-height: 1;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
.setting-item {
|
| 392 |
+
margin-bottom: 1.25rem;
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
.setting-label {
|
| 396 |
+
display: block;
|
| 397 |
+
font-size: 0.875rem;
|
| 398 |
+
color: var(--text-secondary);
|
| 399 |
+
margin-bottom: 0.5rem;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
.setting-input {
|
| 403 |
+
width: 100%;
|
| 404 |
+
background: var(--bg-tertiary);
|
| 405 |
+
border: 1px solid var(--border);
|
| 406 |
+
color: var(--text-primary);
|
| 407 |
+
padding: 0.75rem;
|
| 408 |
+
border-radius: 8px;
|
| 409 |
+
font-size: 0.9rem;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
.setting-input:focus {
|
| 413 |
+
outline: none;
|
| 414 |
+
border-color: var(--accent);
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
/* Code blocks */
|
| 418 |
+
pre {
|
| 419 |
+
background: var(--bg-primary);
|
| 420 |
+
border: 1px solid var(--border);
|
| 421 |
+
border-radius: 8px;
|
| 422 |
+
padding: 1rem;
|
| 423 |
+
overflow-x: auto;
|
| 424 |
+
margin: 0.75rem 0;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
code {
|
| 428 |
+
font-family: 'Courier New', monospace;
|
| 429 |
+
font-size: 0.9em;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
pre code {
|
| 433 |
+
color: #e0e0e0;
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
/* Responsive */
|
| 437 |
+
@media (max-width: 768px) {
|
| 438 |
+
.chat-container {
|
| 439 |
+
padding: 1rem;
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
.header {
|
| 443 |
+
padding: 1rem;
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
.logo-text {
|
| 447 |
+
font-size: 1rem;
|
| 448 |
+
}
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
/* Empty state suggestions */
|
| 452 |
+
.suggestions {
|
| 453 |
+
display: grid;
|
| 454 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 455 |
+
gap: 1rem;
|
| 456 |
+
max-width: 800px;
|
| 457 |
+
margin: 2rem auto;
|
| 458 |
+
padding: 0 1rem;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
.suggestion-card {
|
| 462 |
+
background: var(--bg-secondary);
|
| 463 |
+
border: 1px solid var(--border);
|
| 464 |
+
border-radius: 12px;
|
| 465 |
+
padding: 1rem;
|
| 466 |
+
cursor: pointer;
|
| 467 |
+
transition: all 0.2s ease;
|
| 468 |
+
text-align: left;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
.suggestion-card:hover {
|
| 472 |
+
border-color: var(--accent);
|
| 473 |
+
transform: translateY(-2px);
|
| 474 |
+
box-shadow: 0 4px 12px rgba(0, 212, 170, 0.1);
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
.suggestion-card h4 {
|
| 478 |
+
color: var(--accent);
|
| 479 |
+
margin-bottom: 0.5rem;
|
| 480 |
+
font-size: 0.9rem;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
.suggestion-card p {
|
| 484 |
+
color: var(--text-secondary);
|
| 485 |
+
font-size: 0.85rem;
|
| 486 |
+
line-height: 1.4;
|
| 487 |
+
}
|
| 488 |
+
</style>
|
| 489 |
+
</head>
|
| 490 |
+
<body>
|
| 491 |
+
<header class="header">
|
| 492 |
+
<div class="logo">
|
| 493 |
+
<div class="logo-icon">N</div>
|
| 494 |
+
<div class="logo-text">Nanbeige<span>4.1-3B</span></div>
|
| 495 |
+
</div>
|
| 496 |
+
<div style="display: flex; gap: 1rem; align-items: center;">
|
| 497 |
+
<div class="status">
|
| 498 |
+
<div class="status-dot" id="statusDot"></div>
|
| 499 |
+
<span id="statusText">Checking...</span>
|
| 500 |
+
</div>
|
| 501 |
+
<button class="settings-btn" onclick="toggleSettings()">⚙️ Settings</button>
|
| 502 |
+
<button class="settings-btn" onclick="clearChat()">🗑️ Clear</button>
|
| 503 |
+
</div>
|
| 504 |
+
</header>
|
| 505 |
+
|
| 506 |
+
<div class="settings-overlay" id="settingsOverlay" onclick="toggleSettings()"></div>
|
| 507 |
+
<div class="settings-panel" id="settingsPanel">
|
| 508 |
+
<div class="settings-header">
|
| 509 |
+
<h3 class="settings-title">Settings</h3>
|
| 510 |
+
<button class="close-settings" onclick="toggleSettings()">×</button>
|
| 511 |
+
</div>
|
| 512 |
+
<div class="setting-item">
|
| 513 |
+
<label class="setting-label">Temperature (0.0 - 2.0)</label>
|
| 514 |
+
<input type="number" class="setting-input" id="temperature" min="0" max="2" step="0.1" value="0.6">
|
| 515 |
+
</div>
|
| 516 |
+
<div class="setting-item">
|
| 517 |
+
<label class="setting-label">Max Tokens (1 - 4096)</label>
|
| 518 |
+
<input type="number" class="setting-input" id="maxTokens" min="1" max="4096" step="1" value="2048">
|
| 519 |
+
</div>
|
| 520 |
+
<div class="setting-item">
|
| 521 |
+
<label class="setting-label">System Prompt</label>
|
| 522 |
+
<textarea class="setting-input" id="systemPrompt" rows="3" placeholder="Optional system instructions..."></textarea>
|
| 523 |
+
</div>
|
| 524 |
+
</div>
|
| 525 |
+
|
| 526 |
+
<main class="chat-container" id="chatContainer">
|
| 527 |
+
<div class="welcome-message" id="welcomeMessage">
|
| 528 |
+
<h2>Welcome to Nanbeige4.1-3B</h2>
|
| 529 |
+
<p>A powerful language model for conversation and assistance</p>
|
| 530 |
+
|
| 531 |
+
<div class="suggestions">
|
| 532 |
+
<div class="suggestion-card" onclick="sendSuggestion('Explain quantum computing in simple terms')">
|
| 533 |
+
<h4>💡 Explain a concept</h4>
|
| 534 |
+
<p>"Explain quantum computing in simple terms"</p>
|
| 535 |
+
</div>
|
| 536 |
+
<div class="suggestion-card" onclick="sendSuggestion('Write a Python function to calculate fibonacci numbers')">
|
| 537 |
+
<h4>💻 Code assistance</h4>
|
| 538 |
+
<p>"Write a Python function to calculate fibonacci numbers"</p>
|
| 539 |
+
</div>
|
| 540 |
+
<div class="suggestion-card" onclick="sendSuggestion('Help me brainstorm ideas for a sci-fi short story')">
|
| 541 |
+
<h4>✨ Creative writing</h4>
|
| 542 |
+
<p>"Help me brainstorm ideas for a sci-fi short story"</p>
|
| 543 |
+
</div>
|
| 544 |
+
<div class="suggestion-card" onclick="sendSuggestion('What are the latest developments in AI?')">
|
| 545 |
+
<h4>🤖 General knowledge</h4>
|
| 546 |
+
<p>"What are the latest developments in AI?"</p>
|
| 547 |
+
</div>
|
| 548 |
+
</div>
|
| 549 |
+
</div>
|
| 550 |
+
</main>
|
| 551 |
+
|
| 552 |
+
<div class="input-container">
|
| 553 |
+
<div class="input-wrapper">
|
| 554 |
+
<textarea
|
| 555 |
+
id="messageInput"
|
| 556 |
+
placeholder="Type your message..."
|
| 557 |
+
rows="1"
|
| 558 |
+
onkeydown="handleKeyDown(event)"
|
| 559 |
+
oninput="autoResize(this)"
|
| 560 |
+
></textarea>
|
| 561 |
+
<button class="send-btn" id="sendBtn" onclick="sendMessage()">
|
| 562 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
| 563 |
+
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"/>
|
| 564 |
+
</svg>
|
| 565 |
+
</button>
|
| 566 |
+
</div>
|
| 567 |
+
</div>
|
| 568 |
+
|
| 569 |
+
<script>
|
| 570 |
+
let messages = [];
|
| 571 |
+
let isStreaming = false;
|
| 572 |
+
const API_BASE = window.location.origin;
|
| 573 |
+
|
| 574 |
+
// Check health on load
|
| 575 |
+
checkHealth();
|
| 576 |
+
setInterval(checkHealth, 30000);
|
| 577 |
+
|
| 578 |
+
async function checkHealth() {
|
| 579 |
+
try {
|
| 580 |
+
const response = await fetch(`${API_BASE}/health`);
|
| 581 |
+
const data = await response.json();
|
| 582 |
+
const dot = document.getElementById('statusDot');
|
| 583 |
+
const text = document.getElementById('statusText');
|
| 584 |
+
|
| 585 |
+
if (data.model_loaded) {
|
| 586 |
+
dot.className = 'status-dot online';
|
| 587 |
+
text.textContent = 'Online';
|
| 588 |
+
} else {
|
| 589 |
+
dot.className = 'status-dot';
|
| 590 |
+
text.textContent = 'Loading...';
|
| 591 |
+
}
|
| 592 |
+
} catch (error) {
|
| 593 |
+
document.getElementById('statusDot').className = 'status-dot error';
|
| 594 |
+
document.getElementById('statusText').textContent = 'Offline';
|
| 595 |
+
}
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
function toggleSettings() {
|
| 599 |
+
document.getElementById('settingsPanel').classList.toggle('active');
|
| 600 |
+
document.getElementById('settingsOverlay').classList.toggle('active');
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
function clearChat() {
|
| 604 |
+
messages = [];
|
| 605 |
+
document.getElementById('chatContainer').innerHTML = `
|
| 606 |
+
<div class="welcome-message" id="welcomeMessage">
|
| 607 |
+
<h2>Welcome to Nanbeige4.1-3B</h2>
|
| 608 |
+
<p>Start a new conversation</p>
|
| 609 |
+
</div>
|
| 610 |
+
`;
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
function autoResize(textarea) {
|
| 614 |
+
textarea.style.height = 'auto';
|
| 615 |
+
textarea.style.height = Math.min(textarea.scrollHeight, 200) + 'px';
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
function handleKeyDown(e) {
|
| 619 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 620 |
+
e.preventDefault();
|
| 621 |
+
sendMessage();
|
| 622 |
+
}
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
function sendSuggestion(text) {
|
| 626 |
+
document.getElementById('messageInput').value = text;
|
| 627 |
+
sendMessage();
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
async function sendMessage() {
|
| 631 |
+
const input = document.getElementById('messageInput');
|
| 632 |
+
const text = input.value.trim();
|
| 633 |
+
|
| 634 |
+
if (!text || isStreaming) return;
|
| 635 |
+
|
| 636 |
+
// Hide welcome message
|
| 637 |
+
const welcome = document.getElementById('welcomeMessage');
|
| 638 |
+
if (welcome) welcome.style.display = 'none';
|
| 639 |
+
|
| 640 |
+
// Add user message
|
| 641 |
+
addMessage('user', text);
|
| 642 |
+
messages.push({ role: 'user', content: text });
|
| 643 |
+
|
| 644 |
+
// Clear input
|
| 645 |
+
input.value = '';
|
| 646 |
+
input.style.height = 'auto';
|
| 647 |
+
|
| 648 |
+
// Show loading
|
| 649 |
+
isStreaming = true;
|
| 650 |
+
document.getElementById('sendBtn').disabled = true;
|
| 651 |
+
const loadingId = addLoadingMessage();
|
| 652 |
+
|
| 653 |
+
try {
|
| 654 |
+
const temperature = parseFloat(document.getElementById('temperature').value) || 0.6;
|
| 655 |
+
const maxTokens = parseInt(document.getElementById('maxTokens').value) || 2048;
|
| 656 |
+
const systemPrompt = document.getElementById('systemPrompt').value.trim();
|
| 657 |
+
|
| 658 |
+
let chatMessages = [...messages];
|
| 659 |
+
if (systemPrompt && messages.length === 1) {
|
| 660 |
+
chatMessages.unshift({ role: 'system', content: systemPrompt });
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
const response = await fetch(`${API_BASE}/chat`, {
|
| 664 |
+
method: 'POST',
|
| 665 |
+
headers: { 'Content-Type': 'application/json' },
|
| 666 |
+
body: JSON.stringify({
|
| 667 |
+
messages: chatMessages,
|
| 668 |
+
stream: true,
|
| 669 |
+
temperature: temperature,
|
| 670 |
+
max_tokens: maxTokens
|
| 671 |
+
})
|
| 672 |
+
});
|
| 673 |
+
|
| 674 |
+
if (!response.ok) throw new Error('Failed to get response');
|
| 675 |
+
|
| 676 |
+
// Remove loading, prepare for streaming
|
| 677 |
+
removeLoadingMessage(loadingId);
|
| 678 |
+
const assistantId = addMessage('assistant', '');
|
| 679 |
+
|
| 680 |
+
const reader = response.body.getReader();
|
| 681 |
+
const decoder = new TextDecoder();
|
| 682 |
+
let buffer = '';
|
| 683 |
+
let fullContent = '';
|
| 684 |
+
|
| 685 |
+
while (true) {
|
| 686 |
+
const { done, value } = await reader.read();
|
| 687 |
+
if (done) break;
|
| 688 |
+
|
| 689 |
+
buffer += decoder.decode(value, { stream: true });
|
| 690 |
+
const lines = buffer.split('\n');
|
| 691 |
+
buffer = lines.pop();
|
| 692 |
+
|
| 693 |
+
for (const line of lines) {
|
| 694 |
+
if (line.startsWith('data: ')) {
|
| 695 |
+
try {
|
| 696 |
+
const data = JSON.parse(line.slice(6));
|
| 697 |
+
if (data.type === 'token') {
|
| 698 |
+
fullContent += data.content;
|
| 699 |
+
updateMessage(assistantId, fullContent);
|
| 700 |
+
// allow DOM to repaint between tokens in case chunks arrive together
|
| 701 |
+
await new Promise(r => setTimeout(r, 0));
|
| 702 |
+
} else if (data.type === 'done') {
|
| 703 |
+
messages.push({ role: 'assistant', content: fullContent });
|
| 704 |
+
}
|
| 705 |
+
} catch (e) {
|
| 706 |
+
console.error('Parse error:', e);
|
| 707 |
+
}
|
| 708 |
+
}
|
| 709 |
+
}
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
} catch (error) {
|
| 713 |
+
removeLoadingMessage(loadingId);
|
| 714 |
+
addMessage('assistant', `Error: ${error.message}. Please check if the API is running.`);
|
| 715 |
+
} finally {
|
| 716 |
+
isStreaming = false;
|
| 717 |
+
document.getElementById('sendBtn').disabled = false;
|
| 718 |
+
}
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
function addMessage(role, content) {
|
| 722 |
+
const container = document.getElementById('chatContainer');
|
| 723 |
+
const id = 'msg-' + Date.now();
|
| 724 |
+
|
| 725 |
+
const div = document.createElement('div');
|
| 726 |
+
div.className = `message ${role}-message`;
|
| 727 |
+
div.id = id;
|
| 728 |
+
div.innerHTML = `
|
| 729 |
+
<div class="message-avatar">${role === 'user' ? 'U' : '🤖'}</div>
|
| 730 |
+
<div class="message-content">${formatContent(content)}</div>
|
| 731 |
+
`;
|
| 732 |
+
|
| 733 |
+
container.appendChild(div);
|
| 734 |
+
scrollToBottom();
|
| 735 |
+
return id;
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
function updateMessage(id, content) {
|
| 739 |
+
const msg = document.getElementById(id);
|
| 740 |
+
if (msg) {
|
| 741 |
+
msg.querySelector('.message-content').innerHTML = formatContent(content);
|
| 742 |
+
scrollToBottom();
|
| 743 |
+
}
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
function addLoadingMessage() {
|
| 747 |
+
const id = 'loading-' + Date.now();
|
| 748 |
+
const container = document.getElementById('chatContainer');
|
| 749 |
+
|
| 750 |
+
const div = document.createElement('div');
|
| 751 |
+
div.className = 'message assistant-message';
|
| 752 |
+
div.id = id;
|
| 753 |
+
div.innerHTML = `
|
| 754 |
+
<div class="message-avatar">🤖</div>
|
| 755 |
+
<div class="message-content loading">
|
| 756 |
+
<div class="typing-indicator">
|
| 757 |
+
<span></span>
|
| 758 |
+
<span></span>
|
| 759 |
+
<span></span>
|
| 760 |
+
</div>
|
| 761 |
+
</div>
|
| 762 |
+
`;
|
| 763 |
+
|
| 764 |
+
container.appendChild(div);
|
| 765 |
+
scrollToBottom();
|
| 766 |
+
return id;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
function removeLoadingMessage(id) {
|
| 770 |
+
const el = document.getElementById(id);
|
| 771 |
+
if (el) el.remove();
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
function formatContent(text) {
|
| 775 |
+
// Escape HTML
|
| 776 |
+
text = text.replace(/&/g, '&')
|
| 777 |
+
.replace(/</g, '<')
|
| 778 |
+
.replace(/>/g, '>');
|
| 779 |
+
|
| 780 |
+
// Format code blocks
|
| 781 |
+
text = text.replace(/```(\w+)?\n([\s\S]*?)```/g, '<pre><code>$2</code></pre>');
|
| 782 |
+
text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
|
| 783 |
+
|
| 784 |
+
// Format bold and italic
|
| 785 |
+
text = text.replace(/\*\*\*(.*?)\*\*\*/g, '<strong><em>$1</em></strong>');
|
| 786 |
+
text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
|
| 787 |
+
text = text.replace(/\*(.*?)\*/g, '<em>$1</em>');
|
| 788 |
+
|
| 789 |
+
// Convert newlines to <br> outside of pre blocks
|
| 790 |
+
text = text.replace(/\n/g, '<br>');
|
| 791 |
+
|
| 792 |
+
return text;
|
| 793 |
+
}
|
| 794 |
+
|
| 795 |
+
function scrollToBottom() {
|
| 796 |
+
const container = document.getElementById('chatContainer');
|
| 797 |
+
container.scrollTop = container.scrollHeight;
|
| 798 |
+
}
|
| 799 |
+
</script>
|
| 800 |
+
</body>
|
| 801 |
</html>
|