Dashboard Masticationpedia: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| Riga 61: | Riga 61: | ||
</div> | </div> | ||
<div class="mpai-composer"> | |||
<textarea id="mpai-input" rows="3" placeholder="Scrivi qui la tua domanda..."></textarea> | |||
<div class="mpai-composer-right"> | |||
<label class="mpai-check" style="margin:0 0 6px 0;"> | |||
<input id="mpai-drop-urls" type="checkbox"> | |||
Ignora/Cancella URL e allegati per questo invio | |||
</label> | |||
<button id="mpai-send" class="mpai-btn primary">Invia</button> | |||
</div> | |||
</div> | |||
</main> | </main> | ||
| Riga 127: | Riga 134: | ||
.mpai-composer{display:flex;gap:8px;align-items:flex-end} | .mpai-composer{display:flex;gap:8px;align-items:flex-end} | ||
.mpai-composer textarea{flex:1 1 auto;min-height:90px;border:1px solid var(--line);border-radius:12px;padding:10px} | .mpai-composer textarea{flex:1 1 auto;min-height:90px;border:1px solid var(--line);border-radius:12px;padding:10px} | ||
.mpai-composer-right{display:flex;flex-direction:column;gap:6px} | |||
@media (max-width:1100px){.mpai-grid{grid-template-columns:1fr}.mpai-left,.mpai-right{max-height:none}} | @media (max-width:1100px){.mpai-grid{grid-template-columns:1fr}.mpai-left,.mpai-right{max-height:none}} | ||
</style> | </style> | ||
| Riga 185: | Riga 193: | ||
}); | }); | ||
</script> | </script> | ||
<!-- ========= Handler di invio che manda drop_urls al backend ========= --> | |||
<script> | |||
(function(){ | |||
const $chat = document.getElementById('mpai-chat'); | |||
const $input = document.getElementById('mpai-input'); | |||
const $send = document.getElementById('mpai-send'); | |||
function addMsg(role, text){ | |||
const div = document.createElement('div'); | |||
div.className = 'mpai-msg ' + (role === 'user' ? 'user' : (role === 'assistant' ? 'assistant' : 'error')); | |||
div.innerHTML = '<div class="role">'+role+'</div><div class="body"></div>'; | |||
div.querySelector('.body').textContent = text; | |||
$chat.appendChild(div); | |||
$chat.scrollTop = $chat.scrollHeight; | |||
} | |||
async function sendMessage(){ | |||
const prompt = ($input.value || '').trim(); | |||
if (!prompt) return; | |||
// UI | |||
addMsg('user', prompt); | |||
$input.value = ''; | |||
// Leggi impostazioni UI | |||
const model = document.getElementById('mpai-model')?.value || 'gpt-4o-2024-05-13'; | |||
const temperature = parseFloat(document.getElementById('mpai-temp')?.value || '0.7'); | |||
const drop = document.getElementById('mpai-drop-urls')?.checked === true; | |||
// Se hai una tua gestione file/immagini, collega qui gli array: | |||
const files = []; // <- puoi popolarlo se li mandi al backend | |||
const texts = []; // <- idem | |||
// Costruisci payload per il backend | |||
const payload = { | |||
model, | |||
prompt, | |||
temperature, | |||
drop_urls: drop, // << QUI il flag “Cancella URL” | |||
files, | |||
texts | |||
}; | |||
try { | |||
const res = await fetch('/dashboard/api/openai_project_gpt.php', { | |||
method: 'POST', | |||
headers: { 'Content-Type': 'application/json' }, | |||
credentials: 'include', | |||
body: JSON.stringify(payload) | |||
}); | |||
// Il backend può rispondere testo puro o JSON. | |||
const ct = res.headers.get('content-type') || ''; | |||
let out; | |||
if (ct.includes('application/json')) { | |||
const j = await res.json(); | |||
// accetta varianti: {ok:true,text:"..."}, {message:"..."}, stringa, ecc. | |||
out = j?.text ?? j?.message ?? (typeof j === 'string' ? j : JSON.stringify(j, null, 2)); | |||
} else { | |||
out = await res.text(); | |||
} | |||
addMsg('assistant', out || '(vuoto)'); | |||
} catch (e) { | |||
addMsg('error', String(e)); | |||
} | |||
} | |||
// Eventi invio | |||
$send?.addEventListener('click', sendMessage); | |||
$input?.addEventListener('keydown', (e) => { | |||
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) sendMessage(); | |||
}); | |||
})(); | |||
</script> | |||
</html> | </html> | ||
Versione delle 15:06, 12 ott 2025
🔧 Dashboard Operativa – Masticationpedia
Centro di comando per progetti, API, file e backup