diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 9f32394..5d7d897 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index c095085..23f27c4 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/migrations/0003_reflection_feedback.py b/core/migrations/0003_reflection_feedback.py new file mode 100644 index 0000000..300deed --- /dev/null +++ b/core/migrations/0003_reflection_feedback.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.7 on 2025-12-02 16:01 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_reflection'), + ] + + operations = [ + migrations.AddField( + model_name='reflection', + name='feedback', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/core/migrations/__pycache__/0003_reflection_feedback.cpython-311.pyc b/core/migrations/__pycache__/0003_reflection_feedback.cpython-311.pyc new file mode 100644 index 0000000..fa874ce Binary files /dev/null and b/core/migrations/__pycache__/0003_reflection_feedback.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 3e7ed9c..00fbeb7 100644 --- a/core/models.py +++ b/core/models.py @@ -14,6 +14,7 @@ class Reflection(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) question = models.TextField() answer = models.TextField(blank=True, null=True) + feedback = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True) def __str__(self): diff --git a/core/templates/core/reflection.html b/core/templates/core/reflection.html index 3e8fdbd..619606c 100644 --- a/core/templates/core/reflection.html +++ b/core/templates/core/reflection.html @@ -26,6 +26,10 @@
  • {{ reflection.question }}
    {{ reflection.answer }}
    + {% if reflection.feedback %} + Feedback:
    +

    {{ reflection.feedback }}

    + {% endif %} {{ reflection.created_at|date:"F d, Y" }}
  • {% endfor %} diff --git a/core/views.py b/core/views.py index 184fb79..1c8ac5f 100644 --- a/core/views.py +++ b/core/views.py @@ -86,6 +86,20 @@ def reflection_view(request): reflection = form.save(commit=False) reflection.user = request.user reflection.question = request.POST.get('question') # Get question from hidden input + + # AI-generated feedback + feedback_response = LocalAIApi.create_response({ + "input": [ + {"role": "system", "content": "You are a helpful assistant. Your task is to provide brief, encouraging, and constructive feedback on a user\'s reflection. The feedback should be no more than 50 words."}, + {"role": "user", "content": f"The user was asked: '{reflection.question}' and they responded: '{reflection.answer}'. Please provide some feedback."}, + ], + }) + + if feedback_response.get("success"): + reflection.feedback = LocalAIApi.extract_text(feedback_response) + else: + reflection.feedback = "Thank you for your reflection." # Fallback feedback + reflection.save() return redirect('reflection') else: