This commit is contained in:
yoannchb-pro
2023-03-29 19:55:22 -04:00
parent 1770d044e5
commit 79eb20bcca
12 changed files with 91 additions and 35 deletions
+5
View File
@@ -1,5 +1,10 @@
# CHANGELOG
## v1.0.1
- Removed langage
- Added a button next to model to get the last ChatGPT version
## v1.0.0
- Initial commit
+6 -7
View File
@@ -2,7 +2,7 @@
href="https://www.flaticon.com/free-icons/mortarboard" target="_blank" rel="noopener noreferrer"
title="Mortarboard icons created by itim2101 - Flaticon" ><img src="./extension/icon.png" alt="Mortarboard icons created by itim2101 - Flaticon" width="150" style="display:block; margin:auto;"></a></p>
# Moodle-gpt
# Moodle-gpt v1.0.1
This extension allows you to hide CHAT-GPT in a Moodle quiz. You just need to enter <b>the code configured in the extension</b> on the keyboard and then click on the question you want to solve, and CHAT-GPT will automatically provide the answer. However, one needs to be careful because as we know, CHAT-GPT can make errors especially in calculations.
@@ -36,22 +36,21 @@ Type back the <b>code</b> on the keyboard and the code will be removed from the
<img src="./assets/popup.png" alt="Popup" height="300">
</p>
- <b>Api key\*</b>: the openai api key.
- <b>Code\*</b>: code that you will need to inject/remove the code.
- <b>Langage</b>: the langage you want chatgpt reply (if it's not set it will take the question langage).
- <b>GPT Model</b>: the gpt model you want to use (by default it's "gpt-3.5-turbo").
- <b>Api key</b>: the openai api key.
- <b>Code</b>: code that you will need to inject/remove the code.
- <b>GPT Model</b>: 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.
- <b>Cursor indication</b>: show a pointer cursor and a hourglass to know when the request is finished.
- <b>Title indication</b>: show some informations into the title to know for example if the code have been injected.
<br/> ![Injected](./assets/title-injected.png)
- <b>Console logs</b>: show logs into the console.
<br/><img src="./assets/logs.png" alt="Logs" width="250">
- <b>Request timeout</b>: If the request is too long it will be abort after 10seconds.
- <b>Request timeout</b>: if the request is too long it will be abort after 10seconds.
- <b>Typing effect</b>: 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 <b>Backspace</b> key.
<br/> ![Typing](./assets/typing.gif)
- <b>Mouseover effect</b>: you will need to hover (or click for select) the question response to complete it automaticaly.
<br/> ![Mouseover](./assets/mouseover.gif)
<br/> ![Mouseover2](./assets/mouseover2.gif)
- <b>Table formatting</b>: Format table from the question to make it more readable for CHAT-GPT but cost most tokens (so if the question is too large it will make an error). Example of formatted table:
- <b>Table formatting</b>: format table from the question to make it more readable for CHAT-GPT but cost most tokens (so if the question is too large it will make an error). Example of formatted table:
```
| id | name | birthDate | cars |
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 42 KiB

+2 -4
View File
@@ -87,7 +87,7 @@
},
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,
@@ -147,9 +147,7 @@
question = question.replace(table.textContent, "\n" + htmlTableToString(table) + "\n");
}
}
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);
File diff suppressed because one or more lines are too long
+17 -8
View File
@@ -8,6 +8,13 @@
<link rel="stylesheet" href="style.css" />
<script src="index.js" defer></script>
<link rel="icon" type="image/png" href="../icon.png" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
</head>
<body>
<main>
@@ -20,20 +27,22 @@
/></a>
<h1>MoodleGPT</h1>
<div class="line center">
<label for="apiKey" class="textLabel">Api Key*</label>
<input id="apiKey" type="password" />
<label for="apiKey" class="textLabel">Api Key</label>
<input id="apiKey" type="text" />
</div>
<div class="line center">
<label for="code" class="textLabel">Code*</label>
<label for="code" class="textLabel">Code</label>
<input id="code" type="text" />
</div>
<div class="line center">
<label for="langage" class="textLabel">Langage</label>
<input id="langage" type="text" />
</div>
<div class="line center">
<label for="model" class="textLabel">GPT Model</label>
<input id="model" type="text" />
<input id="model" type="text" value="gpt-3.5-turbo" />
<i
id="reloadModel"
class="fa-solid fa-rotate-right"
disabled
title="Provide an api key first"
></i>
</div>
<div class="line center" style="margin-top: 1rem">
<div class="col">
+48 -6
View File
@@ -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");
}
});
});
+9
View File
@@ -103,3 +103,12 @@ a {
margin-top: 0.75rem;
margin-bottom: -0.25rem;
}
#reloadModel {
cursor: pointer;
}
#reloadModel[disabled] {
cursor: not-allowed;
opacity: 0.75;
}
+1 -1
View File
@@ -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"
+1 -2
View File
@@ -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,
+1 -5
View File
@@ -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);
-1
View File
@@ -1,7 +1,6 @@
type Config = {
apiKey: string;
code: string;
langage?: string;
model?: string;
infinite?: boolean;
typing?: boolean;