Skip to content

Commit

Permalink
fix signals
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Oct 7, 2024
1 parent 9a65393 commit a5cafba
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
8 changes: 6 additions & 2 deletions parley/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ class CreateReviewForm(forms.Form):
def save(self):
try:
ReviewTask.objects.create(
user=User.objects.get(pk=self.cleaned_data["user"]),
evaluation=ModelEvaluation.objects.get(pk=self.cleaned_data["evaluation"]),
user=User.objects.get(
pk=self.cleaned_data["user"]
),
model_evaluation=ModelEvaluation.objects.get(
pk=self.cleaned_data["evaluation"]
),
)
except (User.DoesNotExist, ModelEvaluation.DoesNotExist):
return
8 changes: 4 additions & 4 deletions parley/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.1 on 2024-10-07 01:54
# Generated by Django 5.1.1 on 2024-10-07 03:15

import django.db.models.deletion
import parley.models.llm
Expand Down Expand Up @@ -704,7 +704,7 @@ class Migration(migrations.Migration):
"verbose_name": "response",
"verbose_name_plural": "responses",
"db_table": "responses",
"ordering": ("-created",),
"ordering": ("created",),
"get_latest_by": "created",
},
),
Expand Down Expand Up @@ -830,7 +830,7 @@ class Migration(migrations.Migration):
),
),
(
"evaluation",
"model_evaluation",
models.ForeignKey(
help_text="The evaluation the user is performing",
on_delete=django.db.models.deletion.CASCADE,
Expand Down Expand Up @@ -858,7 +858,7 @@ class Migration(migrations.Migration):
"db_table": "review_tasks",
"ordering": ("-created",),
"get_latest_by": "created",
"unique_together": {("user", "evaluation")},
"unique_together": {("user", "model_evaluation")},
},
),
migrations.AddField(
Expand Down
2 changes: 1 addition & 1 deletion parley/models/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class Response(BaseModel):

class Meta:
db_table = "responses"
ordering = ("-created",)
ordering = ("created",)
get_latest_by = "created"
verbose_name = "response"
verbose_name_plural = "responses"
Expand Down
19 changes: 13 additions & 6 deletions parley/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ReviewTask(TimestampedModel):
help_text="The user that is conducting the evaluation",
)

evaluation = models.ForeignKey(
model_evaluation = models.ForeignKey(
"parley.ModelEvaluation",
null=False,
on_delete=models.CASCADE,
Expand All @@ -63,11 +63,18 @@ class Meta:
db_table = "review_tasks"
ordering = ("-created",)
get_latest_by = "created"
unique_together = ("user", "evaluation")
unique_together = ("user", "model_evaluation")

@property
def task(self):
return self.evaluation.evaluation.task
def evaluation(self):
return self.model_evaluation.evaluation

@property
def model(self):
return self.model_evaluation.model

def prompts(self):
return self.model_evaluation.prompts()

@property
def is_started(self):
Expand All @@ -79,14 +86,14 @@ def is_completed(self):

@property
def percent_complete(self):
n_prompts = self.evaluation.prompts().count()
n_prompts = self.prompts().count()
if n_prompts == 0:
return 0
n_reviews = self.response_reviews.count()
return int((float(n_reviews) / float(n_prompts)) * 100)

def __str__(self):
return f"{self.evaluation.evaluation.name} ({self.evaluation.model.name})"
return f"{self.evaluation.name} ({self.model.name})"

def get_absolute_url(self):
return reverse("review-task", args=(self.id,))
Expand Down
23 changes: 18 additions & 5 deletions parley/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def check_review_task_completion(sender, instance, created, *args, **kwargs):
changed = True

if not task.completed_on:
n_prompts = task.evaluation.prompts().count()
if n_prompts == 0 or task.reviews.count() == n_prompts:
n_prompts = task.prompts().count()
if n_prompts == 0 or task.response_reviews.count() == n_prompts:
task.completed_on = timezone.localtime()
changed = True

Expand All @@ -88,10 +88,23 @@ def check_review_task_completion(sender, instance, created, *args, **kwargs):


@receiver(post_delete, sender=ResponseReview, dispatch_uid="check_review_task_unfinished")
def check_review_task_unfinished(sender, instance, created, *args, **kwargs):
def check_review_task_unfinished(sender, instance, *args, **kwargs):
task = instance.review
if task.completed_on:
n_prompts = task.evaluation.prompts().count()
if n_prompts > 0 and task.reviews.count() < n_prompts:
n_prompts = task.prompts().count()
if n_prompts == 0:
return

n_reviews = task.response_reviews.count()
changed = False

if n_reviews < n_prompts:
task.completed_on = None
changed = True

if n_reviews == 0:
task.started_on = None
changed = True

if changed:
task.save()
2 changes: 1 addition & 1 deletion parley/templatetags/parlance.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def alert_level(level):
@register.simple_tag()
def get_review_task(user, evaluation):
try:
return ReviewTask.objects.get(user=user, evaluation=evaluation)
return ReviewTask.objects.get(user=user, model_evaluation=evaluation)
except ReviewTask.DoesNotExist:
return None
4 changes: 2 additions & 2 deletions templates/site/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ <h4 class="mb-1 name">
<a href="{% url 'admin:parley_reviewtask_change' evaluation.pk %}" class="dropdown-item">
Edit in CMS
</a>
<a href="{% url 'evaluation-detail' evaluation.evaluation.evaluation.pk %}" class="dropdown-item">
<a href="{% url 'evaluation-detail' evaluation.evaluation.pk %}" class="dropdown-item">
View Evaluation
</a>
<a href="{% url 'llm-detail' evaluation.evaluation.model.pk %}" class="dropdown-item">
<a href="{% url 'llm-detail' evaluation.model.pk %}" class="dropdown-item">
View Model
</a>
</div>
Expand Down

0 comments on commit a5cafba

Please sign in to comment.