Skip to content

Commit ce51d98

Browse files
Merge pull request #24 from aixplain/ENG-478-Fixing-model-interfaces-inconsistencies
Correcting abstract method inconsistencies
2 parents ba22ce9 + 7c23d83 commit ce51d98

17 files changed

Lines changed: 389 additions & 301 deletions

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [1.0.0] - 2024-08-28
68

7-
## [v0.0.2] - 2024-07-25
9+
### Added
10+
- Test for TextGenerationChatModel.
11+
### Changed
12+
13+
### Fixed
14+
- Added @abstractmethod decorators to all abstract functions in function_models and aixplain_models.
15+
16+
## [0.0.2] - 2024-07-25
817

918
### Added
1019
- Added support for script nodes.

aixplain/model_interfaces/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = "model-interfaces"
22
__description__ = "model-interfaces is the interface to host your models on aiXplain"
33
__url__ = "https://github.com/aixplain/aixplain-models/tree/main/docs"
4-
__version__ = "0.0.2"
4+
__version__ = "1.0.0"
55
__author__ = "Duraikrishna Selvaraju and Michael Lam"
66
__author_email__ = "krishna.durai@aixplain.com"
77
__license__ = "http://www.apache.org/licenses/LICENSE-2.0"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from kserve.model import Model
22
from typing import Dict, List
3+
from abc import abstractmethod
4+
35
from aixplain.model_interfaces.schemas.function.function_input import APIInput
46
from aixplain.model_interfaces.schemas.function.function_output import APIOutput
57

68
class AixplainModel(Model):
79

10+
@abstractmethod
811
def run_model(self, api_input: Dict[str, List[APIInput]], headers: Dict[str, str] = None) -> Dict[str, List[APIOutput]]:
912
pass
1013

14+
@abstractmethod
1115
def predict(self, request: Dict[str, List[APIInput]], headers: Dict[str, str] = None) -> Dict[str, List[APIOutput]]:
1216
pass

aixplain/model_interfaces/interfaces/function_models.py

Lines changed: 183 additions & 232 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ includes = ["aixplain"]
1515

