This commit is contained in:
yoannchb-pro
2023-06-19 23:08:04 -04:00
parent 47b239ae54
commit 9dfe7acc58
6 changed files with 22 additions and 11 deletions
+2 -1
View File
@@ -45,12 +45,13 @@ function setUpMoodleGpt(config: Config) {
.map((e) => `input[type="${e}"]`)
.join(",");
const query = inputQuery + ", textarea, select, [contenteditable]";
const forms = Array.from(document.querySelectorAll(".formulation"));
const forms = document.querySelectorAll(".formulation");
for (const form of forms) {
const hiddenButton: HTMLElement = form.querySelector(".qtext");
if (config.cursor) hiddenButton.style.cursor = "pointer";
const fn = reply.bind(null, config, hiddenButton, form, query);
listeners.push({ element: hiddenButton, fn });
hiddenButton.addEventListener("click", fn, { once: !config.infinite });
+1 -1
View File
@@ -21,7 +21,7 @@ function createQuestion(config: Config, questionContainer: HTMLElement) {
);
}
const finalQuestion = `Give a short response as possible for this question, reply in the following question langage and only show the result:
const finalQuestion = `Give a short response as possible for this question, reply in the following question langage and only show the result:
${question}
(If you have to choose between multiple results only show the corrects one, separate them with new line and take the same text as the question)`;
return normalizeText(finalQuestion);
+9 -2
View File
@@ -33,11 +33,18 @@ async function reply(
error,
})
);
const haveError = typeof response === "object" && "error" in response;
const isAbortError = haveError && response.error.name === "AbortError";
if (config.cursor)
hiddenButton.style.cursor = config.infinite ? "pointer" : "initial";
hiddenButton.style.cursor =
config.infinite || isAbortError ? "pointer" : "initial";
if (haveError) {
if (isAbortError) {
//TODO: We need to inject back the event
}
if (typeof response === "object" && "error" in response) {
console.error(response.error);
return;
}