1
0

Refactor settings.html to handle Ollama CLI errors and improve model selection

This commit is contained in:
2025-05-24 20:28:13 +02:00
parent 0b28eecb3f
commit 596907ab23

View File

@@ -126,76 +126,69 @@
close.addEventListener('click', rollback);
const modelDiv = document.getElementById('ollama-model-selectors');
// Vorher: deine Standard-Settings holen
const container = document.getElementById('ollama-model-selectors');
const res = await window.electronAPI.ollamaList();
// 1. Modelle holen
const ollamaRes = await window.electronAPI.ollamaList();
if (ollamaRes.error) {
modelDiv.innerHTML = `
<div style="color:red; font-weight:bold; margin:1em 0;">
!! You need to install Ollama to use intelligent message & readme generation !!
</div>
`;
return;
}
if (res.status === 'no-cli') {
container.innerHTML = `
<div style="color:red;font-weight:bold;margin:1em 0;">
!! You need to install Ollama to use intelligent message & README generation !!
</div>`;
return;
}
// 2. qwen2.5-coder-Modelle filtern
const qwenModels = ollamaRes.models
.filter(m => /^qwen2\.5-coder(:[\w\d\-]+)?$/.test(m.name || m.model))
.map(m => m.name || m.model);
// Wenn CLI lief, aber Fehler beim Parsen, oder einfach keine Daten:
const allModels = Array.isArray(res.models) ? res.models : [];
// Filter für qwen2.5-coder
const qwenModels = allModels
.map(m => m.name || m.model)
.filter(name => /^qwen2\.5-coder(:[\w\d\-.]+)?$/.test(name));
// 3. Kein Modell? Pull-Buttons zeigen!
if (!qwenModels.length) {
modelDiv.innerHTML = `
<button id="pullCommitModelBtn" style="margin-bottom:8px;">
ollama pull qwen2.5-coder:7b
</button><br>
<button id="pullReadmeModelBtn">
ollama pull qwen2.5-coder:32b
</button>
`;
document.getElementById('pullCommitModelBtn').onclick = async () => {
await window.electronAPI.ollamaPull('qwen2.5-coder:7b');
location.reload(); // Reload Settings-Dialog
};
document.getElementById('pullReadmeModelBtn').onclick = async () => {
await window.electronAPI.ollamaPull('qwen2.5-coder:32b');
location.reload();
};
return;
}
if (!qwenModels.length) {
// Keine passenden Modelle → Pull-Buttons zeigen
container.innerHTML = `
<button id="pullCommitModelBtn" style="margin-bottom:8px;">
ollama pull qwen2.5-coder:7b
</button><br>
<button id="pullReadmeModelBtn">
ollama pull qwen2.5-coder:32b
</button>`;
document.getElementById('pullCommitModelBtn').onclick = async () => {
await window.electronAPI.ollamaPull('qwen2.5-coder:7b');
location.reload();
};
document.getElementById('pullReadmeModelBtn').onclick = async () => {
await window.electronAPI.ollamaPull('qwen2.5-coder:32b');
location.reload();
};
return;
}
// 4. Dropdowns rendern
function makeOptions(models, preferred) {
return models.map(m => `<option value="${m}"${m.includes(preferred) ? ' selected' : ''}>${m}</option>`).join('');
}
// Defaults wählen
const commitDefault = qwenModels.find(m => m.includes('7b')) || qwenModels[0];
const readmeDefault = qwenModels.find(m => m.includes('32b')) || qwenModels[0];
// Endlich: Dropdowns!
const makeOpts = (models, selected) =>
models.map(m => `<option value="${m}"${m===selected?' selected':''}>${m}</option>`).join('');
// Werte ggf. aus dem Store holen!
const currentCommitModel = await window.settingsAPI.getCommitModel?.() || commitDefault;
const currentReadmeModel = await window.settingsAPI.getReadmeModel?.() || readmeDefault;
// Defaults (oder aus Settings lesen)
const commitDefault = qwenModels.find(m => m.includes('7b')) || qwenModels[0];
const readmeDefault = qwenModels.find(m => m.includes('32b')) || qwenModels[0];
const currentCommit = await window.settingsAPI.getCommitModel?.() || commitDefault;
const currentReadme= await window.settingsAPI.getReadmeModel?.() || readmeDefault;
modelDiv.innerHTML = `
<label style="font-weight:bold;">Model for commit message generation:</label>
<select id="commitModelSelect">
${makeOptions(qwenModels, currentCommitModel)}
</select>
<br>
<label style="font-weight:bold;">Model for README generation:</label>
<select id="readmeModelSelect">
${makeOptions(qwenModels, currentReadmeModel)}
</select>
`;
// Werte speichern bei Auswahl
document.getElementById('commitModelSelect').onchange = e =>
window.settingsAPI.setCommitModel?.(e.target.value);
document.getElementById('readmeModelSelect').onchange = e =>
window.settingsAPI.setReadmeModel?.(e.target.value);
});
container.innerHTML = `
<label><strong>Model for commit message generation:</strong></label>
<select id="commitModelSelect">
${makeOpts(qwenModels, currentCommit)}
</select>
<br><label><strong>Model for README generation:</strong></label>
<select id="readmeModelSelect">
${makeOpts(qwenModels, currentReadme)}
</select>
`;
document.getElementById('commitModelSelect').onchange = e =>
window.settingsAPI.setCommitModel(e.target.value);
document.getElementById('readmeModelSelect').onchange = e =>
window.settingsAPI.setReadmeModel(e.target.value);
});
</script>
</head>
<body>