undo
Browse files- index.html +15 -18
index.html
CHANGED
|
@@ -75,10 +75,6 @@
|
|
| 75 |
<div class="note">Note: official <a href="https://huggingface.co/google/gemma-3-270m" target="_blank" rel="noreferrer">Gemma‑3‑270M</a> is the base HF repo. A ready‑to‑use public GGUF is now available at <a href="https://huggingface.co/ggml-org/gemma-3-270m-GGUF" target="_blank" rel="noreferrer">ggml‑org/gemma‑3‑270m‑GGUF</a> (currently providing <code>gemma-3-270m-Q8_0.gguf</code> ≈292 MB). For maximum speed on low‑RAM phones, the OpenELM‑270M‑Instruct Q3_K_S option above is even lighter, but Gemma‑3‑270M offers strong quality for its size.</div>
|
| 76 |
</details>
|
| 77 |
|
| 78 |
-
<div class="row">
|
| 79 |
-
<label class="tiny">Default instructions (Gemma style)</label>
|
| 80 |
-
<input id="defaultInstr" type="text" placeholder="(optional) e.g., Answer concisely and clearly." class="grow" />
|
| 81 |
-
</div>
|
| 82 |
<div class="row">
|
| 83 |
<label>Max new tokens</label>
|
| 84 |
<input id="nPredict" type="number" min="1" max="512" step="1" value="128" />
|
|
@@ -134,7 +130,6 @@
|
|
| 134 |
const $customBox = document.getElementById('customBox');
|
| 135 |
const $customRepo = document.getElementById('customRepo');
|
| 136 |
const $customFile = document.getElementById('customFile');
|
| 137 |
-
const $defaultInstr = document.getElementById('defaultInstr');
|
| 138 |
|
| 139 |
// ——— State ———
|
| 140 |
const decoder = new TextDecoder();
|
|
@@ -157,14 +152,25 @@
|
|
| 157 |
}
|
| 158 |
};
|
| 159 |
|
| 160 |
-
const messages = [];
|
| 161 |
|
| 162 |
// ——— Chat template for Gemma IT ———
|
| 163 |
const GEMMA_JINJA = `{{ bos_token }}
|
| 164 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
{%- set role = (message['role'] == 'assistant') and 'model' or message['role'] -%}
|
| 166 |
<start_of_turn>{{ role }}
|
| 167 |
-
{{ (message['content'] if message['content'] is string else message['content'][0]['text']) | trim }}<end_of_turn>
|
| 168 |
{%- endfor -%}
|
| 169 |
{%- if add_generation_prompt -%}
|
| 170 |
<start_of_turn>model
|
|
@@ -264,16 +270,7 @@
|
|
| 264 |
if (!text) return;
|
| 265 |
await ensureLoaded();
|
| 266 |
|
| 267 |
-
|
| 268 |
-
if (isGemmaSelected()) {
|
| 269 |
-
const instr = ($defaultInstr.value || '').trim();
|
| 270 |
-
if (instr) composed = instr + "
|
| 271 |
-
|
| 272 |
-
" + composed;
|
| 273 |
-
} else {
|
| 274 |
-
if (messages.length === 0 && sysPrompt) messages.unshift({ role: 'system', content: sysPrompt });
|
| 275 |
-
}
|
| 276 |
-
messages.push({ role: 'user', content: composed });
|
| 277 |
const userBubble = ui.add('user', text);
|
| 278 |
$input.value = '';
|
| 279 |
|
|
|
|
| 75 |
<div class="note">Note: official <a href="https://huggingface.co/google/gemma-3-270m" target="_blank" rel="noreferrer">Gemma‑3‑270M</a> is the base HF repo. A ready‑to‑use public GGUF is now available at <a href="https://huggingface.co/ggml-org/gemma-3-270m-GGUF" target="_blank" rel="noreferrer">ggml‑org/gemma‑3‑270m‑GGUF</a> (currently providing <code>gemma-3-270m-Q8_0.gguf</code> ≈292 MB). For maximum speed on low‑RAM phones, the OpenELM‑270M‑Instruct Q3_K_S option above is even lighter, but Gemma‑3‑270M offers strong quality for its size.</div>
|
| 76 |
</details>
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
<div class="row">
|
| 79 |
<label>Max new tokens</label>
|
| 80 |
<input id="nPredict" type="number" min="1" max="512" step="1" value="128" />
|
|
|
|
| 130 |
const $customBox = document.getElementById('customBox');
|
| 131 |
const $customRepo = document.getElementById('customRepo');
|
| 132 |
const $customFile = document.getElementById('customFile');
|
|
|
|
| 133 |
|
| 134 |
// ——— State ———
|
| 135 |
const decoder = new TextDecoder();
|
|
|
|
| 152 |
}
|
| 153 |
};
|
| 154 |
|
| 155 |
+
const messages = [ { role: "system", content: sysPrompt } ];
|
| 156 |
|
| 157 |
// ——— Chat template for Gemma IT ———
|
| 158 |
const GEMMA_JINJA = `{{ bos_token }}
|
| 159 |
+
{%- if messages[0]['role'] == 'system' -%}
|
| 160 |
+
{%- if messages[0]['content'] is string -%}
|
| 161 |
+
{%- set first_user_prefix = messages[0]['content'] + '\n\n' -%}
|
| 162 |
+
{%- else -%}
|
| 163 |
+
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '\n\n' -%}
|
| 164 |
+
{%- endif -%}
|
| 165 |
+
{%- set loop_messages = messages[1:] -%}
|
| 166 |
+
{%- else -%}
|
| 167 |
+
{%- set first_user_prefix = "" -%}
|
| 168 |
+
{%- set loop_messages = messages -%}
|
| 169 |
+
{%- endif -%}
|
| 170 |
+
{%- for message in loop_messages -%}
|
| 171 |
{%- set role = (message['role'] == 'assistant') and 'model' or message['role'] -%}
|
| 172 |
<start_of_turn>{{ role }}
|
| 173 |
+
{{ (loop.first and first_user_prefix or '') ~ (message['content'] if message['content'] is string else message['content'][0]['text']) | trim }}<end_of_turn>
|
| 174 |
{%- endfor -%}
|
| 175 |
{%- if add_generation_prompt -%}
|
| 176 |
<start_of_turn>model
|
|
|
|
| 270 |
if (!text) return;
|
| 271 |
await ensureLoaded();
|
| 272 |
|
| 273 |
+
messages.push({ role: 'user', content: text });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
const userBubble = ui.add('user', text);
|
| 275 |
$input.value = '';
|
| 276 |
|