miquido / draive

Framework for building AI oriented applications. The project was made by Miquido: https://www.miquido.com/
MIT License
105 stars 20 forks source link

Cannot use StrEnum fields in DataModel #173

Open piotr-rarus opened 2 months ago

piotr-rarus commented 2 months ago

Draive is unable to build a validator for StrEnum. It uses list_validator but doesn't get a range of available values.

Error:

draive.parameters.errors.ParameterValidationError: ("Validation error: Invalid parameter value at: %s - expected '%s' while received '%s'", UserProfileDraive.goals[0], (), <Goal.GENERAL_WELLNESS: 'GENERAL_WELLNESS'>)

Example code:

from enum import StrEnum
from draive import DataModel

class Goal(StrEnum):
    GENERAL_WELLNESS = "GENERAL_WELLNESS"
    INCREASE_ENERGY = "INCREASE_ENERGY"
    ENHANCE_FOCUS = "ENHANCE_FOCUS"
    OTHER = "OTHER"

class UserProfileDraive(DataModel):
    name: str
    goals: list[Goal]

user_profile_draive = UserProfileDraive(name='Piotr', goals=[Goal.GENERAL_WELLNESS])
user_profile_draive_json = user_profile_draive.as_json()
print(user_profile_draive_json)
KaQuMiQ commented 1 month ago

It seems that there is some missing part when decoding Enum based types, I will take a closer look at it