Skip to content

Commit

Permalink
Add support for new type field on complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
cgokmen committed Mar 5, 2025
1 parent 70e7218 commit c288caa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
18 changes: 7 additions & 11 deletions bddl/knowledge_base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,32 +968,28 @@ def __str__(self):

@dataclass(eq=False, order=False)
class ComplaintType(Model):
id: str = UUIDField()
message: str = ""

name: str
complaints_fk: OneToMany = OneToManyField("Complaint", "complaint_type")

class Meta:
pk = "id"
ordering = ["message"]
pk = "name"
ordering = ["name"]

@cached_property
def objects(self):
return [complaint.object for complaint in self.complaints]

def __str__(self):
return self.message

@dataclass(eq=False, order=False)
class Complaint(Model):
id: str = UUIDField()
object_fk: ManyToOne = ManyToOneField(Object, "complaints")
complaint_type_fk: ManyToOne = ManyToOneField(ComplaintType, "complaints")
content: str = ""
prompt_additional_info: str = "" # provided by the QA script as part of the prompt
response: str = "" # provided by the QAing user

class Meta:
pk = "id"
ordering = ["name"]
ordering = ["id"]

def __str__(self):
return f"{self.object.name} - {self.complaint_type.message}: {self.content}"
return f"{self.object.name} - {self.complaint_type.name}: {self.response}"
13 changes: 5 additions & 8 deletions bddl/knowledge_base/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ def create_complaints(self):
for complaint in complaints:
if complaint["processed"]:
continue
complaint_type_name = complaint["type"]
complaint_model_id = complaint["object"].split("-")[1]
complaint_message = complaint["message"]
complaint_content = complaint["complaint"]
complaint_additional_info = complaint["additional_info"]
complaint_response = complaint["complaint"]

# Check if the model ID exists
obj = Object.get(name=complaint_model_id)
Expand All @@ -401,12 +402,8 @@ def create_complaints(self):
continue

# Create the relevant objects
complaint_types_with_message = [ct for ct in ComplaintType.all_objects() if ct.message == complaint_message]
if len(complaint_types_with_message) == 0:
complaint_type = ComplaintType.create(message=complaint_message)
else:
complaint_type, = complaint_types_with_message
Complaint.create(object=obj, complaint_type=complaint_type, content=complaint_content)
complaint_type, created = ComplaintType.get_or_create(name=complaint_type_name)
Complaint.create(object=obj, complaint_type=complaint_type, prompt_additional_info=complaint_additional_info, response=complaint_content)

# TODO: Move to cached property on Synset
def generate_synset_state(self):
Expand Down

0 comments on commit c288caa

Please sign in to comment.