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