Skip to content

Commit 4aa0fe6

Browse files
author
Mikel Echeverria
committed
feat: Agregar selección de modelo en index.html
1 parent 81fb39d commit 4aa0fe6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

index.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,11 @@ <h1>ChatGPT 100% local con WebGPU</h1>
457457
alert('Tu navegador no soporta WebGPU. Por favor, utiliza un navegador compatible como Chrome o Firefox. O tu dispositivo no soporta WebGPU.');
458458
}
459459

460-
import { CreateMLCEngine } from "https://esm.run/@mlc-ai/web-llm"; // Comentar esta línea si quieres desactivar el modelo
461-
462460
// https://github.com/mlc-ai/web-llm/blob/main/src/config.ts#L293 para ver los modelos disponibles
463-
const SELECTED_MODEL = 'Phi-3.5-mini-instruct-q4f16_1-MLC'; // Cambiar por el modelo que quieras usar usando el model_id
461+
const MODELS = {
462+
'Phi3.5 mini - Rápido': 'Phi-3.5-mini-instruct-q4f16_1-MLC',
463+
'LLama3.1 - Inteligente': 'Llama-3.1-8B-Instruct-q4f32_1-MLC-1k',
464+
};
464465

465466
const $ = el => document.querySelector(el);
466467

@@ -471,14 +472,31 @@ <h1>ChatGPT 100% local con WebGPU</h1>
471472
const $container = $('main');
472473
const $button = $('button');
473474
const $loadingMessage = $('small');
475+
const $modelSelect = document.getElementById('model-select');
476+
477+
// Llenar el select con los modelos disponibles
478+
for (const [key, value] of Object.entries(MODELS)) {
479+
const option = document.createElement('option');
480+
option.value = value;
481+
option.textContent = key;
482+
$modelSelect.appendChild(option);
483+
}
484+
485+
let SELECTED_MODEL = await new Promise((resolve) => {
486+
$modelSelect.addEventListener('change', () => {
487+
resolve($modelSelect.value);
488+
});
489+
});
490+
491+
import { CreateMLCEngine } from "https://esm.run/@mlc-ai/web-llm"; // Comentar esta línea si quieres desactivar el modelo
474492

475493
// Cargar el modelo
476494
const engine = await CreateMLCEngine(
477495
SELECTED_MODEL,
478496
{
479497
initProgressCallback: (info) => {
480498
console.log(info);
481-
$loadingMessage.textContent = `Cargando modelo: ${(info.progress * 100).toFixed(0)}%`;
499+
$button.textContent = `Cargando modelo: ${(info.progress * 100).toFixed(0)}%`;
482500
if (info.progress === 1) {
483501
$button.removeAttribute('disabled');
484502
}

0 commit comments

Comments
 (0)