Skip to content

Commit e4184c7

Browse files
committed
Some coding style changes
1 parent 29fb59d commit e4184c7

File tree

10 files changed

+62
-42
lines changed

10 files changed

+62
-42
lines changed

amd/build/expertmode.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/expertmode.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/expertmode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2626
*/
2727

28-
import {get_string} from 'core/str';
28+
import {getString} from 'core/str';
2929
import Notification from 'core/notification';
3030

3131
/**
@@ -49,12 +49,12 @@ export const init = (template) => {
4949
button.addEventListener('click', async(e) => {
5050
e.preventDefault();
5151

52-
const confirmMessage = await get_string('expertmodeconfirm', 'assignfeedback_aif');
52+
const confirmMessage = await getString('expertmodeconfirm', 'assignfeedback_aif');
5353
Notification.confirm(
54-
await get_string('useexpertmodetemplate', 'assignfeedback_aif'),
54+
await getString('useexpertmodetemplate', 'assignfeedback_aif'),
5555
confirmMessage,
56-
await get_string('yes', 'core'),
57-
await get_string('no', 'core'),
56+
await getString('yes', 'core'),
57+
await getString('no', 'core'),
5858
() => {
5959
insertTemplate(promptTextarea, template);
6060
}

classes/task/process_feedback.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function execute(): void {
8888
$data = (object) [
8989
'aif' => $submission->aifid,
9090
'feedback' => $aifeedback,
91+
'feedbackformat' => FORMAT_MARKDOWN,
9192
'timecreated' => $clock->now()->getTimestamp(),
9293
'submission' => $submission->subid,
9394
];

classes/task/process_feedback_rubric_adhoc.php

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ private function get_submission_record(int $assignmentid, int $userid) {
8888
/**
8989
* Generate AI feedback for a submission.
9090
*
91-
* @param object|false $record The submission record.
91+
* @param mixed $record The submission record.
9292
* @param string $triggeredby How the task was triggered: 'auto' (observer) or 'manual' (teacher).
93-
* @param \assign $assign The assign instance.
93+
* @param null|assign $assign The assign instance.
94+
* @return void
9495
*/
9596
private function generate_feedback($record, string $triggeredby = 'manual', ?\assign $assign = null): void {
9697
global $DB, $CFG;
@@ -113,45 +114,47 @@ private function generate_feedback($record, string $triggeredby = 'manual', ?\as
113114
return;
114115
}
115116

116-
try {
117-
// All content (including images and PDFs) is now converted to text during
118-
// prompt building, so we always use the default feedback purpose.
119-
$provider = \core\di::get(\assignfeedback_aif\local\ai_request_provider::class);
120-
$purpose = get_config('assignfeedback_aif', 'purpose') ?: 'feedback';
121-
if (!$provider->is_available($purpose, $record->contextid)) {
122-
mtrace("AI backend not available for purpose '{$purpose}', skipping submission {$record->subid}.");
123-
return;
124-
}
117+
// All content (including images and PDFs) is now converted to text during
118+
// prompt building, so we always use the default feedback purpose.
119+
$provider = \core\di::get(\assignfeedback_aif\local\ai_request_provider::class);
120+
$purpose = get_config('assignfeedback_aif', 'purpose') ?: 'feedback';
121+
if (!$provider->is_available($purpose, $record->contextid)) {
122+
mtrace("AI backend not available for purpose '{$purpose}', skipping submission {$record->subid}.");
123+
return;
124+
}
125125

126+
try {
126127
$aifeedback = $aif->perform_request(
127128
$promptdata['prompt'],
128129
null,
129130
$promptdata['options'],
130131
$this->get_userid() ?: get_admin()->id
131132
);
133+
} catch (\moodle_exception $e) {
134+
mtrace("AI request failed for submission {$record->subid}: " . $e->getMessage());
135+
return;
136+
}
132137

133-
// Practice mode: only when auto-triggered (not teacher) and no marking workflow.
134-
$ispractice = ($triggeredby === 'auto') && $this->is_practice_mode($record->aid);
138+
// Practice mode: only when auto-triggered (not teacher) and no marking workflow.
139+
$ispractice = ($triggeredby === 'auto') && $this->is_practice_mode($record->aid);
135140

136-
// Append the appropriate disclaimer to feedback.
137-
$aifeedback = $aif->append_disclaimer($aifeedback, $ispractice);
141+
// Append the appropriate disclaimer to feedback.
142+
$aifeedback = $aif->append_disclaimer($aifeedback, $ispractice);
138143

139-
$clock = \core\di::get(\core\clock::class);
140-
$data = (object) [
141-
'aif' => $record->aifid,
142-
'feedback' => $aifeedback,
143-
'timecreated' => $clock->now()->getTimestamp(),
144-
'submission' => $record->subid,
145-
];
146-
$DB->insert_record('assignfeedback_aif_feedback', $data);
144+
$clock = \core\di::get(\core\clock::class);
145+
$data = (object) [
146+
'aif' => $record->aifid,
147+
'feedback' => $aifeedback,
148+
'feedbackformat' => FORMAT_MARKDOWN,
149+
'timecreated' => $clock->now()->getTimestamp(),
150+
'submission' => $record->subid,
151+
];
152+
$DB->insert_record('assignfeedback_aif_feedback', $data);
147153

148-
// Ensure a grade record exists so students can see feedback in the submission view.
149-
$this->ensure_grade_record($record, $assign);
154+
// Ensure a grade record exists so students can see feedback in the submission view.
155+
$this->ensure_grade_record($record, $assign);
150156

151-
mtrace("AI feedback generated for assignment {$record->aid} submission {$record->subid}");
152-
} catch (\Exception $e) {
153-
mtrace("Error generating AI feedback: " . $e->getMessage());
154-
}
157+
mtrace("AI feedback generated for assignment {$record->aid} submission {$record->subid}");
155158
}
156159

