Fix Lesson 8 Task 1
This commit is contained in:
parent
f6ae234ec9
commit
b07f920ebf
2 changed files with 20 additions and 35 deletions
|
@ -24,11 +24,14 @@ void LlmMathQuiz::submit()
|
||||||
ui->e_llm->setText(m_llmAnswer);
|
ui->e_llm->setText(m_llmAnswer);
|
||||||
ui->b_submit->setEnabled(false);
|
ui->b_submit->setEnabled(false);
|
||||||
ui->e_user->setReadOnly(true);
|
ui->e_user->setReadOnly(true);
|
||||||
ui->l_opinion->setText("Generating…");
|
|
||||||
|
|
||||||
sendPrompt("The two following lines will contain two answers for a mathematical task. The first value is the expected answer, and the second one is the answer provided. Respond with \"true\" if the provided answer matches the expected answer, and \"false\" if it is not. Always use lowercase."
|
if (m_llmAnswer.contains(ui->e_user->text())) {
|
||||||
+ QString("\n") + m_llmAnswer
|
ui->l_matched->setText(QString::number(ui->l_matched->text().toInt() + 1));
|
||||||
+ QString("\n") + ui->e_user->text());
|
ui->l_match->setText("True");
|
||||||
|
} else
|
||||||
|
ui->l_match->setText("False");
|
||||||
|
|
||||||
|
ui->b_generate->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LlmMathQuiz::generate()
|
void LlmMathQuiz::generate()
|
||||||
|
@ -42,14 +45,13 @@ void LlmMathQuiz::generate()
|
||||||
ui->e_task->setText("Generating…");
|
ui->e_task->setText("Generating…");
|
||||||
ui->e_user->clear();
|
ui->e_user->clear();
|
||||||
ui->e_llm->clear();
|
ui->e_llm->clear();
|
||||||
ui->l_opinion->setText("Not checked");
|
ui->l_match->setText("Not checked");
|
||||||
|
|
||||||
sendPrompt("Generate a math task and a correct answer for it. The task can be anything from simple equations, to logical tasks. Both the task and the answer need to take only one line. Provide the task on the first line, and the answer on the second line. Never use equation 2x + 5 = 11.");
|
sendPrompt("Generate a math task and a correct answer for it. The task can be anything from simple equations, to logical tasks. Both the task and the answer need to take only one line. Provide the task on the first line, and the answer on the second line. Never use equation 2x + 5 = 11.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LlmMathQuiz::newAnswer(QNetworkReply *reply)
|
void LlmMathQuiz::newAnswer(QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
if (!m_taskReceived) {
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
QByteArray textReply = reply->readAll();
|
QByteArray textReply = reply->readAll();
|
||||||
QStringList data = QJsonDocument::fromJson(textReply).object().value("response").toString().split('\n');
|
QStringList data = QJsonDocument::fromJson(textReply).object().value("response").toString().split('\n');
|
||||||
|
@ -62,23 +64,6 @@ void LlmMathQuiz::newAnswer(QNetworkReply *reply)
|
||||||
ui->e_task->setText("Error!");
|
ui->e_task->setText("Error!");
|
||||||
ui->b_generate->setEnabled(true);
|
ui->b_generate->setEnabled(true);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
|
||||||
QByteArray textReply = reply->readAll();
|
|
||||||
QString data = QJsonDocument::fromJson(textReply).object().value("response").toString();
|
|
||||||
if (data == "true") {
|
|
||||||
ui->l_matched->setText(QString::number(ui->l_matched->text().toInt() + 1));
|
|
||||||
ui->l_opinion->setText("Match");
|
|
||||||
} else if (data == "false")
|
|
||||||
ui->l_opinion->setText("Mismatch");
|
|
||||||
else
|
|
||||||
ui->l_opinion->setText("Not match nor mismatch");
|
|
||||||
ui->b_generate->setEnabled(true);
|
|
||||||
} else {
|
|
||||||
ui->e_llm->setText("Error!");
|
|
||||||
ui->b_submit->setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LlmMathQuiz::sendPrompt(QString prompt)
|
void LlmMathQuiz::sendPrompt(QString prompt)
|
||||||
|
|
|
@ -74,12 +74,12 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>LLM opinion:</string>
|
<string>Answer match:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="l_opinion">
|
<widget class="QLabel" name="l_match">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Not checked</string>
|
<string>Not checked</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Reference in a new issue