LLM view refactor

This commit is contained in:
Luciano Gervasoni
2025-04-14 13:49:06 +02:00
parent 43c6c3aabf
commit b876f6d720
4 changed files with 39 additions and 21 deletions

View File

@@ -94,6 +94,12 @@
});
});
// CSRF token helper (required if CSRF protection is enabled)
function getCookie(name) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? match[2] : null;
}
function fetchDetails(urlId, url) {
// Show the loading spinner
document.getElementById("loading-spinner").style.display = "block";
@@ -109,22 +115,24 @@
}
// Fetch URL
let fetchUrl = `/urls/${urlId}/fetch/?url=${encodeURIComponent(url)}&model=${encodeURIComponent(selectedModel)}&text=${encodeURIComponent(inputText)}`;
let fetchUrl = `/urls/llm/`;
let resultContainer = $("#chat-output");
resultContainer.html(""); // Clear previous content before fetching
let fetchButton = $("button[onclick^='fetchDetails']"); // Select the button
fetchButton.prop("disabled", true); // Disable button
fetch(fetchUrl/*, {
fetch(fetchUrl, {
method: "POST",
body: JSON.stringify({
text: inputText
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
}*/).then(response => {
"Content-type": "application/json; charset=UTF-8",
'X-CSRFToken': getCookie('csrftoken') // required if CSRF middleware is active
},
body: JSON.stringify({
model: selectedModel,
message: inputText
})
}).then(response => {
if (!response.ok) {
throw new Error("Error on network response");
}