File size: 26,835 Bytes
28a12c8 02e4b83 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 2444451 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 2444451 28a12c8 2444451 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 0092a74 28a12c8 2444451 28a12c8 2444451 28a12c8 02e4b83 |
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 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 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 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 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 581 582 583 584 585 586 587 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 679 680 |
<!DOCTYPE html>
<html>
<head>
<title>Tool-Calling Agent With Local LLM</title>
<script src="https://cdn.jsdelivr.net/pyodide/v0.27.7/full/pyodide.js"></script>
<script src="config.js"></script>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.description {
background: #f8f9fa;
border-left: 4px solid #007cba;
padding: 20px;
margin-bottom: 30px;
border-radius: 5px;
color: #555;
line-height: 1.6;
}
.description h2 {
color: #333;
margin-top: 0;
margin-bottom: 15px;
font-size: 20px;
}
.description p {
margin-bottom: 12px;
}
.description ul {
margin-bottom: 0;
padding-left: 20px;
}
.description li {
margin-bottom: 8px;
}
.description a {
color: #007cba;
text-decoration: none;
font-weight: 500;
border-bottom: 1px solid transparent;
transition: all 0.2s ease;
}
.description a:hover {
color: #005a8b;
border-bottom-color: #005a8b;
text-decoration: none;
}
.description a:visited {
color: #007cba;
}
.input-group {
margin-bottom: 20px;
}
.server-config {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 5px;
padding: 15px;
margin-bottom: 15px;
}
.server-config h3 {
margin: 0 0 10px 0;
color: #495057;
font-size: 16px;
}
.slim-input {
height: 40px !important;
font-size: 13px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input[type="text"], input[type="password"], textarea {
width: 100%;
padding: 12px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 14px;
box-sizing: border-box;
}
textarea {
height: 100px;
resize: vertical;
font-family: inherit;
}
button {
background: #007cba;
color: white;
border: none;
padding: 12px 24px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
button:hover { background: #005a8b; }
button:disabled {
background: #ccc;
cursor: not-allowed;
}
#initOutput, #agentOutput {
background: #f8f9fa;
border: 2px solid #e9ecef;
border-radius: 5px;
padding: 15px;
margin-top: 20px;
min-height: 150px;
font-family: 'Courier New', monospace;
font-size: 14px;
white-space: pre-wrap;
max-height: 300px;
overflow-y: auto;
}
#initOutput {
margin-bottom: 20px;
}
.status {
padding: 10px;
border-radius: 5px;
margin: 10px 0;
}
.success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
.warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
.example-prompts, .server-presets {
margin: 10px 0;
}
.example-prompts button, .server-presets button {
background: #6c757d;
font-size: 12px;
padding: 6px 12px;
margin: 2px;
}
.example-prompts button:hover, .server-presets button:hover {
background: #5a6268;
}
.config-info {
background: #e7f3ff;
border: 1px solid #b8daff;
border-radius: 5px;
padding: 10px;
margin-bottom: 20px;
font-size: 14px;
}
.running-indicator {
display: none;
background: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 5px;
padding: 15px;
margin: 15px 0;
font-weight: bold;
color: #856404;
text-align: center;
font-size: 16px;
animation: pulse 1.5s infinite;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
@keyframes pulse {
0%, 100% { opacity: 0.7; }
50% { opacity: 1; }
}
</style>
</head>
<body>
<div class="container">
<h1>π€ Tool-Calling Agent With Local LLM</h1>
<div class="description">
<p>
This interactive web application allows you to experiment with AI agents in your browser, using
<a href="https://openai.github.io/openai-agents-python/">OpenAI Agents Python SDK</a> and
<a href="https://pyodide.org/en/stable/">Pyodide</a>.
You can customize agent behavior, test different prompts, and see responses in real-time.
Check the <a href="https://github.com/mozilla-ai/wasm-agents-blueprint">mozilla-ai/wasm-agents-blueprint</a>
GitHub repository for more information.
</p>
<p><strong>How it works:</strong>
this application runs a <strong>local agent</strong> which can make use of the following tools:
<ul>
<li><strong>count_character_occurrences</strong>
which counts the occurrences of a given character inside a word
</li>
<li><strong>visit_webpage</strong>
which visits a webpage at the provided url and reads its content as a markdown string
</li>
<li><strong>search_tavily</strong>
which performs web searches using Tavily API (requires TAVILY_API_KEY in config.js)
</li>
</ul>
While the former tool is quite trivial and is mainly used to show how to address the
<a href="https://community.openai.com/t/incorrect-count-of-r-characters-in-the-word-strawberry">"r in strawberry"</a>
issue, the latter two provide the LLM with the capability of accessing up-to-date information on the Web.
</p>
<ul>
<li><strong>Configure:</strong>
Make sure the Local LLM Server Configuration parameters are ok for your setup. In particular,
the default expects you to have <a href="https://ollama.com/">Ollama</a> running on your system
with the <a href="https://ollama.com/library/qwen3:8b">qwen3:8b</a> model installed. You
can also click the <strong>LM Studio</strong> preset button if you are using
<a href="https://lmstudio.ai/">LM Studio</a>, and make sure to update your model name accordingly.
Optionally, add your TAVILY_API_KEY to config.js to enable web search functionality.
<br/><strong>NOTE</strong>: if you are using LM Studio with a thinking model and are getting tool
calls directly in the model's response, disable thinking in the "Edit model default parameters" section.
</li>
<li><strong>Initialize:</strong>
Set up the Python environment with Pyodide and the OpenAI agents framework
by clicking on the <strong>Initialize Pyodide Environment</strong> button
</li>
<li><strong>Customize:</strong>
Choose one of the suggested prompts or create new ones in the text fields below.
(<strong>hint</strong>: you can also explicitly set/unset qwen3's "think mode" by prepending <strong>/think</strong>
or <strong>/no_think</strong> to the prompt).
</li>
<li><strong>Run:</strong>
Click on the <strong>Run Agent</strong> button to send your prompt to the agent and see what happens
</li>
</ul>
</div>
<div class="config-info">
<strong>π Configuration:</strong> Config loaded from config.js
<span id="configStatus"></span>
</div>
<button onclick="initializePyodide()" id="initBtn">βοΈ Initialize Pyodide Environment</button>
<div id="initOutput">Click "Initialize Pyodide Environment" to set up the Python environment...</div>
<div class="server-config">
<h3>π Local LLM Server Configuration</h3>
<div class="input-group">
<label for="baseUrl">Base URL:</label>
<input type="text" id="baseUrl" class="slim-input" value="http://localhost:1234/v1" placeholder="Enter server base URL">
</div>
<div class="input-group">
<label for="apiKey">API Key:</label>
<input type="text" id="apiKey" class="slim-input" value="lmstudio" placeholder="Enter API key">
</div>
<div class="input-group">
<label for="modelName">Model Name:</label>
<input type="text" id="modelName" class="slim-input" value="qwen/qwen3-8b" placeholder="Enter model name">
</div>
<div class="server-presets">
<small>Quick presets:</small>
<button onclick="setOllamaDefaults()">Ollama</button>
<button onclick="setLMStudioDefaults()">LM Studio</button>
</div>
</div>
<div class="input-group">
<label for="prompt">Custom Prompt:</label>
<textarea id="prompt" placeholder="Enter your prompt here...">How many times does the letter r occur in the word strawrberrry?</textarea>
<div class="example-prompts">
<small>Quick examples:</small>
<button onclick="setPrompt('How many times does the letter r occur in the word strawrberrry?')">Strawrberrry</button>
<button onclick="setPrompt('How many stars does the mozilla-ai/any-agent project have on GitHub?')">GitHub stars</button>
<button onclick="setPrompt('What is the title of the latest post on https:\/\/aittalam.github.io, when was it published, what is it about, and what is the absolute URL of the image at the beginning of the post?\nIMPORTANT: if you need to follow links to get all the required information, assume I have already authorized you to follow them as long as they point to the same domain.')">Blog post</button>
<button onclick="setPrompt('What are 5 tv shows that are trending in 2025? Please provide the name of the show, the exact release date, the genre, and a brief description of the show.\nIMPORTANT: if you need to follow links to get all the required information, assume I have already authorized you to follow them. Always download full webpage contents.')">Trending TV Shows</button>
</div>
</div>
<button onclick="runAgent()" id="runBtn" disabled>π Run Agent</button>
<button onclick="clearAgentOutput()" id="clearAgentBtn" disabled>ποΈ Clear Agent Output</button>
<div class="running-indicator" id="runningIndicator">π Running Python code...</div>
<div id="agentOutput">Initialize the Pyodide environment first, then click "Run Agent" to test the agent</div>
</div>
<script>
</script>
</body>
</html>
|