templates/index.html aktualisiert

This commit is contained in:
2026-03-06 13:09:51 +00:00
parent 9199903fbb
commit ff699e311d

View File

@@ -317,24 +317,22 @@
const provider = document.getElementById('ai-provider').value;
const modelSelect = document.getElementById('ai-model');
const urlContainer = document.getElementById('ollama-url-container');
const ollamaUrl = document.getElementById('ollama-url').value;
// WICHTIG: Hier 'let' statt 'const' nutzen, da wir die URL gleich noch verändern!
let ollamaUrl = document.getElementById('ollama-url').value;
// Sichtbarkeit des URL-Feldes steuern
urlContainer.style.display = (provider === "ollama") ? "flex" : "none";
modelSelect.innerHTML = '<option>Lade Modelle...</option>';
// API-Query vorbereiten
// API-Query vorbereiten
let apiUrl = `/api/models?provider=${provider}`;
if (provider === "ollama" && ollamaUrl) {
// FIX: Prüfen, ob die URL mit /v1 endet. Wenn nicht, hängen wir es an.
// Prüfen, ob die URL mit /v1 endet. Wenn nicht, hängen wir es an.
if (!ollamaUrl.endsWith('/v1') && !ollamaUrl.includes('/api')) {
// Eventuellen Schrägstrich am Ende entfernen und /v1 anhängen
ollamaUrl = ollamaUrl.replace(/\/$/, '') + '/v1';
// Das Input-Feld direkt aktualisieren, damit es beim Speichern stimmt
document.getElementById('ollama-url').value = ollamaUrl;
}
apiUrl += `&base_url=${encodeURIComponent(ollamaUrl)}`;
@@ -342,15 +340,19 @@
try {
const res = await fetch(apiUrl);
if (!res.ok) throw new Error("Server-Antwort nicht OK");
if (!res.ok) throw new Error(`Server antwortete mit Status ${res.status}`);
const data = await res.json();
modelSelect.innerHTML = '';
if (data.models && data.models.length > 0) {
// Prüfen ob 'models' existiert und ein Array mit Inhalten ist
if (data.models && Array.isArray(data.models) && data.models.length > 0) {
data.models.forEach(m => {
const opt = document.createElement('option');
opt.value = opt.textContent = m;
// Manchmal kommen die Modelle als Objekte statt als Strings zurück (je nach Python-Code)
const modelName = typeof m === 'object' ? (m.name || m.id) : m;
opt.value = modelName;
opt.textContent = modelName;
modelSelect.appendChild(opt);
});
@@ -364,7 +366,7 @@
}
} catch (e) {
console.error("Fehler beim Modell-Abruf:", e);
modelSelect.innerHTML = '<option value="">Modelle konnten nicht geladen werden</option>';
modelSelect.innerHTML = '<option value="">Fehler beim Laden</option>';
}
}