157160
/**
@@ -190,8 +193,8 @@ private function ensure_grade_record(object $record, \assign $assign): void {
190193

191194
if (
192195
!$DB->record_exists('assign_grades', [
193-
'assignment' => $record->aid,
194-
'userid' => $record->userid,
196+
'assignment' => $record->aid,
197+
'userid' => $record->userid,
195198
])
196199
) {
197200
$assign->get_user_grade($record->userid, true);

db/install.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
2323
<FIELD NAME="aif" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2424
<FIELD NAME="feedback" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Text of feedback returned from external LLM"/>
25-
<FIELD NAME="feedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Format of the feedback text (e.g. FORMAT_HTML)"/>
25+
<FIELD NAME="feedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="4" SEQUENCE="false" COMMENT="Format of the feedback text (FORMAT_MARKDOWN=4)"/>
2626
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2727
<FIELD NAME="submission" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
2828
</FIELDS>

db/upgrade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ function xmldb_assignfeedback_aif_upgrade($oldversion) {
9494
upgrade_plugin_savepoint(true, 2026031801, 'assignfeedback', 'aif');
9595
}
9696

97+
if ($oldversion < 2026031901) {
98+
// Change feedbackformat from FORMAT_HTML (1) to FORMAT_MARKDOWN (4) for AI-generated feedback.
99+
// AI responses are Markdown, not HTML. FORMAT_MARKDOWN ensures proper rendering.
100+
$DB->set_field('assignfeedback_aif_feedback', 'feedbackformat', FORMAT_MARKDOWN);
101+
102+
upgrade_plugin_savepoint(true, 2026031901, 'assignfeedback', 'aif');
103+
}
104+
97105
return true;
98106
}

lang/en/assignfeedback_aif.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
Focus on both strengths and areas for improvement.
6161
Be encouraging but honest.
6262
63+
Format your response in strict Markdown:
64+
- Use ## for section headings.
65+
- Use "1. " for numbered lists (NOT "1)").
66+
- Use "- " for bullet lists.
67+
- Always leave a blank line before and after headings, lists, and code/math blocks.
68+
- Use **bold** and *italic* for emphasis.
69+
- For math equations use LaTeX: inline with $$ ... $$ and display blocks with \\[ ... \\].
70+
6371
=== LANGUAGE ===
6472
Respond in {{language}}.';
6573
$string['deletefeedbackai'] = 'Delete AI feedback';

locallib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public function get_settings(MoodleQuickForm $mform): void {
102102
'advcheckbox',
103103
'assignfeedback_aif_autogenerate',
104104
get_string('autogenerate', 'assignfeedback_aif'),
105-
' ',
106-
[],
105+
'',
106+
['id' => 'id_assignfeedback_aif_autogenerate'],
107107
[0, 1]
108108
);
109109
$mform->setDefault('assignfeedback_aif_autogenerate', 0);

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626

2727
$plugin->component = 'assignfeedback_aif';
2828
$plugin->release = '0.5.0';
29-
$plugin->version = 2026031900;
29+
$plugin->version = 2026031901;
3030
$plugin->requires = 2024100700; // Moodle 4.5 for Core AI subsystem.
3131
$plugin->maturity = MATURITY_BETA;

0 commit comments

Comments
 (0)