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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<!-- This page is only XHTML 1.0 Transitional because target is being used in a links -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YaCy '#[clientname]#': LLM Selection</title>
#%env/templates/metas.template%#
</head>
<body id="IndexControl">
#%env/templates/header.template%#
#%env/templates/submenuIndexImport.template%#
<script>
let availableModels = [];
const downloadActivities = new Map();
let activeDownloadCount = 0;
const beforeUnloadHandler = event => {
event.preventDefault();
event.returnValue = "Model downloads are still running. Please wait until they finish.";
};
const RECOMMENDED_MODELS = [
["smollm2:360m-instruct-q4_K_M", "0.001", "0.5GB", "english-only minimalistic model for small devices", "Huggingface", "apache-2.0"],
["hf.co/mradermacher/EuroLLM-1.7B-Instruct-GGUF:Q4_K_M", "0.09", "1.5GB", "European Union - funded model, multilingual", "Various European Universities", "apache-2.0"],
["llama3.2:1b-instruct-q4_K_M", "0.18", "1.5GB", "A good 1B model", "Meta", "llama3.2"],
["llama3.2:3b-instruct-q4_K_M", "0.66", "3GB", "A good 3B model", "Meta", "llama3.2"],
["qwen3:4b-instruct-2507-q4_K_M", "7.70", "3GB", "Exceptional good 4B model", "Alibaba", "apache-2.0"],
["hf.co/mradermacher/Josiefied-Qwen3-4B-Instruct-2507-abliterated-v1-GGUF:Q4_K_M", "7.70", "3GB", "uncensored version of qwen3:4b", "huggingface.co/Goekdeniz-Guelmez", "apache-2.0"],
["hf.co/mradermacher/medgemma-4b-it-GGUF:Q4_K_M", "0.84", "4GB", "Medical Knowledge and Vision", "Google", "health-ai-developer-foundations"],
["hf.co/mradermacher/occiglot-7b-eu5-instruct-GGUF:Q4_K_M", "0.19", "5GB", "Support for top-5 EU languages (English, Spanish, French, German, and Italian)", "occiglot.eu", "apache-2.0"],
["hf.co/allenai/OLMoE-1B-7B-0125-Instruct-GGUF:Q4_K_M", "0.22", "5GB", "open and accessible training data, open-source training code, very fast", "allenai.org", "apache-2.0"],
["hf.co/bartowski/AGI-0_Art-0-8B-GGUF:Q4_K_M", "11.9", "6GB", "Exceptional good 8B model, ranking above ChatGPT-3.5", "AGI-0.com and Alibaba", "apache-2.0"],
["phi4:14b-q4_K_M", "5.24", "10GB", "Very strong, made with synthetic data", "Microsoft", "mit"],
["hf.co/mistralai/Magistral-Small-2509-GGUF:Q4_K_M", "5.18", "16GB", "European flagship model, strong multilangual, reasoning", "mistral.ai", "apache-2.0"],
["hf.co/bartowski/cognitivecomputations_Dolphin-Mistral-24B-Venice-Edition-GGUF:Q4_K_M", "", "16GB", "Uncensored multilingual european Mistral-24B for role playing", "mistral.ai and dphn.ai", "apache-2.0"],
["qwen3-vl:30b-a3b-instruct-q4_K_M", "17.33", "22GB", "Very fast, exceptional good 30B model, ranking above GPT-4-turbo, GPT-4.1-nano, GPT-o1, GPT-4o-mini", "Alibaba", "apache-2.0"]
];
/***
*** API functions to access Ollama or OpenAI endpoints (list/load/delete models)
***/
async function fetchJsonOrThrow(url, options = {}) {
const response = await fetch(url, options);
if (response.status !== 200) {
const error = new Error("Model fetch failed");
error.status = response.status;
throw error;
}
return response.json();
}
async function fetchOllamaModels(hoststub) {
return fetchJsonOrThrow(`${hoststub}/api/tags`);
}
async function deleteOllamaModel(hoststub, modelName) {
const response = await fetch(`${hoststub}/api/delete`, {
method: "DELETE",
headers: {"Accept": "application/json", "Content-Type": "application/json"},
body: JSON.stringify({ model: modelName })
});
if (response.status !== 200) {
const error = new Error(`Failed to delete model ${modelName}`);
error.status = response.status;
throw error;
}
}
async function downloadOllamaModel(hoststub, modelName) {
const response = await fetch(`${hoststub}/api/pull`, {
method: "POST",
headers: {"Accept": "application/json", "Content-Type": "application/json"},
body: JSON.stringify({ model: modelName, stream: false })
});
if (response.status !== 200) {
const error = new Error(`Failed to download model ${modelName}`);
error.status = response.status;
throw error;
}
const payload = await response.json().catch(() => null);
if (payload && payload.error) {
const error = new Error(payload.error);
error.status = response.status;
error.payload = payload;
throw error;
}
return payload;
}
async function fetchOpenAICompatibleModels(hoststub) {
return fetchJsonOrThrow(`${hoststub}/v1/models`);
}
async function requestModelsForProvider(provider, hoststub) {
return provider === "OLLAMA"
? fetchOllamaModels(hoststub)
: fetchOpenAICompatibleModels(hoststub);
}
function handleModelLoadError(provider, error) {
console.error("Error fetching models:", error);
const status = error && typeof error.status === "number" ? error.status : null;
if (status) {
const apikeyEl = document.getElementById("apikey");
apiKeyValue = apikeyEl ? apikeyEl.value.trim() : "";
if (provider !== "OLLAMA" && provider !== "LMSTUDIO" && !apiKeyValue) {
alert("an api key is required for this provider");
} else {
alert(`Failed to load models. HTTP status: ${status}`);
}
} else {
alert("Failed to load models. Check the hoststub and console for errors.");
}
}
async function loadModelList() {
availableModels = [];
const provider = document.getElementById("provider").value;
const hoststub = document.getElementById("hoststub").value;
try {
const responsej = await requestModelsForProvider(provider, hoststub);
renderAvailableModels(provider, responsej);
if (provider === "OLLAMA") {
renderRecommendedModels(hoststub);
} else {
const loadModelContainer = document.getElementById("loadModelContainer");
if (!loadModelContainer) return;
loadModelContainer.innerHTML = "";
loadModelContainer.style.display = "none";
}
} catch (error) {
handleModelLoadError(provider, error);
}
}
/***
*** Download Activity
***/
function updateBeforeUnloadGuard() {
if (activeDownloadCount > 0) {
window.addEventListener("beforeunload", beforeUnloadHandler);
} else {
window.removeEventListener("beforeunload", beforeUnloadHandler);
}
}
function getDownloadActivityElements() {
return {
container: document.getElementById("downloadActivityContainer"),
list: document.getElementById("downloadActivityList")
};
}
function addDownloadActivity(modelName) {
const { container, list } = getDownloadActivityElements();
if (!container || !list) return null;
const activityId = `download_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`;
const wrapper = document.createElement("div");
wrapper.className = "download-activity";
wrapper.dataset.activityId = activityId;
wrapper.style.marginBottom = "8px";
wrapper.style.padding = "8px";
wrapper.style.border = "1px solid #ddd";
wrapper.style.borderRadius = "4px";
wrapper.style.backgroundColor = "#f8f8f8";
const title = document.createElement("div");
title.className = "download-activity-title";
title.textContent = `Downloading ${modelName}`;
title.style.fontWeight = "bold";
title.style.marginBottom = "4px";
wrapper.appendChild(title);
const progress = document.createElement("progress");
progress.max = 100;
progress.style.width = "100%";
progress.removeAttribute("value"); // indeterminate
progress.setAttribute("aria-busy", "true");
wrapper.appendChild(progress);
const subtitle = document.createElement("div");
subtitle.className = "download-activity-subtitle";
subtitle.textContent = "Download in progress…";
subtitle.style.fontSize = "0.9em";
subtitle.style.marginTop = "4px";
wrapper.appendChild(subtitle);
list.appendChild(wrapper);
container.style.display = "block";
downloadActivities.set(activityId, wrapper);
activeDownloadCount = downloadActivities.size;
updateBeforeUnloadGuard();
return activityId;
}
function removeDownloadActivity(activityId) {
const wrapper = downloadActivities.get(activityId);
if (wrapper && wrapper.parentNode) {
wrapper.parentNode.removeChild(wrapper);
}
if (downloadActivities.has(activityId)) {
downloadActivities.delete(activityId);
activeDownloadCount = downloadActivities.size;
}
const { container, list } = getDownloadActivityElements();
if (container && list && !list.hasChildNodes()) {
container.style.display = "none";
}
updateBeforeUnloadGuard();
}
/***
*** Rendering Functions
***/
function setHoststub() {
// this is called when the user changes the provider
const provider = document.getElementById("provider").value;
const hoststubInput = document.getElementById("hoststub");
const apikeyInput = document.getElementById("apikey");
if (provider === "OLLAMA") {
hoststubInput.value = "http://localhost:11434";
} else if (provider === "LMSTUDIO") {
hoststubInput.value = "http://localhost:1234";
} else if (provider === "OPENAI") {
hoststubInput.value = "https://api.openai.com";
} else if (provider === "OPENROUTER") {
hoststubInput.value = "https://openrouter.ai/api";
} else {
hoststubInput.value = "";
}
if (!apikeyInput) return;
if (provider === "OLLAMA" || provider === "LMSTUDIO") {
apikeyInput.disabled = true;
apikeyInput.value = "";
} else {
apikeyInput.disabled = false;
}
}
async function handleModelDelete(modelName, deleteButton) {
if (!modelName) return;
const hoststubInput = document.getElementById("hoststub");
const hoststub = hoststubInput ? hoststubInput.value.trim() : "";
if (!hoststub) {
alert("A hoststub is required to delete models.");
return;
}
if (deleteButton) {
deleteButton.disabled = true;
}
try {
await deleteOllamaModel(hoststub, modelName);
} catch (error) {
const status = error && typeof error.status === "number" ? error.status : null;
const message = status
? `Failed to delete model ${modelName}. HTTP status: ${status}`
: `Error while deleting model ${modelName}. Check the console for details.`;
alert(message);
console.error("Model deletion failed:", error);
return;
} finally {
if (deleteButton) {
deleteButton.disabled = false;
}
}
try {
await loadModelList();
} catch (refreshError) {
console.error("Failed to refresh models after deletion:", refreshError);
}
}
function renderAvailableModels(provider, payload) {
// called when the model list was loaded
const availableModelsContainer = document.getElementById("availableModelsContainer");
if (!availableModelsContainer) return;
availableModelsContainer.innerHTML = "<legend>Available Models</legend>";
availableModelsContainer.style.display = "none";
const models = provider === "OLLAMA" ? (payload.models || []) : (payload.data || []);
const getId = provider === "OLLAMA" ? m => m.model : m => m.id;
const frag = document.createDocumentFragment();
const table = document.createElement("table");
table.className = "table table-striped";
const thead = document.createElement("thead");
thead.className = "thead-dark";
const headerRow = document.createElement("tr");
["Model", "Actions"].forEach(h => {
const th = document.createElement("th");
th.textContent = h;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
const tbody = document.createElement("tbody");
models.forEach(m => {
const id = getId(m);
if (!id) return;
availableModels.push(id);
const tr = document.createElement("tr");
const tdMain = document.createElement("td");
tdMain.textContent = id;
tr.appendChild(tdMain);
const actionsTd = document.createElement("td");
const deleteBtn = document.createElement("button");
deleteBtn.type = "button";
deleteBtn.className = "btn btn-danger btn-sm";
deleteBtn.textContent = "Delete";
deleteBtn.style.padding = "2px 8px";
deleteBtn.style.lineHeight = "1.2";
if (provider === "OLLAMA") {
deleteBtn.addEventListener("click", () => handleModelDelete(id, deleteBtn));
} else {
deleteBtn.disabled = true;
deleteBtn.title = "Model management is only supported for Ollama.";
}
actionsTd.appendChild(deleteBtn);
tr.appendChild(actionsTd);
tbody.appendChild(tr);
});
if (tbody.hasChildNodes()) {
table.appendChild(tbody);
frag.appendChild(table);
}
const hasModels = tbody.hasChildNodes();
availableModelsContainer.appendChild(frag);
availableModelsContainer.style.display = hasModels ? "block" : "none";
}
function renderRecommendedModels(hoststub) {
// called when the model list was loaded and the diff to the recommended model list is displayed
const loadModelContainer = document.getElementById("loadModelContainer");
if (!loadModelContainer) return;
loadModelContainer.innerHTML = "<legend>Recommended Models</legend>";
loadModelContainer.style.display = "none";
const downloadableModels = RECOMMENDED_MODELS.filter(m => m && !availableModels.includes(m[0]));
if (!downloadableModels.length) return;
const table = document.createElement("table");
table.className = "table table-striped";
const thead = document.createElement("thead");
thead.className = "thead-dark";
const headerRow = document.createElement("tr");
["Model", "Ranking", "Size", "Description", "Provider", "License", "Actions"].forEach(h => {
const th = document.createElement("th");
th.textContent = h;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
const frag = document.createDocumentFragment();
downloadableModels.forEach(m => {
const modelName = m[0];
const tr = document.createElement("tr");
const tdMain = document.createElement("td");
tdMain.textContent = modelName;
tr.appendChild(tdMain);
[m[1], m[2], m[3], m[4], m[5]].forEach(text => {
const td = document.createElement("td");
td.textContent = text;
tr.appendChild(td);
});
const actionsTd = document.createElement("td");
const downloadBtn = document.createElement("button");
downloadBtn.type = "button";
downloadBtn.className = "btn btn-primary btn-sm";
downloadBtn.textContent = "Download";
downloadBtn.addEventListener("click", async () => {
const activityId = addDownloadActivity(modelName);
downloadBtn.disabled = true;
try {
await downloadOllamaModel(hoststub, modelName);
console.log(`Model ${modelName} is now available on server ${hoststub}.`);
} catch (err) {
const status = err && typeof err.status === "number" ? err.status : null;
const message = status
? `Failed to download model ${modelName}. HTTP status: ${status}`
: `Error pulling model ${modelName} from server ${hoststub}. Check the console for details.`;
alert(message);
console.error("Error during model pull request:", err);
} finally {
downloadBtn.disabled = false;
if (activityId) {
removeDownloadActivity(activityId);
}
try {
await loadModelList();
} catch (refreshError) {
console.error("Failed to refresh models after download:", refreshError);
}
}
});
actionsTd.appendChild(downloadBtn);
tr.appendChild(actionsTd);
frag.appendChild(tr);
});
const tbody = document.createElement("tbody");
tbody.appendChild(frag);
table.appendChild(tbody);
loadModelContainer.appendChild(table);
loadModelContainer.style.display = "block";
}
</script>
<h2>LLM Selection</h2>
<form id="llmForm">
<fieldset><legend>Provider</legend>
<dl>
<dt class="TableCellDark">Select a LLM Provider</dt>
<dd>
<select name="provider" id="provider" class="form-control" onchange="setHoststub()">
<option value="OLLAMA" selected="selected">Ollama</option>
<option value="LMSTUDIO">LMStudio</option>
<option value="OPENAI">OpenAI</option>
<option value="OPENROUTER">Open Router</option>
</select> This makes a preset to the Hoststub value
</dd>
<dt class="TableCellDark">Hoststub</dt>
<dd><input type="text" name="hoststub" id="hoststub" value="http://localhost:11434" size="30" maxlength="60" class="form-control"/> you can probably leave this to the default value
</dd>
<dt class="TableCellDark">API Key</dt>
<dd><input type="text" name="apikey" id="apikey" value="" disabled=true size="30" maxlength="60" class="form-control"/> (not required for Ollama or LMStudio)
</dd>
<dt class="TableCellDark">Max Token</dt>
<dd>
<select id="maxtoken" name="maxtoken" class="form-control">
<option selected="selected">4096</option>
<option>8192</option>
<option>16384</option>
<option>32768</option>
<option>65536</option>
<option>131072</option>
<option>262440</option>
</select> You must set the Context Length in the LLM provider to fit to your selected max token; in Ollama you find a Context Length slider in the settings
</dd>
<dt> </dt>
<dd><input name="llmselection" value="Load Model Name List" class="btn btn-primary" style="width:240px;" onclick="loadModelList()"/>
</dd>
</dl>
</fieldset>
</form>
<fieldset id="availableModelsContainer" style="display:none"></fieldset>
<fieldset id="loadModelContainer" style="display:none"></fieldset>
<fieldset id="downloadActivityContainer" style="display:none">
<legend>Model Downloads</legend>
<div id="downloadActivityList"></div>
</fieldset>
<fieldset><legend>LLM List</legend>
<table border="0" summary="Pack List Archive">
<tr class="TableHeader"><td>Pack</td><td>Process</td><td>Size (KB)</td></tr>
#{packs}#
<tr class="TableCell#(dark)#Light::Dark#(/dark)#"><td>#[file]#</td><td>#[type]#</td><td>#[size]#</td></tr>
#{/packs}#
</table>
</fieldset>
#%env/templates/footer.template%#
</body>
</html>
|