Skip to content

Commit

Permalink
Merge pull request #1387 from watchdogpolska/develop
Browse files Browse the repository at this point in the history
v1.3.2 Llm evaluation - fixes
  • Loading branch information
PiotrIw authored Oct 31, 2023
2 parents f5d335c + 182752a commit dee6559
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion feder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PEP 396: The __version__ attribute's value SHOULD be a string.
__version__ = "1.3.1"
__version__ = "1.3.2"


# Compatibility to eg. django-rest-framework
Expand Down
4 changes: 3 additions & 1 deletion feder/llm_evaluation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def get_monitoring_normalized_response_template(monitoring_pk):
.order_by("-created")
)

if (
# TODO: make sure to update when introducing more LlmMonitoringRequest methods
# TODO: or find better solution
if len(monitoring_llm_requests) == 1 or (
len(monitoring_llm_requests) > 1
and monitoring_llm_requests[0].response != monitoring_llm_requests[1].response
):
Expand Down
21 changes: 14 additions & 7 deletions feder/main/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging

from django.contrib.admin.models import ADDITION, CHANGE, DELETION, LogEntry
from django.contrib.contenttypes.models import ContentType
Expand All @@ -9,6 +10,8 @@
from django.utils.safestring import mark_safe
from rest_framework_csv.renderers import CSVStreamingRenderer

logger = logging.getLogger(__name__)


def get_numeric_param(request, key):
"""Get numeric param from request"""
Expand Down Expand Up @@ -63,13 +66,17 @@ def get_email_domain(email: str) -> str:
def render_normalized_response_html_table(normalized_response):
html = "<table class='table table-bordered compact'>\n"
html += "<tr><th>Nr</th><th>Pytanie</th><th>Odpowiedź</th></tr>\n"
for key, subdict in json.loads(normalized_response).items():
html += (
f"<tr><td>{key}</td><td>{subdict.get('Pytanie', '')}</td>"
+ f"<td>{subdict.get('Odpowiedź', '')}</td></tr>\n"
)
html += "</table>"
return mark_safe(html)
try:
for key, subdict in json.loads(normalized_response).items():
html += (
f"<tr><td>{key}</td><td>{subdict.get('Pytanie', '')}</td>"
+ f"<td>{subdict.get('Odpowiedź', '')}</td></tr>\n"
)
html += "</table>"
return mark_safe(html)
except json.JSONDecodeError:
logger.warning(f"Normalized response is not valid JSON: {normalized_response}")
return mark_safe("<p>Normalized response is not valid JSON.</p>")


class PaginatedCSVStreamingRenderer(CSVStreamingRenderer):
Expand Down

0 comments on commit dee6559

Please sign in to comment.