From f47fd6d50b4a3c2f37158d94622e9b93706cdf6c Mon Sep 17 00:00:00 2001 From: Ben Burtenshaw Date: Tue, 8 Oct 2024 14:32:04 +0200 Subject: [PATCH] feat: add method in settings resource --- argilla/src/argilla/settings/_resource.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/argilla/src/argilla/settings/_resource.py b/argilla/src/argilla/settings/_resource.py index 6d6703274a..352c0b6dcd 100644 --- a/argilla/src/argilla/settings/_resource.py +++ b/argilla/src/argilla/settings/_resource.py @@ -285,6 +285,27 @@ def from_hub( def __eq__(self, other: "Settings") -> bool: return self.serialize() == other.serialize() # TODO: Create proper __eq__ methods for fields and questions + def add( + self, property: Union[Field, VectorField, MetadataType, QuestionType] + ) -> Union[Field, VectorField, MetadataType, QuestionType]: + # review all settings properties and remove any existing property with the same name + for attributes in [self.fields, self.questions, self.vectors, self.metadata]: + for prop in attributes: + if prop.name == property.name: + attributes.remove(prop) + + if isinstance(property, Field): + self.fields.add(property) + elif isinstance(property, QuestionType): + self.questions.add(property) + elif isinstance(property, VectorField): + self.vectors.add(property) + elif isinstance(property, MetadataType): + self.metadata.add(property) + else: + raise ValueError(f"Unsupported property type: {type(property).__name__}") + return property + ##################### # Repr Methods # #####################