Skip to content

Commit

Permalink
Merge branch 'feature/detailed-message-actions' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza committed Nov 25, 2024
2 parents cf45c11 + 7568fc6 commit 290abe3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nexus/logs/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import unicodedata
import re
import string
from typing import List, Dict
from uuid import uuid4

Expand Down Expand Up @@ -30,6 +33,13 @@ class Message(models.Model):
def __str__(self) -> str:
return f"{self.status} - {self.contact_urn}"

def clean_string(self, s: str) -> str:
s = s.lower()
s = " ".join(s.split())
s = unicodedata.normalize("NFKD", s).encode("ascii", "ignore").decode("utf-8")
s = re.sub(f"[{re.escape(string.punctuation)}]", "", s)
return s

@property
def groundedness_details(self):
from router.classifiers.groundedness import Groundedness
Expand All @@ -52,8 +62,10 @@ def groundedness_details(self):
"score": sentence.get("score"),
}
for chunk in self.messagelog.chunks_json:
evidence: str = sentence.get("evidence", "").strip('"')
if evidence.lower() in chunk.get("full_page").lower():
evidence: str = sentence.get("evidence", "")
clean_evidence: str = self.clean_string(evidence)
clean_chunk: str = self.clean_string(chunk)
if clean_evidence in clean_chunk:
sentence_stats["sources"].append(
{
"filename": chunk.get("filename"),
Expand Down

0 comments on commit 290abe3

Please sign in to comment.