Skip to content

Commit

Permalink
feat: Add basic support to bool features (#5576)
Browse files Browse the repository at this point in the history
# Description
<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that are required for this change. -->

Also, relax type casting for metadata values, accepting Any.

**Type of change**
<!-- Please delete options that are not relevant. Remember to title the
PR according to the type of change -->

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Refactor (change restructuring the codebase without changing
functionality)
- Improvement (change adding some improvement to an existing
functionality)
- Documentation update

**How Has This Been Tested**
<!-- Please add some reference about how your feature has been tested.
-->

**Checklist**
<!-- Please go over the list and make sure you've taken everything into
account -->

- I added relevant documentation
- I followed the style guidelines of this project
- I did a self-review of my code
- I made corresponding changes to the documentation
- I confirm My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature
works
- I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
  • Loading branch information
frascuchon authored Oct 11, 2024
1 parent e4b2d79 commit 70b9d30
Show file tree
Hide file tree
Showing 12 changed files with 452 additions and 339 deletions.
4 changes: 4 additions & 0 deletions argilla-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ These are the section headers that we use:

## [Unreleased]()

### Changed

- Changed supported values for terms metadata options to accept other than strings values. ([#5589](https://github.com/argilla-io/argilla/pull/5589))

### Removed

- Removed name pattern validation for Workspaces, Datasets, and Users. ([#5575](https://github.com/argilla-io/argilla/pull/5575))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

class TermsMetadataMetrics(BaseModel):
class TermCount(BaseModel):
term: str
term: Any
count: int

type: Literal[MetadataPropertyType.terms] = Field(MetadataPropertyType.terms, const=True)
Expand Down Expand Up @@ -72,13 +72,18 @@ def round_result(cls, v: float):


MetadataMetrics = Annotated[
Union[TermsMetadataMetrics, IntegerMetadataMetrics, FloatMetadataMetrics], Field(..., discriminator="type")
Union[
TermsMetadataMetrics,
IntegerMetadataMetrics,
FloatMetadataMetrics,
],
Field(..., discriminator="type"),
]


class TermsMetadataProperty(BaseModel):
type: Literal[MetadataPropertyType.terms]
values: Optional[List[str]] = None
values: Optional[List[Any]] = None


class IntegerMetadataProperty(BaseModel):
Expand All @@ -98,7 +103,6 @@ class FloatMetadataProperty(BaseModel):
Field(..., discriminator="type"),
]


MetadataPropertyName = Annotated[
str,
Field(
Expand All @@ -109,7 +113,6 @@ class FloatMetadataProperty(BaseModel):
),
]


MetadataPropertyTitle = Annotated[
constr(min_length=METADATA_PROPERTY_CREATE_TITLE_MIN_LENGTH, max_length=METADATA_PROPERTY_CREATE_TITLE_MAX_LENGTH),
Field(..., description="The title of the metadata property"),
Expand All @@ -133,7 +136,7 @@ def check_bounds(cls, values: Dict[str, Any]) -> Dict[str, Any]:

class TermsMetadataPropertyCreate(BaseModel):
type: Literal[MetadataPropertyType.terms]
values: Optional[List[str]] = Field(
values: Optional[List[Any]] = Field(
None, min_items=TERMS_METADATA_PROPERTY_VALUES_MIN_ITEMS, max_items=TERMS_METADATA_PROPERTY_VALUES_MAX_ITEMS
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def check_metadata(self, value: Any) -> None:

class TermsMetadataPropertySettings(BaseMetadataPropertySettings):
type: Literal[MetadataPropertyType.terms]
values: Optional[List[str]] = None
values: Optional[List[Any]] = None

def check_metadata(self, value: Union[str, List[str]]) -> None:
def check_metadata(self, value: Any) -> None:
if self.values is None:
return

values = value
if isinstance(values, str):
if not isinstance(values, list):
values = [value]

for v in values:
Expand Down
Loading

0 comments on commit 70b9d30

Please sign in to comment.