Skip to content

Commit

Permalink
Merge pull request #1736 from watchdogpolska/dev_ext
Browse files Browse the repository at this point in the history
v1.5.16
  • Loading branch information
PiotrIw authored Jun 25, 2024
2 parents 2b574d1 + 347188b commit c7c2ad0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 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.5.15"
__version__ = "1.5.16"


# Compatibility to eg. django-rest-framework
Expand Down
7 changes: 6 additions & 1 deletion feder/llm_evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
NORMALIZED_RESPONSE_QUESTION_KEY,
EMAIL_CTEGORISATiON_REFUSED,
answer_categorization,
letter_categories_text,
letter_categorization,
letter_evaluation_intro,
letter_response_normalization,
Expand Down Expand Up @@ -149,9 +150,11 @@ def categorize_letter(cls, letter):
institution=institution_name,
monitoring_question=monitoring_template,
)
categories = letter_categories_text.format(institution=institution_name)
test_prompt = letter_categorization.format(
intro=intro,
institution=institution_name,
letter_categories=categories,
monitoring_response="",
)

Expand All @@ -171,6 +174,7 @@ def categorize_letter(cls, letter):
final_prompt = letter_categorization.format(
intro=intro,
institution=institution_name,
letter_categories=categories,
monitoring_response=texts[0],
)
letter_llm_request = cls.objects.create(
Expand Down Expand Up @@ -201,6 +205,7 @@ def categorize_letter(cls, letter):
"intro": intro,
"institution": institution_name,
"monitoring_response": texts[0],
"letter_categories": categories,
}
)
except ValueError as e:
Expand All @@ -220,7 +225,7 @@ def categorize_letter(cls, letter):
letter_llm_request.token_usage = llm_info_dict
letter_llm_request.status = cls.STATUS.done
letter_llm_request.save()
letter.ai_evaluation = resp
letter.ai_evaluation = resp.strip("`").strip()
if "F) email nie jest odpowiedzią" in resp and "jest spamem" in resp:
letter.is_spam = letter.SPAM.probable_spam
letter.save()
Expand Down
3 changes: 2 additions & 1 deletion feder/llm_evaluation/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
]

EMAIL_IS_ANSWER = letter_categories_list[0].template[:25]
EMAIL_IS_SPAM = letter_categories_list[-2].template[:29]
EMAIL_CTEGORISATiON_REFUSED = (
letter_categories_list[-1].template + " Odmowa kategoryzacji przez Azure GPT."
)
Expand All @@ -66,7 +67,7 @@
```{monitoring_response}```.
""",
template_format="f-string",
partial_variables={"letter_categories": letter_categories_text},
partial_variables={"letter_categories": letter_categories_text.template},
)

letter_response_normalization = PromptTemplate.from_template(
Expand Down
15 changes: 7 additions & 8 deletions feder/llm_evaluation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from background_task import background
from django.utils.translation import gettext_lazy as _

from feder.llm_evaluation.prompts import EMAIL_IS_ANSWER
from feder.llm_evaluation.prompts import EMAIL_IS_ANSWER, EMAIL_IS_SPAM

from .models import LlmLetterRequest, LlmMonitoringRequest

Expand Down Expand Up @@ -44,20 +44,19 @@ def categorize_letter_in_background(letter_pk):

the_same_content_evaluated = (
Letter.objects.filter(
title=letter.title, body=letter.body, ai_evaluation__isnull=False
title=letter.title,
body=letter.body,
ai_evaluation__isnull=False,
ai_evaluation__icontains=EMAIL_IS_SPAM,
)
.exclude(pk=letter_pk)
.first()
)

if (
the_same_content_evaluated
and "F) email nie jest odpowiedzią" in the_same_content_evaluated.ai_evaluation
and "jest spamem" in the_same_content_evaluated.ai_evaluation
):
if the_same_content_evaluated:
message = _(
"AI categorisation skipped for letter with the same content "
+ "as already evaluated letter: "
+ "as already evaluated spam letter: "
) + str(the_same_content_evaluated.pk)
logger.info(f"Letter (pk={letter_pk}): {message}")
letter.ai_evaluation = the_same_content_evaluated.ai_evaluation
Expand Down

0 comments on commit c7c2ad0

Please sign in to comment.