diff --git a/ai_eval/shortanswer.py b/ai_eval/shortanswer.py index 2501a9d..cd9b553 100644 --- a/ai_eval/shortanswer.py +++ b/ai_eval/shortanswer.py @@ -30,6 +30,15 @@ class ShortAnswerAIEvalXBlock(AIEvalXBlock): scope=Scope.settings, ) + character_image = String( + display_name=_("Character Image URL"), + help=_( + "URL for an image to be shown to the left of the chat box; " + "leave empty to disable" + ), + scope=Scope.settings, + ) + max_responses = Integer( display_name=_("Max Responses"), help=_("The maximum number of response messages the student can submit"), @@ -47,6 +56,7 @@ class ShortAnswerAIEvalXBlock(AIEvalXBlock): editable_fields = AIEvalXBlock.editable_fields + ( "max_responses", "allow_reset", + "character_image", ) def validate_field_data(self, validation, data): diff --git a/ai_eval/static/css/shortanswer.css b/ai_eval/static/css/shortanswer.css index fb0bec5..75ca04d 100644 --- a/ai_eval/static/css/shortanswer.css +++ b/ai_eval/static/css/shortanswer.css @@ -1,5 +1,15 @@ /* CSS for ShortAnswerAIEvalXBlock */ +.shortanswer_image { + float: left; + margin-right: 4rem; + width: 30%; +} + +.shortanswer_image > img { + max-width: 100%; +} + .shortanswer_block .count { font-weight: bold; } diff --git a/ai_eval/templates/shortanswer.html b/ai_eval/templates/shortanswer.html index 2fc4d32..7a7293d 100644 --- a/ai_eval/templates/shortanswer.html +++ b/ai_eval/templates/shortanswer.html @@ -1,3 +1,9 @@ +{% if self.character_image %} +
+ +
+{% endif %} +
diff --git a/ai_eval/tests/test_ai_eval.py b/ai_eval/tests/test_ai_eval.py index da5d4ea..c217a5e 100644 --- a/ai_eval/tests/test_ai_eval.py +++ b/ai_eval/tests/test_ai_eval.py @@ -85,3 +85,13 @@ def test_reset_forbidden(self): with self.assertRaises(JsonHandlerError): block.reset.__wrapped__(block, data={}) self.assertEqual(block.messages, {"USER": ["Hello"], "LLM": ["Hello"]}) + + def test_character_image(self): + """Test the character image.""" + data = { + **self.data, + "character_image": "/static/image.jpg", + } + block = ShortAnswerAIEvalXBlock(ToyRuntime(), DictFieldData(data), None) + frag = block.student_view() + self.assertIn('', frag.content)