Skip to content

Commit

Permalink
Review Task Views
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Oct 7, 2024
1 parent 7b5202a commit c20cf4b
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 25 deletions.
11 changes: 8 additions & 3 deletions parlance/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
from django.contrib import admin
from django.urls import path, include

from parley.views import ReviewTaskDetail
from parley.views import LLMList, LLMDetail
from parley.views import UploaderFormView, CreateReviewTask, ResponseDetail
from parlance.views import Dashboard, AccountSettings, AccountProfile
from parley.views import UploaderFormView, CreateReviewTask, ResponseDetail
from parley.views import EvaluationList, EvaluationDetail, DownloadPrompts


Expand All @@ -47,17 +48,21 @@
# Application Pages
path("", Dashboard.as_view(), name="dashboard"),
path("upload/", UploaderFormView.as_view(), name="upload"),

path("account/profile", AccountProfile.as_view(), name="account-profile"),
path("account/settings", AccountSettings.as_view(), name="account-settings"),

path("evaluations/", EvaluationList.as_view(), name="evaluations-list"),
path("evaluations/<uuid:pk>", EvaluationDetail.as_view(), name="evaluation-detail"),
path("evaluations/<uuid:pk>/download", DownloadPrompts.as_view(), name="evaluation-download"),
path("evaluations/create-review-task", CreateReviewTask.as_view(), name="create-review-task"),

path("reviews/<int:pk>", ReviewTaskDetail.as_view(), name="review-task"),

path("models/", LLMList.as_view(), name="llms-list"),
path("models/<uuid:pk>", LLMDetail.as_view(), name="llm-detail"),
path("responses/<uuid:pk>", ResponseDetail.as_view(), name="response-detail"),

path("evaluations/create-review-task", CreateReviewTask.as_view(), name="create-review-task"),

# Admin URLs
path("admin/", admin.site.urls),

Expand Down
6 changes: 4 additions & 2 deletions parlance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from django.shortcuts import render
from django.views.generic import TemplateView
from parley.models import LLM, Evaluation, Prompt, Response
from parley.models import LLM, Evaluation, Prompt, Response, ReviewTask


##########################################################################
Expand All @@ -41,7 +41,9 @@ def get_context_data(self, **kwargs):
context["n_responses"] = Response.objects.count()

# Get evaluations and models
context["evaluations"] = Evaluation.objects.filter(active=True)
context["evaluations"] = ReviewTask.objects.filter(
completed_on=None, user=self.request.user
)
context["llms"] = LLM.objects.all()[:20]

return context
Expand Down
4 changes: 3 additions & 1 deletion 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:00
# Generated by Django 5.1.1 on 2024-10-07 01:54

