fetch("/minigpt/index.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ messages }) }) .then(response => { if (!response.ok) { return response.text().then(text => { throw new Error(`HTTP ${response.status}: ${text}`); }); } return response.json(); }) .then(data => { if (data.error) { throw new Error(data.error.message || "Error desconocido en el servidor"); } const assistantResponse = data.choices[0].message.content; chatBox.innerHTML += `
Asistente: ${assistantResponse}
`; messages.push({ role: "assistant", content: assistantResponse }); }) .catch(error => { chatBox.innerHTML += `
Error: ${error.message}
`; });