Skip to content

Commit

Permalink
chore: Relax metadata value typing
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Oct 7, 2024
1 parent 1bd49e5 commit 29e86d8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
1 change: 0 additions & 1 deletion argilla/src/argilla/_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from argilla._models._record._suggestion import SuggestionModel
from argilla._models._record._response import UserResponseModel, ResponseStatus
from argilla._models._record._vector import VectorModel, VectorValue
from argilla._models._record._metadata import MetadataModel, MetadataValue
from argilla._models._search import (
SearchQueryModel,
AndFilterModel,
Expand Down
7 changes: 2 additions & 5 deletions argilla/src/argilla/_models/_record/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Annotated, Union, List
from typing import Annotated, Any

from pydantic import BaseModel


MetadataValue = Annotated[Union[str, List[str], float, int, None], "The value of the metadata field dictionary"]


class MetadataModel(BaseModel):
"""Schema for the metadata of a `Dataset`"""

name: Annotated[str, "The name of the metadata field or key in the metadata dictionary"]
value: MetadataValue
value: Any
4 changes: 2 additions & 2 deletions argilla/src/argilla/_models/_record/_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from pydantic import BaseModel, Field, field_serializer, field_validator

from argilla._models._record._metadata import MetadataModel, MetadataValue
from argilla._models._record._metadata import MetadataModel
from argilla._models._record._response import UserResponseModel
from argilla._models._record._suggestion import SuggestionModel
from argilla._models._record._vector import VectorModel
Expand All @@ -44,7 +44,7 @@ class RecordModel(ResourceModel):

status: Literal["pending", "completed"] = "pending"
fields: Optional[Dict[str, FieldValue]] = None
metadata: Optional[Union[List[MetadataModel], Dict[str, MetadataValue]]] = Field(default_factory=dict)
metadata: Optional[Union[List[MetadataModel], Dict[str, Any]]] = Field(default_factory=dict)
vectors: Optional[List[VectorModel]] = Field(default_factory=list)
responses: Optional[List[UserResponseModel]] = Field(default_factory=list)
suggestions: Optional[Union[Tuple[SuggestionModel], List[SuggestionModel]]] = Field(default_factory=tuple)
Expand Down
7 changes: 3 additions & 4 deletions argilla/src/argilla/records/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
from argilla._helpers._media import cast_image, uncast_image
from argilla._models import (
FieldValue,
MetadataModel,
MetadataValue,
RecordModel,
SuggestionModel,
UserResponseModel,
VectorModel,
VectorValue,
)
from argilla._models._record._metadata import MetadataModel
from argilla._resource import Resource
from argilla.responses import Response, UserResponse
from argilla.suggestions import Suggestion
Expand Down Expand Up @@ -61,7 +60,7 @@ def __init__(
self,
id: Optional[Union[UUID, str]] = None,
fields: Optional[Dict[str, FieldValue]] = None,
metadata: Optional[Dict[str, MetadataValue]] = None,
metadata: Optional[Dict[str, Any]] = None,
vectors: Optional[Dict[str, VectorValue]] = None,
responses: Optional[List[Response]] = None,
suggestions: Optional[List[Suggestion]] = None,
Expand Down Expand Up @@ -331,7 +330,7 @@ def _is_chat(self, key: str) -> bool:
class RecordMetadata(dict):
"""This is a container class for the metadata of a Record."""

def __init__(self, metadata: Optional[Dict[str, MetadataValue]] = None) -> None:
def __init__(self, metadata: Optional[Dict[str, Any]] = None) -> None:
super().__init__(metadata or {})

def to_dict(self) -> dict:
Expand Down
3 changes: 2 additions & 1 deletion argilla/tests/unit/test_resources/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

from argilla import Dataset, Record, Response, Settings, Suggestion, TextField, TextQuestion
from argilla._exceptions import ArgillaError
from argilla._models import MetadataModel, RecordModel
from argilla._models import RecordModel
from argilla._models._record._metadata import MetadataModel


@pytest.fixture()
Expand Down

0 comments on commit 29e86d8

Please sign in to comment.