MoodleGPT
-
-
+
+
-
+
-
-
-
-
-
+
+
diff --git a/extension/popup/index.js b/extension/popup/index.js
index 3a64487..ececaed 100644
--- a/extension/popup/index.js
+++ b/extension/popup/index.js
@@ -1,7 +1,7 @@
const saveBtn = document.querySelector(".save");
const message = document.querySelector("#message");
-const inputsText = ["apiKey", "code", "langage", "model"];
+const inputsText = ["apiKey", "code", "model"];
const inputsCheckbox = [
"logs",
"title",
@@ -22,7 +22,7 @@ function showMessage(messageTxt, valide) {
//save the configuration
saveBtn.addEventListener("click", function () {
- const [apiKey, code, langage, model] = inputsText.map((selector) =>
+ const [apiKey, code, model] = inputsText.map((selector) =>
document.querySelector("#" + selector).value.trim()
);
const [logs, title, cursor, typing, mouseover, infinite, table, timeout] =
@@ -30,7 +30,7 @@ saveBtn.addEventListener("click", function () {
(selector) => document.querySelector("#" + selector).checked
);
- if (!apiKey || !code) {
+ if (!apiKey || !code || !model) {
showMessage("Please comple all the form");
return;
}
@@ -44,7 +44,6 @@ saveBtn.addEventListener("click", function () {
moodleGPT: {
apiKey,
code,
- langage,
model,
logs,
title,
@@ -64,11 +63,54 @@ saveBtn.addEventListener("click", function () {
chrome.storage.sync.get(["moodleGPT"]).then(function (storage) {
if (storage.moodleGPT) {
const config = storage.moodleGPT;
- inputsText.forEach(
- (key) => (document.querySelector("#" + key).value = config[key] || "")
+ inputsText.forEach((key) =>
+ config[key]
+ ? (document.querySelector("#" + key).value = config[key])
+ : null
);
inputsCheckbox.forEach(
(key) => (document.querySelector("#" + key).checked = config[key] || "")
);
}
+
+ //getting the last chatgpt version
+ const apiKeySelector = document.querySelector("#apiKey");
+ const reloadModel = document.querySelector("#reloadModel");
+
+ let apiKey = apiKeySelector.value;
+
+ function checkFileldApiKey() {
+ if (apiKey) {
+ reloadModel.removeAttribute("disabled");
+ reloadModel.setAttribute("title", "Get last ChatGPT version");
+ return;
+ }
+
+ reloadModel.setAttribute("disabled", true);
+ reloadModel.setAttribute("title", "Provide an api key first");
+ }
+
+ checkFileldApiKey();
+
+ apiKeySelector.addEventListener("change", function (event) {
+ apiKey = apiKeySelector.value.trim();
+ checkFileldApiKey();
+ });
+
+ reloadModel.addEventListener("click", async function () {
+ if (!apiKey) return;
+ try {
+ const req = await fetch("https://api.openai.com/v1/models", {
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ },
+ });
+ const rep = await req.json();
+ const model = rep.data.find((model) => model.id.includes("gpt"));
+ document.querySelector("#model").value = model.root;
+ } catch (err) {
+ console.error(err);
+ showMessage("Failed to fetch last ChatGPT version");
+ }
+ });
});
diff --git a/extension/popup/style.css b/extension/popup/style.css
index 64ea098..ecf51c8 100644
--- a/extension/popup/style.css
+++ b/extension/popup/style.css
@@ -103,3 +103,12 @@ a {
margin-top: 0.75rem;
margin-bottom: -0.25rem;
}
+
+#reloadModel {
+ cursor: pointer;
+}
+
+#reloadModel[disabled] {
+ cursor: not-allowed;
+ opacity: 0.75;
+}
diff --git a/package.json b/package.json
index 05a8e00..d5acdf9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "moodle-gpt",
- "version": "1.0.0",
+ "version": "1.0.1",
"description": "This extension allows you to hide CHAT-GPT in a Moodle quiz.",
"scripts": {
"build": "rollup -c"
diff --git a/src/core/get-response.ts b/src/core/get-response.ts
index 43decad..56275d3 100644
--- a/src/core/get-response.ts
+++ b/src/core/get-response.ts
@@ -21,8 +21,7 @@ async function getChatGPTResponse(
},
signal: config.timeout ? controller.signal : null,
body: JSON.stringify({
- model:
- config.model && config.model !== "" ? config.model : "gpt-3.5-turbo",
+ model: config.model,
messages: [{ role: "user", content: question }],
temperature: 0.8,
top_p: 1.0,
diff --git a/src/core/normalize-question.ts b/src/core/normalize-question.ts
index c712fd3..1be2239 100644
--- a/src/core/normalize-question.ts
+++ b/src/core/normalize-question.ts
@@ -23,11 +23,7 @@ function normalizeQuestion(config: Config, questionContainer: HTMLElement) {
}
}
- const finalQuestion = `Give a short response as possible for this question, reply in ${
- config.langage && config.langage !== ""
- ? 'this langage "' + config.langage + '"'
- : "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);
diff --git a/src/types/config.d.ts b/src/types/config.d.ts
index 2f53194..d913f2e 100644
--- a/src/types/config.d.ts
+++ b/src/types/config.d.ts
@@ -1,7 +1,6 @@
type Config = {
apiKey: string;
code: string;
- langage?: string;
model?: string;
infinite?: boolean;
typing?: boolean;
-- Api key\*: the openai api key.
-- Code\*: code that you will need to inject/remove the code.
-- Langage: the langage you want chatgpt reply (if it's not set it will take the question langage).
-- GPT Model: the gpt model you want to use (by default it's "gpt-3.5-turbo").
+- Api key: the openai api key.
+- Code: code that you will need to inject/remove the code.
+- GPT Model: the gpt model you want to use (by default it's "gpt-3.5-turbo"). You can click on the reload button to get the latest version of available gpt model for your account but you need to enter the api key first.
- Cursor indication: show a pointer cursor and a hourglass to know when the request is finished.
- Title indication: show some informations into the title to know for example if the code have been injected.
-- Request timeout: If the request is too long it will be abort after 10seconds.
+- Request timeout: if the request is too long it will be abort after 10seconds.
- Typing effect: create a typing effect for text. Type any text and it will be replaced by the correct one. If you want to stop it press Backspace key.