modif selection chatbot

This commit is contained in:
nicoboy
2026-01-05 09:25:37 +01:00
parent e3d392bf08
commit f199ce0653
4 changed files with 212 additions and 20 deletions

View File

@ -28,13 +28,13 @@ function openAddKeyModal(provider = null) {
document.getElementById('keyAction').value = 'add';
editMode = false;
// Important : activer le select AVANT de définir la valeur
providerSelect.disabled = false;
// Pre-select provider if provided
if (provider) {
providerSelect.value = provider;
updateModelsList();
providerSelect.disabled = false;
} else {
providerSelect.disabled = false;
providerSelect.dispatchEvent(new Event('change')); // Trigger updateModelsList
}
title.textContent = 'Ajouter une clé API';
@ -282,6 +282,98 @@ function deleteKey(provider) {
});
}
// ========== Set Default Provider ==========
function setAsDefault(provider, model) {
const formData = new FormData();
formData.append('action', 'set_default');
formData.append('provider', provider);
formData.append('model', model);
fetch('chatbot_api_ajax.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast(data.message || 'Provider par défaut mis à jour', 'success');
setTimeout(() => {
window.location.reload();
}, 1000);
} else {
showToast(data.error || 'Erreur', 'error');
}
})
.catch(error => {
console.error('Error:', error);
showToast('Erreur de connexion', 'error');
});
}
// ========== Configure Ollama ==========
function configureOllama() {
const availableModels = models['ollama'] || [];
if (availableModels.length === 0) {
showToast('Aucun modèle Ollama disponible', 'error');
return;
}
// Créer une liste des modèles
let modelOptions = '<select id="ollama-model-select" style="width: 100%; padding: 0.5rem; margin: 1rem 0; border: 2px solid #e2e8f0; border-radius: 8px;">';
availableModels.forEach(model => {
modelOptions += `<option value="${model.model_id}">${model.display_name}</option>`;
});
modelOptions += '</select>';
// Simple prompt
const modelHtml = `
<div style="padding: 1rem;">
<p style="margin-bottom: 1rem;">Choisir le modèle Ollama par défaut :</p>
${modelOptions}
</div>
`;
// Utiliser une confirm box simple pour l'instant
// (dans une vraie app, utiliser le modal existant)
const modal = document.getElementById('keyModal');
const modalContent = modal.querySelector('.modal-content');
const originalContent = modalContent.innerHTML;
modalContent.innerHTML = `
<div class="modal-header">
<h2>Configuration Ollama</h2>
<button class="modal-close" onclick="closeKeyModal()">×</button>
</div>
<div style="padding: 1.5rem;">
<p style="margin-bottom: 1rem;">Choisir le modèle Ollama à utiliser par défaut :</p>
<select id="ollama-model-select" style="width: 100%; padding: 0.75rem; border: 2px solid #e2e8f0; border-radius: 8px; font-family: 'JetBrains Mono', monospace;">
${availableModels.map(m => `<option value="${m.model_id}">${m.display_name}</option>`).join('')}
</select>
<div style="display: flex; gap: 1rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 2px solid #e2e8f0;">
<button class="btn-secondary" onclick="closeKeyModal(); document.querySelector('.modal-content').innerHTML = \`${originalContent.replace(/`/g, '\\`')}\`;">Annuler</button>
<button class="btn-primary" onclick="saveOllamaConfig()">💾 Enregistrer</button>
</div>
</div>
`;
modal.classList.add('show');
}
function saveOllamaConfig() {
const select = document.getElementById('ollama-model-select');
const model = select.value;
if (!model) {
showToast('Veuillez sélectionner un modèle', 'error');
return;
}
setAsDefault('ollama', model);
}
// ========== Toast Notifications ==========
function showToast(message, type = 'info') {