1616
[project]
1717
name = "model-interfaces"
18-
version = "0.0.2"
18+
version = "1.0.0"
1919
description = "A package specifying the model interfaces supported by aiXplain"
2020
license = { text = "Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0" }
2121
dependencies = [

tests/unit_tests/models/test_mock_classification.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def test_predict(self):
2626
predict_output = mock_model.predict(predict_input)
2727
output_dict = predict_output["predictions"][0]
2828

29-
assert output_dict["data"] == "positive"
30-
assert output_dict["predicted_labels"][0]["label"] == "positive"
31-
assert output_dict["predicted_labels"][0]["confidence"] == 0.7
29+
assert output_dict.data == "positive"
30+
assert output_dict.predicted_labels[0].label == "positive"
31+
assert output_dict.predicted_labels[0].confidence == 0.7
3232

3333
class MockModel(ClassificationModel):
34-
def run_model(self, api_input: Dict[str, List[ClassificationInput]], headers: Dict[str, str] = None) -> Dict[str, List[ClassificationOutput]]:
35-
instances = api_input["instances"]
34+
def run_model(self, api_input: List[ClassificationInput], headers: Dict[str, str] = None) -> List[ClassificationOutput]:
35+
instances = api_input
3636
predictions_list = []
3737
# There's only 1 instance in this case.
3838
for instance in instances:
@@ -50,7 +50,6 @@ def run_model(self, api_input: Dict[str, List[ClassificationInput]], headers: Di
5050
"data": data,
5151
"predicted_labels": labels
5252
}
53-
speech_recognition_output = ClassificationOutput(**output_dict)
54-
predictions_list.append(speech_recognition_output)
55-
predict_output = {"predictions": predictions_list}
56-
return predict_output
53+
classification_output = ClassificationOutput(**output_dict)
54+
predictions_list.append(classification_output)
55+
return predictions_list

tests/unit_tests/models/test_mock_diacritization.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ def test_predict(self):
2626
predict_output = mock_model.predict(predict_input)
2727
output_dict = predict_output["predictions"][0]
2828

29-
assert output_dict["data"] == "السَّلَامُ عَلَيْكُمْ"
30-
assert output_dict["details"]["text"] == "السَّلَامُ عَلَيْكُمْ"
31-
assert output_dict["details"]["confidence"] == 0.7
29+
assert output_dict.data == "السَّلَامُ عَلَيْكُمْ"
30+
assert output_dict.details.text == "السَّلَامُ عَلَيْكُمْ"
31+
assert output_dict.details.confidence == 0.7
3232

3333
class MockModel(DiacritizationModel):
34-
def run_model(self, api_input: Dict[str, List[DiacritizationInput]], headers: Dict[str, str] = None) -> Dict[str, List[DiacritizationOutput]]:
35-
instances = api_input["instances"]
34+
def run_model(self, api_input: List[DiacritizationInput], headers: Dict[str, str] = None) -> List[DiacritizationOutput]:
3635
predictions_list = []
3736
# There's only 1 instance in this case.
38-
for instance in instances:
37+
for instance in api_input:
3938
instance_data = instance.dict()
4039
model_instance = Mock()
4140
model_instance.process_data.return_value = ("السَّلَامُ عَلَيْكُمْ", 0.7)
@@ -52,5 +51,4 @@ def run_model(self, api_input: Dict[str, List[DiacritizationInput]], headers: Di
5251
}
5352
speech_recognition_output = DiacritizationOutput(**output_dict)
5453
predictions_list.append(speech_recognition_output)
55-
predict_output = {"predictions": predictions_list}
56-
return predict_output
54+
return predictions_list

tests/unit_tests/models/test_mock_fill_text_mask.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ def test_predict(self):
3131
predict_output = mock_model.predict(predict_input)
3232
output_dict = predict_output["predictions"][0]
3333

34-
assert output_dict["data"] == "We are filling a text mask."
34+
assert output_dict.data == "We are filling a text mask."
3535

3636
class MockModel(FillTextMaskModel):
37-
def run_model(self, api_input: Dict[str, List[FillTextMaskInput]], headers: Dict[str, str] = None) -> Dict[str, List[FillTextMaskOutput]]:
38-
instances = api_input["instances"]
37+
def run_model(self, api_input: List[FillTextMaskInput], headers: Dict[str, str] = None) -> List[FillTextMaskOutput]:
3938
predictions_list = []
4039
# There's only 1 instance in this case.
41-
for instance in instances:
40+
for instance in api_input:
4241
instance_data = instance.dict()
4342
model_instance = Mock()
4443
model_instance.process_data.return_value = "We are filling a text mask."
@@ -53,5 +52,4 @@ def run_model(self, api_input: Dict[str, List[FillTextMaskInput]], headers: Dict
5352
}
5453
output = FillTextMaskOutput(**output_dict)
5554
predictions_list.append(output)
56-
predict_output = {"predictions": predictions_list}
57-
return predict_output
55+
return predictions_list

tests/unit_tests/models/test_mock_speech_enhancement.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ def test_predict(self):
3535
predict_output = mock_model.predict(predict_input)
3636
output_dict = predict_output["predictions"][0]
3737

38-
assert output_dict["data"] == "VGhpcyBpcyBhbiBhdWRpbyBvdXRwdXQ="
38+
assert output_dict.data == "VGhpcyBpcyBhbiBhdWRpbyBvdXRwdXQ="
3939

4040
class MockModel(SpeechEnhancementModel):
41-
def run_model(self, api_input: Dict[str, List[SpeechEnhancementInput]], headers: Dict[str, str] = None) -> Dict[str, List[SpeechEnhancementOutput]]:
42-
instances = api_input["instances"]
41+
def run_model(self, api_input: List[SpeechEnhancementInput], headers: Dict[str, str] = None) -> List[SpeechEnhancementOutput]:
4342
predictions_list = []
4443
# There's only 1 instance in this case.
45-
for instance in instances:
44+
for instance in api_input:
4645
instance_data = instance.dict()
4746
model_instance = Mock()
4847
model_instance.process_data.return_value = encode(b"This is an audio output")
@@ -59,5 +58,4 @@ def run_model(self, api_input: Dict[str, List[SpeechEnhancementInput]], headers:
5958
}
6059
speech_recognition_output = SpeechEnhancementOutput(**output_dict)
6160
predictions_list.append(speech_recognition_output)
62-
predict_output = {"predictions": predictions_list}
63-
return predict_output
61+
return predictions_list

tests/unit_tests/models/test_mock_speech_recognition.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ def test_predict(self):
3535
predict_output = mock_model.predict(predict_input)
3636
output_dict = predict_output["predictions"][0]
3737

38-
assert output_dict["data"] == "This is a test transcription"
39-
assert output_dict["details"]["text"] == "This is a test transcription"
40-
assert output_dict["details"]["confidence"] == 0.7
38+
assert output_dict.data == "This is a test transcription"
39+
assert output_dict.details.text == "This is a test transcription"
40+
assert output_dict.details.confidence == 0.7
4141

4242
class MockModel(SpeechRecognitionModel):
43-
def run_model(self, api_input: Dict[str, List[SpeechRecognitionInput]], headers: Dict[str, str] = None) -> Dict[str, List[SpeechRecognitionOutput]]:
44-
instances = api_input["instances"]
43+
def run_model(self, api_input: List[SpeechRecognitionInput], headers: Dict[str, str] = None) -> List[SpeechRecognitionOutput]:
4544
predictions_list = []
4645
# There's only 1 instance in this case.
47-
for instance in instances:
46+
for instance in api_input:
4847
instance_data = instance.dict()
4948
model_instance = Mock()
5049
model_instance.process_data.return_value = ("This is a test transcription", 0.7)
@@ -61,5 +60,4 @@ def run_model(self, api_input: Dict[str, List[SpeechRecognitionInput]], headers:
6160
}
6261
speech_recognition_output = SpeechRecognitionOutput(**output_dict)
6362
predictions_list.append(speech_recognition_output)
64-
predict_output = {"predictions": predictions_list}
65-
return predict_output
63+
return predictions_list

0 commit comments

Comments
 (0)