From b0f99ee4a978edcc02207dbaaea54fa762dc7d33 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 3 Nov 2024 12:17:04 -0800 Subject: [PATCH] (chore) bring perfection to switch delegate --- logic/mathematics/sieve.js | 3 ++- qml/PracticePage.qml | 20 +++++++++++++++----- qml/SettingsPage.qml | 33 +++++++++++++++++++++------------ qml/WelcomePage.qml | 16 ++++++++++------ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/logic/mathematics/sieve.js b/logic/mathematics/sieve.js index 601257d..6c514a7 100644 --- a/logic/mathematics/sieve.js +++ b/logic/mathematics/sieve.js @@ -19,8 +19,9 @@ var question = [ } for (int i = 2; i <= n; i++) { - if (isPrime[i]) + if (isPrime[i]) { cout << i << " "; + } } }`, answerGo: `package main diff --git a/qml/PracticePage.qml b/qml/PracticePage.qml index 80b4480..7313e64 100644 --- a/qml/PracticePage.qml +++ b/qml/PracticePage.qml @@ -175,9 +175,20 @@ Rectangle { } function submitPrompt(prompt) { - var url = "https://api-inference.huggingface.co/models/llama-3.1-Nemotron-70b-instruct"; + var url = "https://api.openai.com/v1/chat/completions"; var jsonData = { - "inputs": prompt + "model": "gpt-3.5-turbo", + "messages": [ + { + "role": "system", + "content": "You are an expert code reviewer. Provide constructive feedback and suggestions for improvement." + }, + { + "role": "user", + "content": "Here is the code snippet for feedback:\n" + prompt + } + ], + "temperature": 0.7 }; var xhr = new XMLHttpRequest(); @@ -189,7 +200,7 @@ Rectangle { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { var response = JSON.parse(xhr.responseText); - root.aiComment = response[0].generated_text; + root.aiComment = response.choices[0].message.content; } else { console.log("Error: ", xhr.statusText); } @@ -205,8 +216,7 @@ Rectangle { root.submittedAnswer = userAnswer - var prompt = "\nWhat is a brief difference between \n\n ```\n" + expectedAnswer + "\n```\n\n and \n\n```\n" + userAnswer + "\n```" - submitPrompt(prompt); + submitPrompt(userAnswer); sessionObject.attempted += 1 diff --git a/qml/SettingsPage.qml b/qml/SettingsPage.qml index d097f29..5b8de18 100644 --- a/qml/SettingsPage.qml +++ b/qml/SettingsPage.qml @@ -162,22 +162,26 @@ Rectangle { indicator: Rectangle { implicitWidth: 50 implicitHeight: 26 - x: control.width - width - control.rightPadding + x: control.width - width - control.rightPadding + 3 y: parent.height / 2 - height / 2 radius: 13 color: control.checked ? themeObject.buttonEasyColor : "#cccccc" border.color: control.checked ? themeObject.buttonEasyColor : "#cccccc" Rectangle { - x: control.checked ? parent.width - width : 0 - width: 26 - height: 26 - radius: 13 + x: control.checked ? parent.width - width - 3 : 3 + width: 22 + height: 22 + radius: 11 + anchors.verticalCenter: parent.verticalCenter color: control.down ? "#cccccc" : "#ffffff" border.color: control.checked ? (control.down ? themeObject.buttonEasyColor : "#21be2b") : "#999999" Behavior on x { - NumberAnimation { duration: 200 } + NumberAnimation { + duration: 200 + easing.type: Easing.InOutQuad + } } } } @@ -207,22 +211,27 @@ Rectangle { indicator: Rectangle { implicitWidth: 50 implicitHeight: 26 - x: control.width - width - control.rightPadding + x: control.width - width - control.rightPadding + 3 y: parent.height / 2 - height / 2 radius: 13 color: control.checked ? themeObject.buttonEasyColor : "#cccccc" border.color: control.checked ? themeObject.buttonEasyColor : "#cccccc" + opacity: enabled ? 1.0 : 0.5 Rectangle { - x: control.checked ? parent.width - width : 0 - width: 26 - height: 26 - radius: 13 + x: control.checked ? parent.width - width - 3 : 3 + width: 22 + height: 22 + radius: 11 + anchors.verticalCenter: parent.verticalCenter color: control.down ? "#cccccc" : "#ffffff" border.color: control.checked ? (control.down ? themeObject.buttonEasyColor : "#21be2b") : "#999999" Behavior on x { - NumberAnimation { duration: 200 } + NumberAnimation { + duration: 200 + easing.type: Easing.InOutQuad + } } } } diff --git a/qml/WelcomePage.qml b/qml/WelcomePage.qml index 4ccdf22..1d0e295 100644 --- a/qml/WelcomePage.qml +++ b/qml/WelcomePage.qml @@ -117,7 +117,7 @@ Rectangle { indicator: Rectangle { implicitWidth: 50 implicitHeight: 26 - x: themeToggle.width - width - themeToggle.rightPadding + x: themeToggle.width - width - themeToggle.rightPadding + 3 y: parent.height / 2 - height / 2 radius: 13 color: themeToggle.checked ? themeObject.buttonEasyColor : "#cccccc" @@ -125,15 +125,19 @@ Rectangle { opacity: enabled ? 1.0 : 0.5 Rectangle { - x: themeToggle.checked ? parent.width - width : 0 - width: 26 - height: 26 - radius: 13 + x: themeToggle.checked ? parent.width - width - 3 : 3 + width: 22 + height: 22 + radius: 11 + anchors.verticalCenter: parent.verticalCenter color: themeToggle.down ? "#cccccc" : "#ffffff" border.color: themeToggle.checked ? (themeToggle.down ? themeObject.buttonEasyColor : "#21be2b") : "#999999" Behavior on x { - NumberAnimation { duration: 200 } + NumberAnimation { + duration: 200 + easing.type: Easing.InOutQuad + } } } }