Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): added update model features #146

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sdk/radicalbit_platform_sdk/apis/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
FileReference,
Granularity,
ModelDefinition,
ModelFeatures,
ModelType,
OutputType,
ReferenceFileUpload,
Expand Down Expand Up @@ -77,6 +78,18 @@ def frameworks(self) -> Optional[str]:
def algorithm(self) -> Optional[str]:
return self.__algorithm

def update_features(self, features: List[ColumnDefinition]) -> None:
def __callback(_: requests.Response) -> None:
self.__features = features

invoke(
method='POST',
url=f'{self.__base_url}/api/models/{str(self.__uuid)}',
valid_response_code=200,
data=ModelFeatures(features=features).model_dump_json(),
func=__callback,
)

def delete(self) -> None:
"""Delete the actual `Model` from the platform

Expand Down
2 changes: 2 additions & 0 deletions sdk/radicalbit_platform_sdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CreateModel,
Granularity,
ModelDefinition,
ModelFeatures,
OutputType,
)
from .model_type import ModelType
Expand All @@ -47,6 +48,7 @@
'Granularity',
'CreateModel',
'ModelDefinition',
'ModelFeatures',
'ColumnDefinition',
'JobStatus',
'DataType',
Expand Down
6 changes: 6 additions & 0 deletions sdk/radicalbit_platform_sdk/models/model_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class Granularity(str, Enum):
MONTH = 'MONTH'


class ModelFeatures(BaseModel):
features: List[ColumnDefinition]

model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)


class BaseModelDefinition(BaseModel):
"""A base class for model definition.

Expand Down
50 changes: 50 additions & 0 deletions sdk/tests/apis/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Granularity,
JobStatus,
ModelDefinition,
ModelFeatures,
ModelType,
OutputType,
ReferenceFileUpload,
Expand Down Expand Up @@ -56,6 +57,55 @@ def test_delete_model(self):
)
model.delete()

@responses.activate
def test_update_model_features(self):
base_url = 'http://api:9000'
model_id = uuid.uuid4()
column_def = ColumnDefinition(
name='column', type=SupportedTypes.string, field_type=FieldType.categorical
)
outputs = OutputType(prediction=column_def, output=[column_def])
model = Model(
base_url,
ModelDefinition(
uuid=model_id,
name='My Model',
model_type=ModelType.BINARY,
data_type=DataType.TABULAR,
granularity=Granularity.MONTH,
features=[column_def],
outputs=outputs,
target=column_def,
timestamp=column_def,
created_at=str(time.time()),
updated_at=str(time.time()),
),
)
new_features = [
ColumnDefinition(
name='column1',
type=SupportedTypes.string,
field_type=FieldType.categorical,
),
ColumnDefinition(
name='column2', type=SupportedTypes.int, field_type=FieldType.numerical
),
ColumnDefinition(
name='column3',
type=SupportedTypes.bool,
field_type=FieldType.categorical,
),
]
responses.add(
method=responses.POST,
url=f'{base_url}/api/models/{str(model_id)}',
body=ModelFeatures(features=new_features).model_dump_json(),
status=200,
)
model.update_features(new_features)

assert model.features() == new_features

@mock_aws
@responses.activate
def test_load_reference_dataset_without_object_name(self):
Expand Down