import django.db.models.deletion
import parley.models.llm
Expand Down Expand Up @@ -814,6 +814,7 @@ class Migration(migrations.Migration):
(
"started_on",
models.DateTimeField(
blank=True,
default=None,
help_text="The timestamp that the review was start on, null if not started",
null=True,
Expand All @@ -822,6 +823,7 @@ class Migration(migrations.Migration):
(
"completed_on",
models.DateTimeField(
blank=True,
default=None,
help_text="The timestamp that the review was completed, null if not completed",
null=True,
Expand Down
3 changes: 3 additions & 0 deletions parley/models/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ class Meta:
def image(self):
return self.model.image

def prompts(self):
return self.evaluation.prompts.filter(exclude=False)

def responses(self):
return Response.objects.filter(
model=self.model, prompt__evaluation=self.evaluation
Expand Down
23 changes: 21 additions & 2 deletions parley/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .base import TimestampedModel

from django.db import models
from django.urls import reverse


##########################################################################
Expand Down Expand Up @@ -49,12 +50,12 @@ class ReviewTask(TimestampedModel):
)

started_on = models.DateTimeField(
null=True, default=None,
null=True, default=None, blank=True,
help_text="The timestamp that the review was start on, null if not started"
)

completed_on = models.DateTimeField(
null=True, default=None,
null=True, default=None, blank=True,
help_text="The timestamp that the review was completed, null if not completed",
)

Expand All @@ -64,6 +65,10 @@ class Meta:
get_latest_by = "created"
unique_together = ("user", "evaluation")

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

@property
def is_started(self):
return self.started_on is not None
Expand All @@ -72,6 +77,20 @@ def is_started(self):
def is_completed(self):
return self.completed_on is not None

@property
def percent_complete(self):
n_prompts = self.evaluation.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})"

def get_absolute_url(self):
return reverse("review-task", args=(self.id,))


class ResponseReview(TimestampedModel):

Expand Down
4 changes: 4 additions & 0 deletions parley/templates/evaluation/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ <h4 class="mb-1 name">

{% get_review_task user model as review_task %}
{% if review_task %}
{% if review_task.is_completed %}
<span class="badge py-2 text-bg-success">Review Complete!</span>
{% else %}
<a href="{{ review_task.get_absolute_url }}" class="btn btn-sm btn-white d-none d-xl-inline-block">
Continue Review
</a>
{% endif %}
{% else %}
<form action="{% url 'create-review-task' %}" method="post" class="m-0 p-0 d-inline-block">
<input type="hidden" name="user" value="{{ user.id }}" />
Expand Down
4 changes: 4 additions & 0 deletions parley/templates/reviews/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends 'page.html' %}

{% block page-pretitle %}Reviews{% endblock %}
{% block page-title %}{{ review }}{% endblock %}
14 changes: 13 additions & 1 deletion parley/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from parley.exceptions import ParlanceUploadError
from parley.forms import Uploader, CreateReviewForm
from parley.models import LLM, Response, Evaluation, Prompt
from parley.models import LLM, Response, Evaluation, Prompt, ReviewTask


##########################################################################
Expand Down Expand Up @@ -194,3 +194,15 @@ def form_invalid(self, form):

def get(self, *args, **kwargs):
return HttpResponseNotAllowed(['POST'])


class ReviewTaskDetail(DetailView):

model = ReviewTask
template_name = "reviews/detail.html"
context_object_name = "review"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_id"] = "review"
return context
54 changes: 38 additions & 16 deletions templates/site/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div class="card">
<div class="card-header">
<h4 class="card-header-title">
Active Evaluations
Pending Review Tasks
</h4>

</div>
Expand All @@ -39,7 +39,7 @@ <h4 class="card-header-title">
<div class="row align-items-center">
<div class="col-auto">
<!-- icon -->
<a href="#!" class="avatar avatar-lg">
<a href="{{ evaluation.get_absolute_url }}" class="avatar avatar-lg">
<span class="avatar-title rounded bg-white text-secondary">
<span class="fe fe-clipboard"></span>
</span>
Expand All @@ -49,25 +49,34 @@ <h4 class="card-header-title">

<!-- Title -->
<h4 class="mb-1 name">
<a href="#!">{{ evaluation.name }}</a>
<a href="{{ evaluation.get_absolute_url }}">{{ evaluation }}</a>
</h4>

<!-- Text -->
<p class="card-text small text-muted mb-1">
{{ evaluation.task }}
</p>

<!-- Time -->
<p class="card-text small text-muted">
{{ evaluation.prompts.count }} prompts
</p>
<!-- Progress -->
{% with pcent=evaluation.percent_complete %}
<div class="row align-items-center g-0">
<div class="col-auto">
<div class="small me-2">{{ pcent }}%</div>
</div>
<div class="col pe-5">
<div class="progress progress-sm">
<div class="progress-bar" role="progressbar" style="width: {{ pcent }}%" aria-valuenow="{{ pcent }}" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</div>
{% endwith %}

</div>
<div class="col-auto">

<!-- Button -->
<a href="#!" class="btn btn-sm btn-white d-none d-md-inline-block">
Download
<a href="{{ evaluation.get_absolute_url }}" class="btn btn-sm btn-white d-none d-md-inline-block">
{% if evaluation.is_started %}Continue Review{% else %}Begin Review{% endif %}
</a>

</div>
Expand All @@ -79,14 +88,14 @@ <h4 class="mb-1 name">
<i class="fe fe-more-vertical"></i>
</a>
<div class="dropdown-menu dropdown-menu-end">
<a href="#!" class="dropdown-item">
Action
<a href="{% url 'admin:parley_reviewtask_change' evaluation.pk %}" class="dropdown-item">
Edit in CMS
</a>
<a href="#!" class="dropdown-item">
Another action
<a href="{% url 'evaluation-detail' evaluation.evaluation.evaluation.pk %}" class="dropdown-item">
View Evaluation
</a>
<a href="#!" class="dropdown-item">
Something else here
<a href="{% url 'llm-detail' evaluation.evaluation.model.pk %}" class="dropdown-item">
View Model
</a>
</div>
</div>
Expand All @@ -96,7 +105,20 @@ <h4 class="mb-1 name">
</li>
{% empty %}
<li class="list-group-item">
<p>No Active Review Tasks</p>
<p>
You have no pending review tasks!
</p>
<p>
To begin a review, go to the
<a href="{% url 'evaluations-list' %}">Evaluations</a> page, and select
an evaluation that has at least one model associated with it. When you
reach the evaluation detail page, click on the "Begin Review" button to
start an evaluation.
</p>
<p>
If all models have been marked as reviewed &mdash; congratulations, you
are an expert reviewer! Let's train a new model and get evaluating!
</p>
</li>
{% endfor %}
</ul>
Expand Down

0 comments on commit c20cf4b

Please sign in to comment.