Auto commit: 2025-12-02T16:09:33.054Z
This commit is contained in:
parent
4647314b9d
commit
b0afe7cbe9
Binary file not shown.
Binary file not shown.
18
core/migrations/0003_reflection_feedback.py
Normal file
18
core/migrations/0003_reflection_feedback.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
Binary file not shown.
@ -14,6 +14,7 @@ class Reflection(models.Model):
|
|||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
question = models.TextField()
|
question = models.TextField()
|
||||||
answer = models.TextField(blank=True, null=True)
|
answer = models.TextField(blank=True, null=True)
|
||||||
|
feedback = models.TextField(blank=True, null=True)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
@ -26,6 +26,10 @@
|
|||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong>{{ reflection.question }}</strong><br>
|
<strong>{{ reflection.question }}</strong><br>
|
||||||
{{ reflection.answer }}<br>
|
{{ reflection.answer }}<br>
|
||||||
|
{% if reflection.feedback %}
|
||||||
|
<strong>Feedback:</strong><br>
|
||||||
|
<p class="text-muted">{{ reflection.feedback }}</p>
|
||||||
|
{% endif %}
|
||||||
<small class="text-muted">{{ reflection.created_at|date:"F d, Y" }}</small>
|
<small class="text-muted">{{ reflection.created_at|date:"F d, Y" }}</small>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@ -86,6 +86,20 @@ def reflection_view(request):
|
|||||||
reflection = form.save(commit=False)
|
reflection = form.save(commit=False)
|
||||||
reflection.user = request.user
|
reflection.user = request.user
|
||||||
reflection.question = request.POST.get('question') # Get question from hidden input
|
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()
|
reflection.save()
|
||||||
return redirect('reflection')
|
return redirect('reflection')
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user