File size: 1,528 Bytes
0172013 7eabdbb 6851964 363880e 6851964 363880e 6851964 0172013 363880e 0172013 363880e 0172013 363880e 0172013 363880e 0172013 363880e 6851964 363880e 6851964 363880e 6851964 363880e 0172013 363880e 6851964 0172013 363880e 0172013 363880e 0172013 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | const API_URL =
"https://promotional-expert-eligibility-navigator.trycloudflare.com/generate";
async function sendMessage() {
const input = document.querySelector("#messageInput");
const chat = document.querySelector("#chat");
const text = input.value.trim();
if (!text) return;
addMessage(text, "user");
input.value = "";
const loading = addMessage("Arko está pensando...", "ai");
try {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
prompt: text,
max_new_tokens: 300
})
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.detail || data.error || "API error");
}
loading.textContent =
data.response || "Arko no devolvió una respuesta.";
} catch (error) {
console.error(error);
loading.textContent =
"No se pudo conectar con Arko Incode 1.0.";
}
}
function addMessage(text, type) {
const chat = document.querySelector("#chat");
const message = document.createElement("div");
message.className = `message ${type}`;
message.textContent = text;
chat.appendChild(message);
chat.scrollTop = chat.scrollHeight;
return message;
}
document
.querySelector("#sendButton")
?.addEventListener("click", sendMessage);
document
.querySelector("#messageInput")
?.addEventListener("keydown", (event) => {
if (event.key === "Enter") {
sendMessage();
}
}); |