From 1c7e1e70890c2dd636d709e67440e7de001c8f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C4=99czek?= Date: Thu, 7 Nov 2024 11:12:00 +0100 Subject: [PATCH] Create POC for simplifications --- .../core/entities/responses/workflows.py | 10 +- .../query_language/entities/introspection.py | 10 +- .../query_language/entities/operations.py | 415 ++++++++++-------- .../execution_engine/entities/types.py | 10 +- .../introspection/connections_discovery.py | 4 +- .../introspection/entities.py | 2 +- .../introspection/schema_parser.py | 5 +- .../unit_tests/core/cache/test_serializers.py | 16 +- 8 files changed, 258 insertions(+), 214 deletions(-) diff --git a/inference/core/entities/responses/workflows.py b/inference/core/entities/responses/workflows.py index afc94f93b..9e4688892 100644 --- a/inference/core/entities/responses/workflows.py +++ b/inference/core/entities/responses/workflows.py @@ -67,17 +67,17 @@ def from_internal_entity( nested_operation_input_kind, nested_operation_output_kind = None, None if operation_description.nested_operation_input_kind: nested_operation_input_kind = [ - k.name for k in operation_description.nested_operation_input_kind + k for k in operation_description.nested_operation_input_kind ] if operation_description.nested_operation_output_kind: nested_operation_output_kind = [ - k.name for k in operation_description.nested_operation_output_kind + k for k in operation_description.nested_operation_output_kind ] return cls( operation_type=operation_description.operation_type, compound=operation_description.compound, - input_kind=[k.name for k in operation_description.input_kind], - output_kind=[k.name for k in operation_description.output_kind], + input_kind=[k for k in operation_description.input_kind], + output_kind=[k for k in operation_description.output_kind], nested_operation_input_kind=nested_operation_input_kind, nested_operation_output_kind=nested_operation_output_kind, description=operation_description.description, @@ -95,7 +95,7 @@ def from_internal_entity( cls, operator_description: OperatorDescription ) -> "ExternalOperatorDescription": operands_kinds = [ - [k.name for k in kind] for kind in operator_description.operands_kinds + [k for k in kind] for kind in operator_description.operands_kinds ] return cls( operator_type=operator_description.operator_type, diff --git a/inference/core/workflows/core_steps/common/query_language/entities/introspection.py b/inference/core/workflows/core_steps/common/query_language/entities/introspection.py index 779ba1aca..bb935d26c 100644 --- a/inference/core/workflows/core_steps/common/query_language/entities/introspection.py +++ b/inference/core/workflows/core_steps/common/query_language/entities/introspection.py @@ -8,15 +8,15 @@ class OperationDescription(BaseModel): operation_type: str compound: bool - input_kind: List[Kind] - output_kind: List[Kind] - nested_operation_input_kind: Optional[List[Kind]] = None - nested_operation_output_kind: Optional[List[Kind]] = None + input_kind: List[str] + output_kind: List[str] + nested_operation_input_kind: Optional[List[str]] = None + nested_operation_output_kind: Optional[List[str]] = None description: Optional[str] = None class OperatorDescription(BaseModel): operator_type: str operands_number: int - operands_kinds: List[List[Kind]] + operands_kinds: List[List[str]] description: Optional[str] = None diff --git a/inference/core/workflows/core_steps/common/query_language/entities/operations.py b/inference/core/workflows/core_steps/common/query_language/entities/operations.py index d20f0f404..5039b2522 100644 --- a/inference/core/workflows/core_steps/common/query_language/entities/operations.py +++ b/inference/core/workflows/core_steps/common/query_language/entities/operations.py @@ -46,8 +46,8 @@ class StringToLowerCase(OperationDefinition): json_schema_extra={ "description": "Executes lowercase operation on input string", "compound": False, - "input_kind": [STRING_KIND], - "output_kind": [STRING_KIND], + "input_kind": [STRING_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["StringToLowerCase"] @@ -58,8 +58,8 @@ class StringToUpperCase(OperationDefinition): json_schema_extra={ "description": "Executes uppercase operation on input string", "compound": False, - "input_kind": [STRING_KIND], - "output_kind": [STRING_KIND], + "input_kind": [STRING_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["StringToUpperCase"] @@ -70,8 +70,8 @@ class LookupTable(OperationDefinition): json_schema_extra={ "description": "Changes value according to mapping stated in lookup table", "compound": False, - "input_kind": [WILDCARD_KIND], - "output_kind": [WILDCARD_KIND], + "input_kind": [WILDCARD_KIND.name], + "output_kind": [WILDCARD_KIND.name], }, ) type: Literal["LookupTable"] @@ -84,13 +84,17 @@ class ToNumber(OperationDefinition): "description": "Changes value into number - float or int depending on configuration", "compound": False, "input_kind": [ - STRING_KIND, - BOOLEAN_KIND, - INTEGER_KIND, - FLOAT_KIND, - FLOAT_ZERO_TO_ONE_KIND, + STRING_KIND.name, + BOOLEAN_KIND.name, + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], + "output_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, ], - "output_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], }, ) type: Literal["ToNumber"] @@ -102,8 +106,16 @@ class NumberRound(OperationDefinition): json_schema_extra={ "description": "Rounds the number", "compound": False, - "input_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - "output_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + "input_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], + "output_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], }, ) type: Literal["NumberRound"] @@ -115,10 +127,10 @@ class SequenceMap(OperationDefinition): json_schema_extra={ "description": "Changes each value of sequence according to mapping stated in lookup table", "compound": True, - "input_kind": [LIST_OF_VALUES_KIND], - "output_kind": [LIST_OF_VALUES_KIND], - "nested_operation_input_kind": [WILDCARD_KIND], - "nested_operation_output_kind": [WILDCARD_KIND], + "input_kind": [LIST_OF_VALUES_KIND.name], + "output_kind": [LIST_OF_VALUES_KIND.name], + "nested_operation_input_kind": [WILDCARD_KIND.name], + "nested_operation_output_kind": [WILDCARD_KIND.name], }, ) type: Literal["SequenceMap"] @@ -130,8 +142,12 @@ class NumericSequenceAggregate(OperationDefinition): json_schema_extra={ "description": "Aggregates numeric sequence using aggregation function like min or max - adjusted to work on numbers", "compound": False, - "input_kind": [LIST_OF_VALUES_KIND], - "output_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + "input_kind": [LIST_OF_VALUES_KIND.name], + "output_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], }, ) type: Literal["NumericSequenceAggregate"] @@ -144,8 +160,8 @@ class SequenceAggregate(OperationDefinition): json_schema_extra={ "description": "Aggregates sequence using generic aggregation methods - adjusted to majority data types", "compound": False, - "input_kind": [LIST_OF_VALUES_KIND], - "output_kind": [WILDCARD_KIND], + "input_kind": [LIST_OF_VALUES_KIND.name], + "output_kind": [WILDCARD_KIND.name], }, ) type: Literal["SequenceAggregate"] @@ -157,8 +173,8 @@ class ToString(OperationDefinition): json_schema_extra={ "description": "Stringifies data", "compound": False, - "input_kind": [WILDCARD_KIND], - "output_kind": [STRING_KIND], + "input_kind": [WILDCARD_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["ToString"] @@ -169,8 +185,12 @@ class ToBoolean(OperationDefinition): json_schema_extra={ "description": "Changes input data into boolean", "compound": False, - "input_kind": [FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND, INTEGER_KIND], - "output_kind": [BOOLEAN_KIND], + "input_kind": [ + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + INTEGER_KIND.name, + ], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["ToBoolean"] @@ -181,8 +201,8 @@ class StringSubSequence(OperationDefinition): json_schema_extra={ "description": "Takes sub-string of the input string", "compound": False, - "input_kind": [STRING_KIND], - "output_kind": [STRING_KIND], + "input_kind": [STRING_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["StringSubSequence"] @@ -197,11 +217,11 @@ class DetectionsPropertyExtract(OperationDefinition): "(as a list of elements - one element represents single detection)", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], - "output_kind": [LIST_OF_VALUES_KIND], + "output_kind": [LIST_OF_VALUES_KIND.name], }, ) type: Literal["DetectionsPropertyExtract"] @@ -214,11 +234,11 @@ class DetectionsToDictionary(OperationDefinition): "description": "Converts detections into `inference` response format dictionary", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], - "output_kind": [DICTIONARY_KIND], + "output_kind": [DICTIONARY_KIND.name], }, ) type: Literal["DetectionsToDictionary"] @@ -231,9 +251,13 @@ class ClassificationPropertyExtract(OperationDefinition): "(as a list of elements - one element represents single detection)", "compound": False, "input_kind": [ - CLASSIFICATION_PREDICTION_KIND, + CLASSIFICATION_PREDICTION_KIND.name, + ], + "output_kind": [ + STRING_KIND.name, + LIST_OF_VALUES_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, ], - "output_kind": [STRING_KIND, LIST_OF_VALUES_KIND, FLOAT_ZERO_TO_ONE_KIND], }, ) type: Literal["ClassificationPropertyExtract"] @@ -246,14 +270,14 @@ class DetectionsSelection(OperationDefinition): "description": "Selects bounding boxes based on predefined criterias", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], }, ) @@ -266,8 +290,8 @@ class ExtractDetectionProperty(OperationDefinition): json_schema_extra={ "description": "Extracts property from single detection", "compound": False, - "input_kind": [DETECTION_KIND], - "output_kind": [WILDCARD_KIND], + "input_kind": [DETECTION_KIND.name], + "output_kind": [WILDCARD_KIND.name], }, ) type: Literal["ExtractDetectionProperty"] @@ -281,17 +305,17 @@ class DetectionsFilter(OperationDefinition): "applying filter operation in context of every single detection within prediction", "compound": True, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], - "nested_operation_input_kind": [DETECTION_KIND], - "nested_operation_output_kind": [BOOLEAN_KIND], + "nested_operation_input_kind": [DETECTION_KIND.name], + "nested_operation_output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["DetectionsFilter"] @@ -304,14 +328,14 @@ class SortDetections(OperationDefinition): "description": "Changes the order of detected bounding boxes.", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], }, ) @@ -326,14 +350,14 @@ class DetectionsOffset(OperationDefinition): "description": "Makes detected bounding boxes bigger by applying offset to its size", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], }, ) @@ -348,14 +372,14 @@ class DetectionsShift(OperationDefinition): "description": "Shifting detected bounding boxes in assigned direction", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], }, ) @@ -370,12 +394,12 @@ class RandomNumber(OperationDefinition): "description": "Special operation to let random sampling - ignoring input data and changing it " "into random floating point value. To be used mainly to sample predictions or images.", "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, - WILDCARD_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, + WILDCARD_KIND.name, ], - "output_kind": [FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + "output_kind": [FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], }, ) type: Literal["RandomNumber"] @@ -387,8 +411,8 @@ class ExtractImageProperty(OperationDefinition): model_config = ConfigDict( json_schema_extra={ "description": "Extracts specific property of image (like size)", - "input_kind": [IMAGE_KIND], - "output_kind": [INTEGER_KIND], + "input_kind": [IMAGE_KIND.name], + "output_kind": [INTEGER_KIND.name], }, ) type: Literal["ExtractImageProperty"] @@ -399,8 +423,8 @@ class ConvertImageToJPEG(OperationDefinition): model_config = ConfigDict( json_schema_extra={ "description": "Converts image to JPEG", - "input_kind": [IMAGE_KIND], - "output_kind": [BYTES_KIND], + "input_kind": [IMAGE_KIND.name], + "output_kind": [BYTES_KIND.name], }, ) type: Literal["ConvertImageToJPEG"] @@ -411,8 +435,8 @@ class ConvertDictionaryToJSON(OperationDefinition): model_config = ConfigDict( json_schema_extra={ "description": "Converts dictionary to serialized JSON", - "input_kind": [DICTIONARY_KIND], - "output_kind": [STRING_KIND], + "input_kind": [DICTIONARY_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["ConvertDictionaryToJSON"] @@ -422,8 +446,8 @@ class ConvertImageToBase64(OperationDefinition): model_config = ConfigDict( json_schema_extra={ "description": "Converts image to base64-encoded JPEG", - "input_kind": [IMAGE_KIND], - "output_kind": [STRING_KIND], + "input_kind": [IMAGE_KIND.name], + "output_kind": [STRING_KIND.name], }, ) type: Literal["ConvertImageToBase64"] @@ -434,8 +458,8 @@ class StringMatches(OperationDefinition): json_schema_extra={ "description": "Checks if string matches regex", "compound": False, - "input_kind": [STRING_KIND], - "output_kind": [BOOLEAN_KIND], + "input_kind": [STRING_KIND.name], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["StringMatches"] @@ -448,13 +472,13 @@ class SequenceLength(OperationDefinition): "description": "Operation determines the length of input sequence", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, - LIST_OF_VALUES_KIND, - DICTIONARY_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, + LIST_OF_VALUES_KIND.name, + DICTIONARY_KIND.name, ], - "output_kind": [INTEGER_KIND], + "output_kind": [INTEGER_KIND.name], }, ) type: Literal["SequenceLength"] @@ -465,10 +489,10 @@ class SequenceApply(OperationDefinition): json_schema_extra={ "description": "Operation applies chain of operations at every element of sequence", "compound": True, - "input_kind": [LIST_OF_VALUES_KIND], - "output_kind": [LIST_OF_VALUES_KIND], - "nested_operation_input_kind": [WILDCARD_KIND], - "nested_operation_output_kind": [WILDCARD_KIND], + "input_kind": [LIST_OF_VALUES_KIND.name], + "output_kind": [LIST_OF_VALUES_KIND.name], + "nested_operation_input_kind": [WILDCARD_KIND.name], + "nested_operation_output_kind": [WILDCARD_KIND.name], }, ) type: Literal["SequenceApply"] @@ -480,8 +504,16 @@ class Multiply(OperationDefinition): json_schema_extra={ "description": "Multiplication", "compound": False, - "input_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - "output_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + "input_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], + "output_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], }, ) type: Literal["Multiply"] @@ -493,8 +525,16 @@ class Divide(OperationDefinition): json_schema_extra={ "description": "Dividing value against other", "compound": False, - "input_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - "output_kind": [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + "input_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], + "output_kind": [ + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], }, ) type: Literal["Divide"] @@ -507,14 +547,14 @@ class DetectionsRename(OperationDefinition): "description": "Renames classes in detections based on provided mapping", "compound": False, "input_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], "output_kind": [ - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], }, ) @@ -589,23 +629,23 @@ class Equals(BinaryOperator): "operands_number": 2, "operands_kinds": [ [ - INTEGER_KIND, - STRING_KIND, - FLOAT_KIND, - FLOAT_ZERO_TO_ONE_KIND, - BOOLEAN_KIND, - LIST_OF_VALUES_KIND, + INTEGER_KIND.name, + STRING_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + BOOLEAN_KIND.name, + LIST_OF_VALUES_KIND.name, ], [ - INTEGER_KIND, - STRING_KIND, - FLOAT_KIND, - FLOAT_ZERO_TO_ONE_KIND, - BOOLEAN_KIND, - LIST_OF_VALUES_KIND, + INTEGER_KIND.name, + STRING_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + BOOLEAN_KIND.name, + LIST_OF_VALUES_KIND.name, ], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) ==", "=="] @@ -618,23 +658,23 @@ class NotEquals(BinaryOperator): "operands_number": 2, "operands_kinds": [ [ - INTEGER_KIND, - STRING_KIND, - FLOAT_KIND, - FLOAT_ZERO_TO_ONE_KIND, - BOOLEAN_KIND, - LIST_OF_VALUES_KIND, + INTEGER_KIND.name, + STRING_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + BOOLEAN_KIND.name, + LIST_OF_VALUES_KIND.name, ], [ - INTEGER_KIND, - STRING_KIND, - FLOAT_KIND, - FLOAT_ZERO_TO_ONE_KIND, - BOOLEAN_KIND, - LIST_OF_VALUES_KIND, + INTEGER_KIND.name, + STRING_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + BOOLEAN_KIND.name, + LIST_OF_VALUES_KIND.name, ], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) !=", "!="] @@ -646,10 +686,10 @@ class NumberGreater(BinaryOperator): "description": "Checks if first value (number) is greater than the second value (number)", "operands_number": 2, "operands_kinds": [ - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) >"] @@ -661,10 +701,10 @@ class NumberGreaterEqual(BinaryOperator): "description": "Checks if first value (number) is greater or equal than the second value (number)", "operands_number": 2, "operands_kinds": [ - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) >="] @@ -676,10 +716,10 @@ class NumberLower(BinaryOperator): "description": "Checks if first value (number) is lower than the second value (number)", "operands_number": 2, "operands_kinds": [ - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) <"] @@ -691,10 +731,10 @@ class NumberLowerEqual(BinaryOperator): "description": "Checks if first value (number) is lower or equal than the second value (number)", "operands_number": 2, "operands_kinds": [ - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - [INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], + [INTEGER_KIND.name, FLOAT_KIND.name, FLOAT_ZERO_TO_ONE_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Number) <="] @@ -706,10 +746,10 @@ class StringStartsWith(BinaryOperator): "description": "Checks if string given as first value starts with string provided as second value", "operands_number": 2, "operands_kinds": [ - [STRING_KIND], - [STRING_KIND], + [STRING_KIND.name], + [STRING_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(String) startsWith"] @@ -721,10 +761,10 @@ class StringEndsWith(BinaryOperator): "description": "Checks if string given as first value ends with string provided as second value", "operands_number": 2, "operands_kinds": [ - [STRING_KIND], - [STRING_KIND], + [STRING_KIND.name], + [STRING_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(String) endsWith"] @@ -736,10 +776,10 @@ class StringContains(BinaryOperator): "description": "Checks if string given as first value contains string provided as second value", "operands_number": 2, "operands_kinds": [ - [STRING_KIND], - [STRING_KIND], + [STRING_KIND.name], + [STRING_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(String) contains"] @@ -751,10 +791,15 @@ class In(BinaryOperator): "description": "Checks if first value is element of second value (usually list or dictionary)", "operands_number": 2, "operands_kinds": [ - [STRING_KIND, INTEGER_KIND, FLOAT_KIND, FLOAT_ZERO_TO_ONE_KIND], - [LIST_OF_VALUES_KIND, DICTIONARY_KIND], + [ + STRING_KIND.name, + INTEGER_KIND.name, + FLOAT_KIND.name, + FLOAT_ZERO_TO_ONE_KIND.name, + ], + [LIST_OF_VALUES_KIND.name, DICTIONARY_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["in (Sequence)"] @@ -766,10 +811,10 @@ class AllInSequence(BinaryOperator): "description": "Checks if all elements of first value are elements of second value (usually list)", "operands_number": 2, "operands_kinds": [ - [LIST_OF_VALUES_KIND], - [LIST_OF_VALUES_KIND], + [LIST_OF_VALUES_KIND.name], + [LIST_OF_VALUES_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["all in (Sequence)"] @@ -781,10 +826,10 @@ class AnyInSequence(BinaryOperator): "description": "Checks if any element of first value is element of second value (usually list)", "operands_number": 2, "operands_kinds": [ - [LIST_OF_VALUES_KIND], - [LIST_OF_VALUES_KIND], + [LIST_OF_VALUES_KIND.name], + [LIST_OF_VALUES_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["any in (Sequence)"] @@ -800,9 +845,9 @@ class Exists(UnaryOperator): "description": "Checks if value is given (not `None`)", "operands_number": 1, "operands_kinds": [ - [WILDCARD_KIND], + [WILDCARD_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["Exists"] @@ -814,9 +859,9 @@ class DoesNotExist(UnaryOperator): "description": "Checks if value is not given (`None`)", "operands_number": 1, "operands_kinds": [ - [WILDCARD_KIND], + [WILDCARD_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["DoesNotExist"] @@ -828,9 +873,9 @@ class IsTrue(UnaryOperator): "description": "Checks if value is `True`", "operands_number": 1, "operands_kinds": [ - [BOOLEAN_KIND], + [BOOLEAN_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Boolean) is True"] @@ -842,9 +887,9 @@ class IsFalse(UnaryOperator): "description": "Checks if value is `False`", "operands_number": 1, "operands_kinds": [ - [BOOLEAN_KIND], + [BOOLEAN_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Boolean) is False"] @@ -857,14 +902,14 @@ class IsEmpty(UnaryOperator): "operands_number": 1, "operands_kinds": [ [ - LIST_OF_VALUES_KIND, - DICTIONARY_KIND, - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + LIST_OF_VALUES_KIND.name, + DICTIONARY_KIND.name, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Sequence) is empty"] @@ -877,14 +922,14 @@ class IsNotEmpty(UnaryOperator): "operands_number": 1, "operands_kinds": [ [ - LIST_OF_VALUES_KIND, - DICTIONARY_KIND, - OBJECT_DETECTION_PREDICTION_KIND, - INSTANCE_SEGMENTATION_PREDICTION_KIND, - KEYPOINT_DETECTION_PREDICTION_KIND, + LIST_OF_VALUES_KIND.name, + DICTIONARY_KIND.name, + OBJECT_DETECTION_PREDICTION_KIND.name, + INSTANCE_SEGMENTATION_PREDICTION_KIND.name, + KEYPOINT_DETECTION_PREDICTION_KIND.name, ], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Sequence) is not empty"] @@ -896,9 +941,9 @@ class DetectionInZone(BinaryOperator): "description": "Checks if detection is in zone", "operands_number": 2, "operands_kinds": [ - [DETECTION_KIND, ZONE_KIND], + [DETECTION_KIND.name, ZONE_KIND.name], ], - "output_kind": [BOOLEAN_KIND], + "output_kind": [BOOLEAN_KIND.name], }, ) type: Literal["(Detection) in zone"] diff --git a/inference/core/workflows/execution_engine/entities/types.py b/inference/core/workflows/execution_engine/entities/types.py index 748fe3c52..5337752cf 100644 --- a/inference/core/workflows/execution_engine/entities/types.py +++ b/inference/core/workflows/execution_engine/entities/types.py @@ -1054,7 +1054,7 @@ def StepOutputSelector(kind: Optional[List[Kind]] = None): json_schema_extra = { REFERENCE_KEY: True, SELECTED_ELEMENT_KEY: STEP_OUTPUT_AS_SELECTED_ELEMENT, - KIND_KEY: [k.dict() for k in kind], + KIND_KEY: [k.name for k in kind], } return Annotated[ str, @@ -1069,7 +1069,7 @@ def WorkflowParameterSelector(kind: Optional[List[Kind]] = None): json_schema_extra = { REFERENCE_KEY: True, SELECTED_ELEMENT_KEY: "workflow_parameter", - KIND_KEY: [k.dict() for k in kind], + KIND_KEY: [k.name for k in kind], } return Annotated[ str, @@ -1085,7 +1085,7 @@ def WorkflowParameterSelector(kind: Optional[List[Kind]] = None): json_schema_extra={ REFERENCE_KEY: True, SELECTED_ELEMENT_KEY: "workflow_image", - KIND_KEY: [IMAGE_KIND.dict()], + KIND_KEY: [IMAGE_KIND.name], } ), ] @@ -1097,7 +1097,7 @@ def WorkflowParameterSelector(kind: Optional[List[Kind]] = None): json_schema_extra={ REFERENCE_KEY: True, SELECTED_ELEMENT_KEY: STEP_OUTPUT_AS_SELECTED_ELEMENT, - KIND_KEY: [IMAGE_KIND.dict()], + KIND_KEY: [IMAGE_KIND.name], } ), ] @@ -1112,7 +1112,7 @@ def WorkflowParameterSelector(kind: Optional[List[Kind]] = None): json_schema_extra={ REFERENCE_KEY: True, SELECTED_ELEMENT_KEY: "workflow_video_metadata", - KIND_KEY: [VIDEO_METADATA_KIND.dict()], + KIND_KEY: [VIDEO_METADATA_KIND.name], } ), ] diff --git a/inference/core/workflows/execution_engine/introspection/connections_discovery.py b/inference/core/workflows/execution_engine/introspection/connections_discovery.py index 7aec6d53a..384839599 100644 --- a/inference/core/workflows/execution_engine/introspection/connections_discovery.py +++ b/inference/core/workflows/execution_engine/introspection/connections_discovery.py @@ -126,7 +126,7 @@ def get_all_inputs_kind_major( if allowed_reference.selected_element == STEP_AS_SELECTED_ELEMENT: continue for single_kind in allowed_reference.kind: - kind_major_step_inputs[single_kind.name].add( + kind_major_step_inputs[single_kind].add( BlockPropertySelectorDefinition( block_type=block_description.block_class, manifest_type_identifier=block_description.manifest_type_identifier, @@ -176,7 +176,7 @@ def discover_block_input_connections( continue for single_kind in allowed_reference.kind: blocks_matching_property.update( - output_kind2schemas.get(single_kind.name, set()) + output_kind2schemas.get(single_kind, set()) ) result[selector.property_name] = blocks_matching_property return result diff --git a/inference/core/workflows/execution_engine/introspection/entities.py b/inference/core/workflows/execution_engine/introspection/entities.py index 8fba19528..bd0ad144b 100644 --- a/inference/core/workflows/execution_engine/introspection/entities.py +++ b/inference/core/workflows/execution_engine/introspection/entities.py @@ -17,7 +17,7 @@ @dataclass(frozen=True) class ReferenceDefinition: selected_element: str - kind: List[Kind] + kind: List[str] @dataclass(frozen=True) diff --git a/inference/core/workflows/execution_engine/introspection/schema_parser.py b/inference/core/workflows/execution_engine/introspection/schema_parser.py index 01976fa56..329fce9cc 100644 --- a/inference/core/workflows/execution_engine/introspection/schema_parser.py +++ b/inference/core/workflows/execution_engine/introspection/schema_parser.py @@ -284,10 +284,7 @@ def retrieve_selectors_from_simple_property( allowed_references = [ ReferenceDefinition( selected_element=property_definition[SELECTED_ELEMENT_KEY], - kind=[ - Kind.model_validate(k) - for k in property_definition.get(KIND_KEY, []) - ], + kind=[k for k in property_definition.get(KIND_KEY, [])], ) ] return SelectorDefinition( diff --git a/tests/inference/unit_tests/core/cache/test_serializers.py b/tests/inference/unit_tests/core/cache/test_serializers.py index 8c982f6de..0d294e31b 100644 --- a/tests/inference/unit_tests/core/cache/test_serializers.py +++ b/tests/inference/unit_tests/core/cache/test_serializers.py @@ -1,9 +1,11 @@ import os from unittest.mock import MagicMock + import pytest + from inference.core.cache.serializers import ( - to_cachable_inference_item, build_condensed_response, + to_cachable_inference_item, ) from inference.core.entities.requests.inference import ( ClassificationInferenceRequest, @@ -11,16 +13,16 @@ ) from inference.core.entities.responses.inference import ( ClassificationInferenceResponse, - MultiLabelClassificationInferenceResponse, + ClassificationPrediction, InstanceSegmentationInferenceResponse, + InstanceSegmentationPrediction, + Keypoint, KeypointsDetectionInferenceResponse, + KeypointsPrediction, + MultiLabelClassificationInferenceResponse, + MultiLabelClassificationPrediction, ObjectDetectionInferenceResponse, ObjectDetectionPrediction, - ClassificationPrediction, - MultiLabelClassificationPrediction, - InstanceSegmentationPrediction, - KeypointsPrediction, - Keypoint, Point, )