You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB

  1. from auto_labeling_pipeline.models import RequestModelFactory
  2. from django.core.exceptions import ValidationError
  3. from django.db import models
  4. from api.models import Project
  5. class AutoLabelingConfig(models.Model):
  6. TASK_CHOICES = (
  7. ('Category', 'category'),
  8. ('Span', 'span'),
  9. ('Text', 'text'),
  10. ('Relation', 'relation')
  11. )
  12. model_name = models.CharField(max_length=100)
  13. model_attrs = models.JSONField(default=dict)
  14. template = models.TextField(default='')
  15. label_mapping = models.JSONField(default=dict, blank=True)
  16. project = models.ForeignKey(
  17. to=Project,
  18. on_delete=models.CASCADE,
  19. related_name='auto_labeling_config'
  20. )
  21. task_type = models.CharField(max_length=100, choices=TASK_CHOICES)
  22. default = models.BooleanField(default=False)
  23. created_at = models.DateTimeField(auto_now_add=True)
  24. updated_at = models.DateTimeField(auto_now=True)
  25. def __str__(self):
  26. return self.model_name
  27. def clean_fields(self, exclude=None):
  28. super().clean_fields(exclude=exclude)
  29. try:
  30. RequestModelFactory.find(self.model_name)
  31. except NameError:
  32. message = f'The specified model name {self.model_name} does not exist.'
  33. raise ValidationError(message)
  34. except Exception:
  35. message = 'The attributes does not match the model.'
  36. raise ValidationError(message)