Upload bundle.js
Browse files
bundle.js
CHANGED
|
@@ -8989,99 +8989,14 @@ WebGPU throws: "${t8.message}"`);
|
|
| 8989 |
}
|
| 8990 |
var MODEL_PATHS = [
|
| 8991 |
{
|
| 8992 |
-
name: "
|
| 8993 |
-
hfUrl: "https://huggingface.co/
|
| 8994 |
-
localUrl: "./models/
|
| 8995 |
},
|
| 8996 |
{
|
| 8997 |
-
name: "
|
| 8998 |
-
hfUrl: "https://huggingface.co/litert-community/
|
| 8999 |
-
localUrl: "./models/
|
| 9000 |
-
},
|
| 9001 |
-
{
|
| 9002 |
-
name: "Gemma3 1B IT int8",
|
| 9003 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-1B-IT/resolve/main/gemma3-1b-it-int8-web.task",
|
| 9004 |
-
localUrl: "./models/gemma3-1b-it-int8-web.task"
|
| 9005 |
-
},
|
| 9006 |
-
{
|
| 9007 |
-
name: "Gemma3 1B IT int4",
|
| 9008 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-1B-IT/resolve/main/gemma3-1b-it-int4-web.task",
|
| 9009 |
-
localUrl: "./models/gemma3-1b-it-int4-web.task"
|
| 9010 |
-
},
|
| 9011 |
-
{
|
| 9012 |
-
name: "Gemma3 1B IT q4_0",
|
| 9013 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-1B-IT/resolve/main/gemma3-1b-it-q4_0-web.task",
|
| 9014 |
-
localUrl: "./models/gemma3-1b-it-q4_0-web.task"
|
| 9015 |
-
},
|
| 9016 |
-
{
|
| 9017 |
-
name: "Gemma3 4B IT int8",
|
| 9018 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-4B-IT/resolve/main/gemma3-4b-it-int8-web.task",
|
| 9019 |
-
localUrl: "./models/gemma3-4b-it-int8-web.task"
|
| 9020 |
-
},
|
| 9021 |
-
{
|
| 9022 |
-
name: "Gemma3 4B IT int4",
|
| 9023 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-4B-IT/resolve/main/gemma3-4b-it-int4-web.task",
|
| 9024 |
-
localUrl: "./models/gemma3-4b-it-int4-web.task"
|
| 9025 |
-
},
|
| 9026 |
-
{
|
| 9027 |
-
name: "Gemma3 4B IT q4_0",
|
| 9028 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-4B-IT/resolve/main/gemma3-4b-it-q4_0-web.task",
|
| 9029 |
-
localUrl: "./models/gemma3-4b-it-q4_0-web.task"
|
| 9030 |
-
},
|
| 9031 |
-
{
|
| 9032 |
-
name: "Gemma3 12B IT int8",
|
| 9033 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-12B-IT/resolve/main/gemma3-12b-it-int8-web.task",
|
| 9034 |
-
localUrl: "./models/gemma3-12b-it-int8-web.task"
|
| 9035 |
-
},
|
| 9036 |
-
{
|
| 9037 |
-
name: "Gemma3 12B IT int4",
|
| 9038 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-12B-IT/resolve/main/gemma3-12b-it-int4-web.task",
|
| 9039 |
-
localUrl: "./models/gemma3-12b-it-int4-web.task"
|
| 9040 |
-
},
|
| 9041 |
-
{
|
| 9042 |
-
name: "Gemma3 12B IT q4_0",
|
| 9043 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-12B-IT/resolve/main/gemma3-12b-it-q4_0-web.task",
|
| 9044 |
-
localUrl: "./models/gemma3-12b-it-q4_0-web.task"
|
| 9045 |
-
},
|
| 9046 |
-
{
|
| 9047 |
-
name: "Gemma3 27B IT int8",
|
| 9048 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-27B-IT/resolve/main/gemma3-27b-it-int8-web.task",
|
| 9049 |
-
localUrl: "./models/gemma3-27b-it-int8-web.task"
|
| 9050 |
-
},
|
| 9051 |
-
{
|
| 9052 |
-
name: "Gemma3 27B IT q4_0",
|
| 9053 |
-
hfUrl: "https://huggingface.co/litert-community/Gemma3-27B-IT/resolve/main/gemma3-27b-it-q4_0-web.task",
|
| 9054 |
-
localUrl: "./models/gemma3-27b-it-q4_0-web.task"
|
| 9055 |
-
},
|
| 9056 |
-
{
|
| 9057 |
-
name: "Gemma3n E2B IT int4",
|
| 9058 |
-
hfUrl: "https://huggingface.co/google/gemma-3n-E2B-it-litert-lm/resolve/main/gemma-3n-E2B-it-int4-Web.litertlm",
|
| 9059 |
-
localUrl: "./models/gemma-3n-E2B-it-int4-Web.litertlm"
|
| 9060 |
-
},
|
| 9061 |
-
{
|
| 9062 |
-
name: "Gemma3n E4B IT int4",
|
| 9063 |
-
hfUrl: "https://huggingface.co/google/gemma-3n-E4B-it-litert-lm/resolve/main/gemma-3n-E4B-it-int4-Web.litertlm",
|
| 9064 |
-
localUrl: "./models/gemma-3n-E4B-it-int4-Web.litertlm"
|
| 9065 |
-
},
|
| 9066 |
-
{
|
| 9067 |
-
name: "TranslateGemma 4B IT int8",
|
| 9068 |
-
hfUrl: "https://huggingface.co/litert-community/TranslateGemma-4B-IT/resolve/main/translategemma-4b-it-int8-web.task",
|
| 9069 |
-
localUrl: "./models/translategemma-4b-it-int8-web.task"
|
| 9070 |
-
},
|
| 9071 |
-
{
|
| 9072 |
-
name: "TranslateGemma 12B IT int8",
|
| 9073 |
-
hfUrl: "https://huggingface.co/litert-community/TranslateGemma-12B-IT/resolve/main/translategemma-12b-it-int8-web.task",
|
| 9074 |
-
localUrl: "./models/translategemma-12b-it-int8-web.task"
|
| 9075 |
-
},
|
| 9076 |
-
{
|
| 9077 |
-
name: "TranslateGemma 27B IT int8",
|
| 9078 |
-
hfUrl: "https://huggingface.co/litert-community/TranslateGemma-27B-IT/resolve/main/translategemma-27b-it-int8-web.task",
|
| 9079 |
-
localUrl: "./models/translategemma-27b-it-int8-web.task"
|
| 9080 |
-
},
|
| 9081 |
-
{
|
| 9082 |
-
name: "MedGemma 27B IT int8",
|
| 9083 |
-
hfUrl: "https://huggingface.co/litert-community/MedGemma-27B-IT/resolve/main/medgemma-27b-it-int8-web.task",
|
| 9084 |
-
localUrl: "./models/medgemma-27b-it-int8-web.task"
|
| 9085 |
}
|
| 9086 |
];
|
| 9087 |
function getModelUrl(model) {
|
|
@@ -9308,294 +9223,6 @@ WebGPU throws: "${t8.message}"`);
|
|
| 9308 |
return hub.oauthHandleRedirectIfPresent(...args);
|
| 9309 |
};
|
| 9310 |
|
| 9311 |
-
// src/code_sandbox.ts
|
| 9312 |
-
var _CodeSandbox = class _CodeSandbox {
|
| 9313 |
-
// 5 seconds
|
| 9314 |
-
constructor() {
|
| 9315 |
-
this.worker = null;
|
| 9316 |
-
this.workerScript = `
|
| 9317 |
-
self.onmessage = function(event) {
|
| 9318 |
-
const code = event.data;
|
| 9319 |
-
const consoleMessages = [];
|
| 9320 |
-
|
| 9321 |
-
const originalConsole = {
|
| 9322 |
-
log: self.console.log,
|
| 9323 |
-
warn: self.console.warn,
|
| 9324 |
-
error: self.console.error,
|
| 9325 |
-
};
|
| 9326 |
-
|
| 9327 |
-
const captureConsoleMessage = (type, ...args) => {
|
| 9328 |
-
const text = args.map(arg => {
|
| 9329 |
-
if (arg instanceof Error) return arg.stack || arg.toString();
|
| 9330 |
-
if (typeof arg === 'object' && arg !== null) {
|
| 9331 |
-
try {
|
| 9332 |
-
return JSON.stringify(arg);
|
| 9333 |
-
} catch (e) {
|
| 9334 |
-
return typeof arg.toString === 'function' ? arg.toString() : '[Unstringifiable Object]';
|
| 9335 |
-
}
|
| 9336 |
-
}
|
| 9337 |
-
return String(arg);
|
| 9338 |
-
}).join(' ');
|
| 9339 |
-
consoleMessages.push({ type, text });
|
| 9340 |
-
// originalConsole[type].apply(self.console, args); // Optional: log to worker's console
|
| 9341 |
-
};
|
| 9342 |
-
|
| 9343 |
-
self.console.log = (...args) => captureConsoleMessage('log', ...args);
|
| 9344 |
-
self.console.warn = (...args) => captureConsoleMessage('warn', ...args);
|
| 9345 |
-
self.console.error = (...args) => captureConsoleMessage('error', ...args);
|
| 9346 |
-
|
| 9347 |
-
let resultPayload = {
|
| 9348 |
-
resultAsString: undefined,
|
| 9349 |
-
error: undefined,
|
| 9350 |
-
consoleMessages: consoleMessages,
|
| 9351 |
-
};
|
| 9352 |
-
|
| 9353 |
-
try {
|
| 9354 |
-
const result = eval(code);
|
| 9355 |
-
if (typeof result === 'undefined') {
|
| 9356 |
-
resultPayload.resultAsString = 'undefined';
|
| 9357 |
-
} else {
|
| 9358 |
-
try {
|
| 9359 |
-
resultPayload.resultAsString = String(result);
|
| 9360 |
-
} catch (e_to_string) {
|
| 9361 |
-
const err = e_to_string instanceof Error ? e_to_string : new Error(String(e_to_string));
|
| 9362 |
-
resultPayload.resultAsString = \`[Error converting result to string: \${err.message}]\`;
|
| 9363 |
-
consoleMessages.push({ type: 'error', text: \`Error converting result to string: \${err.message}\` });
|
| 9364 |
-
}
|
| 9365 |
-
}
|
| 9366 |
-
} catch (e) {
|
| 9367 |
-
const err = e instanceof Error ? e : new Error(String(e));
|
| 9368 |
-
resultPayload.error = err.stack || err.toString();
|
| 9369 |
-
consoleMessages.push({ type: 'error', text: \`Execution Error: \${resultPayload.error}\` });
|
| 9370 |
-
} finally {
|
| 9371 |
-
self.console.log = originalConsole.log;
|
| 9372 |
-
self.console.warn = originalConsole.warn;
|
| 9373 |
-
self.console.error = originalConsole.error;
|
| 9374 |
-
self.postMessage(resultPayload);
|
| 9375 |
-
}
|
| 9376 |
-
};
|
| 9377 |
-
`;
|
| 9378 |
-
this.initWorker();
|
| 9379 |
-
}
|
| 9380 |
-
initWorker() {
|
| 9381 |
-
if (this.worker) {
|
| 9382 |
-
try {
|
| 9383 |
-
this.worker.terminate();
|
| 9384 |
-
} catch (e8) {
|
| 9385 |
-
console.warn("Error terminating existing worker during re-initialization:", e8);
|
| 9386 |
-
}
|
| 9387 |
-
this.worker = null;
|
| 9388 |
-
}
|
| 9389 |
-
try {
|
| 9390 |
-
const blob = new Blob([this.workerScript], { type: "application/javascript" });
|
| 9391 |
-
const workerUrl = URL.createObjectURL(blob);
|
| 9392 |
-
this.worker = new Worker(workerUrl);
|
| 9393 |
-
URL.revokeObjectURL(workerUrl);
|
| 9394 |
-
return true;
|
| 9395 |
-
} catch (error) {
|
| 9396 |
-
console.error("Failed to initialize Web Worker:", error);
|
| 9397 |
-
this.worker = null;
|
| 9398 |
-
return false;
|
| 9399 |
-
}
|
| 9400 |
-
}
|
| 9401 |
-
/**
|
| 9402 |
-
* Executes arbitrary JavaScript code in a Web Worker with a timeout.
|
| 9403 |
-
* @param code The JavaScript code string to execute.
|
| 9404 |
-
* @param timeoutMs The maximum time (in milliseconds) to allow for execution.
|
| 9405 |
-
* Defaults to 5000ms (5 seconds).
|
| 9406 |
-
* @returns A Promise that resolves with a SandboxResult object.
|
| 9407 |
-
*/
|
| 9408 |
-
run(code, timeoutMs = _CodeSandbox.DEFAULT_TIMEOUT_MS) {
|
| 9409 |
-
return new Promise((resolve) => {
|
| 9410 |
-
if (!this.worker) {
|
| 9411 |
-
if (!this.initWorker()) {
|
| 9412 |
-
resolve({
|
| 9413 |
-
error: "Web Worker is not available and could not be re-initialized.",
|
| 9414 |
-
consoleMessages: []
|
| 9415 |
-
});
|
| 9416 |
-
return;
|
| 9417 |
-
}
|
| 9418 |
-
}
|
| 9419 |
-
const workerForThisRun = this.worker;
|
| 9420 |
-
let timeoutId = null;
|
| 9421 |
-
const cleanupAndResolve = (result) => {
|
| 9422 |
-
if (timeoutId !== null) {
|
| 9423 |
-
clearTimeout(timeoutId);
|
| 9424 |
-
timeoutId = null;
|
| 9425 |
-
}
|
| 9426 |
-
if (workerForThisRun && typeof workerForThisRun.removeEventListener === "function") {
|
| 9427 |
-
try {
|
| 9428 |
-
workerForThisRun.removeEventListener("message", messageHandlerWrapper);
|
| 9429 |
-
workerForThisRun.removeEventListener("error", errorHandlerWrapper);
|
| 9430 |
-
} catch (e8) {
|
| 9431 |
-
console.warn("Error removing event listeners during cleanup:", e8);
|
| 9432 |
-
}
|
| 9433 |
-
}
|
| 9434 |
-
resolve(result);
|
| 9435 |
-
};
|
| 9436 |
-
const messageHandlerWrapper = (event) => {
|
| 9437 |
-
cleanupAndResolve(event.data);
|
| 9438 |
-
};
|
| 9439 |
-
const errorHandlerWrapper = (event) => {
|
| 9440 |
-
cleanupAndResolve({
|
| 9441 |
-
error: `Worker script error: ${event.message} (at ${event.filename}:${event.lineno})`,
|
| 9442 |
-
consoleMessages: []
|
| 9443 |
-
// Console messages from eval'd code likely won't be available
|
| 9444 |
-
});
|
| 9445 |
-
};
|
| 9446 |
-
timeoutId = setTimeout(() => {
|
| 9447 |
-
timeoutId = null;
|
| 9448 |
-
try {
|
| 9449 |
-
workerForThisRun.terminate();
|
| 9450 |
-
} catch (e8) {
|
| 9451 |
-
console.warn("Error terminating worker on timeout:", e8);
|
| 9452 |
-
}
|
| 9453 |
-
console.warn(`Sandbox worker for this run terminated due to timeout (${timeoutMs}ms).`);
|
| 9454 |
-
if (this.worker === workerForThisRun) {
|
| 9455 |
-
this.worker = null;
|
| 9456 |
-
}
|
| 9457 |
-
try {
|
| 9458 |
-
workerForThisRun.removeEventListener("message", messageHandlerWrapper);
|
| 9459 |
-
workerForThisRun.removeEventListener("error", errorHandlerWrapper);
|
| 9460 |
-
} catch (_e2) {
|
| 9461 |
-
}
|
| 9462 |
-
resolve({
|
| 9463 |
-
error: `Execution timed out after ${timeoutMs}ms. The worker for this run has been terminated.`,
|
| 9464 |
-
consoleMessages: []
|
| 9465 |
-
// Console messages from worker are lost on timeout
|
| 9466 |
-
});
|
| 9467 |
-
}, timeoutMs);
|
| 9468 |
-
workerForThisRun.addEventListener("message", messageHandlerWrapper);
|
| 9469 |
-
workerForThisRun.addEventListener("error", errorHandlerWrapper);
|
| 9470 |
-
try {
|
| 9471 |
-
workerForThisRun.postMessage(code);
|
| 9472 |
-
} catch (e8) {
|
| 9473 |
-
const err = e8 instanceof Error ? e8 : new Error(String(e8));
|
| 9474 |
-
cleanupAndResolve({
|
| 9475 |
-
error: `Failed to send code to worker: ${err.message}`,
|
| 9476 |
-
consoleMessages: []
|
| 9477 |
-
});
|
| 9478 |
-
}
|
| 9479 |
-
});
|
| 9480 |
-
}
|
| 9481 |
-
/**
|
| 9482 |
-
* Terminates the current Web Worker, if active.
|
| 9483 |
-
* Subsequent calls to run() will attempt to create a new worker.
|
| 9484 |
-
*/
|
| 9485 |
-
terminate() {
|
| 9486 |
-
if (this.worker) {
|
| 9487 |
-
this.worker.terminate();
|
| 9488 |
-
this.worker = null;
|
| 9489 |
-
console.log("Sandbox worker explicitly terminated.");
|
| 9490 |
-
}
|
| 9491 |
-
}
|
| 9492 |
-
};
|
| 9493 |
-
_CodeSandbox.DEFAULT_TIMEOUT_MS = 5e3;
|
| 9494 |
-
var CodeSandbox = _CodeSandbox;
|
| 9495 |
-
|
| 9496 |
-
// src/personas/js_tool_use.ts
|
| 9497 |
-
var EVAL_TAG = "```js-eval";
|
| 9498 |
-
var MAX_CONSOLE_LOG_CHARS = 1e3;
|
| 9499 |
-
var JS_TOOL_USE = {
|
| 9500 |
-
name: "JS Interpreter Tool Use",
|
| 9501 |
-
instructions: [
|
| 9502 |
-
{
|
| 9503 |
-
role: "system",
|
| 9504 |
-
text: `You are a helpful assistant with access to a javascript interpreter. Use the interpreter when necessary to provide an accurate answer to the user.
|
| 9505 |
-
|
| 9506 |
-
If you choose to run an expression in the js interpreter, include a javascript code block in your response, like this:
|
| 9507 |
-
${EVAL_TAG}
|
| 9508 |
-
12345 * 5432;
|
| 9509 |
-
\`\`\`
|
| 9510 |
-
|
| 9511 |
-
After you respond with a code block, the system will execute your code and give you the response, at which point you will have the opportunity to read it and respond to the user or run more javascript code if necessary. Note that the user does not see the javascript expressions you write, nor do they see the response (including \`console.log\` statements). Additionally, you will only receive the result of the expression or an error message if it fails. You won't see any \`console.log\` messages.
|
| 9512 |
-
|
| 9513 |
-
You may make multiple calls to the javascript interpreter before replying to the user.
|
| 9514 |
-
`
|
| 9515 |
-
},
|
| 9516 |
-
{
|
| 9517 |
-
role: "user",
|
| 9518 |
-
text: "What is the 50th Fibonacci number?"
|
| 9519 |
-
},
|
| 9520 |
-
{
|
| 9521 |
-
role: "model",
|
| 9522 |
-
text: `${EVAL_TAG}
|
| 9523 |
-
function fibonacci(n) {
|
| 9524 |
-
if (n <= 1) {
|
| 9525 |
-
return n;
|
| 9526 |
-
}
|
| 9527 |
-
|
| 9528 |
-
let a = 0;
|
| 9529 |
-
let b = 1;
|
| 9530 |
-
|
| 9531 |
-
for (let i = 2; i <= n; i++) {
|
| 9532 |
-
const temp = a + b;
|
| 9533 |
-
a = b;
|
| 9534 |
-
b = temp;
|
| 9535 |
-
}
|
| 9536 |
-
|
| 9537 |
-
return b;
|
| 9538 |
-
}
|
| 9539 |
-
|
| 9540 |
-
fibonacci(123);
|
| 9541 |
-
\`\`\``
|
| 9542 |
-
},
|
| 9543 |
-
{
|
| 9544 |
-
role: "system",
|
| 9545 |
-
text: "12586269025"
|
| 9546 |
-
},
|
| 9547 |
-
{
|
| 9548 |
-
role: "model",
|
| 9549 |
-
text: `The 50th Fibonacci number is 12586269025.`
|
| 9550 |
-
}
|
| 9551 |
-
],
|
| 9552 |
-
promptTemplate: {
|
| 9553 |
-
...BASE_GEMMA3_PERSONA.promptTemplate,
|
| 9554 |
-
system: {
|
| 9555 |
-
pre: "<start_of_turn>system\n",
|
| 9556 |
-
post: "<end_of_turn>\n"
|
| 9557 |
-
}
|
| 9558 |
-
},
|
| 9559 |
-
tools: {
|
| 9560 |
-
[EVAL_TAG]: async (code) => {
|
| 9561 |
-
try {
|
| 9562 |
-
const sandbox = new CodeSandbox();
|
| 9563 |
-
const regex = /```js-eval\n([\s\S]*?)\n```/g;
|
| 9564 |
-
const matches = [...code.matchAll(regex)];
|
| 9565 |
-
const match = matches[0]?.[1];
|
| 9566 |
-
if (match == null) {
|
| 9567 |
-
throw new Error("Improper code block formatting");
|
| 9568 |
-
}
|
| 9569 |
-
const result = await sandbox.run(match);
|
| 9570 |
-
let consoleMessages = result.consoleMessages.map((message) => `${message.type}: ${message.text}`).join("\n");
|
| 9571 |
-
if (consoleMessages.length > MAX_CONSOLE_LOG_CHARS) {
|
| 9572 |
-
consoleMessages = consoleMessages.slice(0, MAX_CONSOLE_LOG_CHARS) + `
|
| 9573 |
-
Log truncated at ${MAX_CONSOLE_LOG_CHARS} chars. ${consoleMessages.length - MAX_CONSOLE_LOG_CHARS} remain.`;
|
| 9574 |
-
}
|
| 9575 |
-
const error = result.error ? `
|
| 9576 |
-
|
| 9577 |
-
Error: ${result.error}` : "";
|
| 9578 |
-
return `Result: ${result.resultAsString}
|
| 9579 |
-
|
| 9580 |
-
Console messages:
|
| 9581 |
-
${consoleMessages}${error}`;
|
| 9582 |
-
} catch (e8) {
|
| 9583 |
-
if (e8 instanceof Error) {
|
| 9584 |
-
return e8.stack ?? String(e8);
|
| 9585 |
-
} else {
|
| 9586 |
-
return `Thrown: ${String(e8)}`;
|
| 9587 |
-
}
|
| 9588 |
-
}
|
| 9589 |
-
}
|
| 9590 |
-
}
|
| 9591 |
-
};
|
| 9592 |
-
|
| 9593 |
-
// src/personas.ts
|
| 9594 |
-
var PERSONAS = [
|
| 9595 |
-
BASE_GEMMA3_PERSONA,
|
| 9596 |
-
JS_TOOL_USE
|
| 9597 |
-
];
|
| 9598 |
-
|
| 9599 |
// src/custom_dropdown.ts
|
| 9600 |
var CustomDropdown = class extends i4 {
|
| 9601 |
constructor() {
|
|
@@ -9710,8 +9337,6 @@ ${consoleMessages}${error}`;
|
|
| 9710 |
var LlmOptions = class extends i4 {
|
| 9711 |
constructor() {
|
| 9712 |
super(...arguments);
|
| 9713 |
-
this.personas = PERSONAS;
|
| 9714 |
-
this.selectedPersonaName = PERSONAS[0]?.name ?? "";
|
| 9715 |
this.cachedModels = /* @__PURE__ */ new Map();
|
| 9716 |
this.options = structuredClone(DEFAULT_OPTIONS);
|
| 9717 |
this.isLoggedIn = !!localStorage.getItem("oauth");
|
|
@@ -9737,22 +9362,6 @@ ${consoleMessages}${error}`;
|
|
| 9737 |
});
|
| 9738 |
this.dispatchEvent(event);
|
| 9739 |
}
|
| 9740 |
-
dispatchPersonaChanged(persona) {
|
| 9741 |
-
const event = new CustomEvent("persona-changed", {
|
| 9742 |
-
detail: persona,
|
| 9743 |
-
bubbles: true,
|
| 9744 |
-
composed: true
|
| 9745 |
-
});
|
| 9746 |
-
this.dispatchEvent(event);
|
| 9747 |
-
}
|
| 9748 |
-
handlePersonaChange(e8) {
|
| 9749 |
-
const selectedName = e8.target.value;
|
| 9750 |
-
const selectedPersona = this.personas.find((p5) => p5.name === selectedName);
|
| 9751 |
-
if (selectedPersona) {
|
| 9752 |
-
this.selectedPersonaName = selectedName;
|
| 9753 |
-
this.dispatchPersonaChanged(selectedPersona);
|
| 9754 |
-
}
|
| 9755 |
-
}
|
| 9756 |
handleTemperatureChange(e8) {
|
| 9757 |
this.options = produce(this.options, (options) => {
|
| 9758 |
options.temperature = parseFloat(e8.target.value);
|
|
@@ -9810,11 +9419,6 @@ ${consoleMessages}${error}`;
|
|
| 9810 |
getFileName(path) {
|
| 9811 |
return path.split("/").pop();
|
| 9812 |
}
|
| 9813 |
-
renderPersonaOptions() {
|
| 9814 |
-
return this.personas.map(
|
| 9815 |
-
(persona) => b2`<option value="${persona.name}">${persona.name}</option>`
|
| 9816 |
-
);
|
| 9817 |
-
}
|
| 9818 |
handleModelFileChange(e8) {
|
| 9819 |
const file = e8.target.files?.[0];
|
| 9820 |
if (file) {
|
|
@@ -9885,16 +9489,6 @@ ${consoleMessages}${error}`;
|
|
| 9885 |
` : ""}
|
| 9886 |
`}
|
| 9887 |
</div>
|
| 9888 |
-
<div>
|
| 9889 |
-
<label for="persona-select">Prompt Template:</label>
|
| 9890 |
-
<select
|
| 9891 |
-
id="persona-select"
|
| 9892 |
-
.value=${this.selectedPersonaName}
|
| 9893 |
-
@change=${this.handlePersonaChange}
|
| 9894 |
-
>
|
| 9895 |
-
${this.renderPersonaOptions()}
|
| 9896 |
-
</select>
|
| 9897 |
-
</div>
|
| 9898 |
<div>
|
| 9899 |
<label for="temperature"
|
| 9900 |
>Temperature: ${this.options.temperature.toFixed(2)}</label
|
|
@@ -10048,12 +9642,6 @@ ${consoleMessages}${error}`;
|
|
| 10048 |
color: #666;
|
| 10049 |
}
|
| 10050 |
`;
|
| 10051 |
-
__decorateClass([
|
| 10052 |
-
n4({ type: Array })
|
| 10053 |
-
], LlmOptions.prototype, "personas", 2);
|
| 10054 |
-
__decorateClass([
|
| 10055 |
-
n4({ type: String })
|
| 10056 |
-
], LlmOptions.prototype, "selectedPersonaName", 2);
|
| 10057 |
__decorateClass([
|
| 10058 |
n4({ type: Array })
|
| 10059 |
], LlmOptions.prototype, "cachedModels", 2);
|
|
@@ -10101,7 +9689,7 @@ ${consoleMessages}${error}`;
|
|
| 10101 |
this.currentAppliedOptions = structuredClone(DEFAULT_OPTIONS);
|
| 10102 |
this.pendingOptions = structuredClone(DEFAULT_OPTIONS);
|
| 10103 |
this.hasPendingOptionsChanges = false;
|
| 10104 |
-
this.selectedPersona =
|
| 10105 |
this.cachedModels = /* @__PURE__ */ new Map();
|
| 10106 |
this.llmService = new LlmService();
|
| 10107 |
this.llmService.history.subscribe((history) => {
|
|
@@ -10112,6 +9700,7 @@ ${consoleMessages}${error}`;
|
|
| 10112 |
this.loadingProgress = progress;
|
| 10113 |
this.requestUpdate();
|
| 10114 |
});
|
|
|
|
| 10115 |
getCachedModelsInfo().then((models) => {
|
| 10116 |
this.cachedModels = models;
|
| 10117 |
});
|
|
@@ -10124,28 +9713,6 @@ ${consoleMessages}${error}`;
|
|
| 10124 |
const model = MODEL_PATHS.find((m4) => getModelUrl(m4) === modelPath);
|
| 10125 |
return model ? model.name : "custom model";
|
| 10126 |
}
|
| 10127 |
-
async handlePersonaChanged(event) {
|
| 10128 |
-
const newPersona = event.detail;
|
| 10129 |
-
if (this.selectedPersona.name === newPersona.name) {
|
| 10130 |
-
return;
|
| 10131 |
-
}
|
| 10132 |
-
console.log("Persona selected:", newPersona.name);
|
| 10133 |
-
this.isGenerating = false;
|
| 10134 |
-
this.errorMessage = null;
|
| 10135 |
-
this.selectedPersona = newPersona;
|
| 10136 |
-
this.requestUpdate();
|
| 10137 |
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
| 10138 |
-
try {
|
| 10139 |
-
this.llmService.setPersona(this.selectedPersona);
|
| 10140 |
-
console.log(`Chat context updated for persona: ${this.selectedPersona.name}`);
|
| 10141 |
-
} catch (error) {
|
| 10142 |
-
console.error("Failed to apply new persona:", error);
|
| 10143 |
-
this.errorMessage = `Failed to switch persona. Error: ${error instanceof Error ? error.message : String(error)}`;
|
| 10144 |
-
} finally {
|
| 10145 |
-
this.userInputElement?.focus();
|
| 10146 |
-
this.requestUpdate();
|
| 10147 |
-
}
|
| 10148 |
-
}
|
| 10149 |
handleOptionsChange(event) {
|
| 10150 |
const newOptionsFromChild = event.detail;
|
| 10151 |
this.pendingOptions = newOptionsFromChild;
|
|
@@ -10299,11 +9866,8 @@ ${consoleMessages}${error}`;
|
|
| 10299 |
<div class="options-container">
|
| 10300 |
<llm-options
|
| 10301 |
.options=${this.pendingOptions}
|
| 10302 |
-
.personas=${PERSONAS}
|
| 10303 |
-
.selectedPersonaName=${this.selectedPersona.name}
|
| 10304 |
.cachedModels=${this.cachedModels}
|
| 10305 |
@options-changed=${this.handleOptionsChange}
|
| 10306 |
-
@persona-changed=${this.handlePersonaChanged}
|
| 10307 |
@cached-models-changed=${this.handleCachedModelsChanged}
|
| 10308 |
?disabled=${this.isLoadingModel || this.isGenerating}
|
| 10309 |
>
|
|
@@ -10505,9 +10069,6 @@ ${consoleMessages}${error}`;
|
|
| 10505 |
__decorateClass([
|
| 10506 |
r5()
|
| 10507 |
], LlmChat.prototype, "hasPendingOptionsChanges", 2);
|
| 10508 |
-
__decorateClass([
|
| 10509 |
-
r5()
|
| 10510 |
-
], LlmChat.prototype, "selectedPersona", 2);
|
| 10511 |
__decorateClass([
|
| 10512 |
r5()
|
| 10513 |
], LlmChat.prototype, "cachedModels", 2);
|
|
|
|
| 8989 |
}
|
| 8990 |
var MODEL_PATHS = [
|
| 8991 |
{
|
| 8992 |
+
name: "Placeholder1",
|
| 8993 |
+
hfUrl: "https://huggingface.co/unsloth/gemma-3-270m/resolve/main/model.safetensors",
|
| 8994 |
+
localUrl: "./models/placeholder1-web.task"
|
| 8995 |
},
|
| 8996 |
{
|
| 8997 |
+
name: "Placeholder2",
|
| 8998 |
+
hfUrl: "https://huggingface.co/litert-community/placeholder2/resolve/main/placeholder2-web.task",
|
| 8999 |
+
localUrl: "./models/placeholder2-web.task"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9000 |
}
|
| 9001 |
];
|
| 9002 |
function getModelUrl(model) {
|
|
|
|
| 9223 |
return hub.oauthHandleRedirectIfPresent(...args);
|
| 9224 |
};
|
| 9225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9226 |
// src/custom_dropdown.ts
|
| 9227 |
var CustomDropdown = class extends i4 {
|
| 9228 |
constructor() {
|
|
|
|
| 9337 |
var LlmOptions = class extends i4 {
|
| 9338 |
constructor() {
|
| 9339 |
super(...arguments);
|
|
|
|
|
|
|
| 9340 |
this.cachedModels = /* @__PURE__ */ new Map();
|
| 9341 |
this.options = structuredClone(DEFAULT_OPTIONS);
|
| 9342 |
this.isLoggedIn = !!localStorage.getItem("oauth");
|
|
|
|
| 9362 |
});
|
| 9363 |
this.dispatchEvent(event);
|
| 9364 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9365 |
handleTemperatureChange(e8) {
|
| 9366 |
this.options = produce(this.options, (options) => {
|
| 9367 |
options.temperature = parseFloat(e8.target.value);
|
|
|
|
| 9419 |
getFileName(path) {
|
| 9420 |
return path.split("/").pop();
|
| 9421 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9422 |
handleModelFileChange(e8) {
|
| 9423 |
const file = e8.target.files?.[0];
|
| 9424 |
if (file) {
|
|
|
|
| 9489 |
` : ""}
|
| 9490 |
`}
|
| 9491 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9492 |
<div>
|
| 9493 |
<label for="temperature"
|
| 9494 |
>Temperature: ${this.options.temperature.toFixed(2)}</label
|
|
|
|
| 9642 |
color: #666;
|
| 9643 |
}
|
| 9644 |
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9645 |
__decorateClass([
|
| 9646 |
n4({ type: Array })
|
| 9647 |
], LlmOptions.prototype, "cachedModels", 2);
|
|
|
|
| 9689 |
this.currentAppliedOptions = structuredClone(DEFAULT_OPTIONS);
|
| 9690 |
this.pendingOptions = structuredClone(DEFAULT_OPTIONS);
|
| 9691 |
this.hasPendingOptionsChanges = false;
|
| 9692 |
+
this.selectedPersona = BASE_GEMMA3_PERSONA;
|
| 9693 |
this.cachedModels = /* @__PURE__ */ new Map();
|
| 9694 |
this.llmService = new LlmService();
|
| 9695 |
this.llmService.history.subscribe((history) => {
|
|
|
|
| 9700 |
this.loadingProgress = progress;
|
| 9701 |
this.requestUpdate();
|
| 9702 |
});
|
| 9703 |
+
this.llmService.setPersona(this.selectedPersona);
|
| 9704 |
getCachedModelsInfo().then((models) => {
|
| 9705 |
this.cachedModels = models;
|
| 9706 |
});
|
|
|
|
| 9713 |
const model = MODEL_PATHS.find((m4) => getModelUrl(m4) === modelPath);
|
| 9714 |
return model ? model.name : "custom model";
|
| 9715 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9716 |
handleOptionsChange(event) {
|
| 9717 |
const newOptionsFromChild = event.detail;
|
| 9718 |
this.pendingOptions = newOptionsFromChild;
|
|
|
|
| 9866 |
<div class="options-container">
|
| 9867 |
<llm-options
|
| 9868 |
.options=${this.pendingOptions}
|
|
|
|
|
|
|
| 9869 |
.cachedModels=${this.cachedModels}
|
| 9870 |
@options-changed=${this.handleOptionsChange}
|
|
|
|
| 9871 |
@cached-models-changed=${this.handleCachedModelsChanged}
|
| 9872 |
?disabled=${this.isLoadingModel || this.isGenerating}
|
| 9873 |
>
|
|
|
|
| 10069 |
__decorateClass([
|
| 10070 |
r5()
|
| 10071 |
], LlmChat.prototype, "hasPendingOptionsChanges", 2);
|
|
|
|
|
|
|
|
|
|
| 10072 |
__decorateClass([
|
| 10073 |
r5()
|
| 10074 |
], LlmChat.prototype, "cachedModels", 2);
|