Skip to content

Commit

Permalink
Merge pull request #702 from roboflow/dynamic_block_descriptions
Browse files Browse the repository at this point in the history
Add optional descriptions to dynamic blocks
  • Loading branch information
PawelPeczek-Roboflow authored Oct 3, 2024
2 parents 85b1a3c + 05c3d61 commit 489c242
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
from inference.core.workflows.execution_engine.v1.compiler.entities import (
BlockSpecification,
)
from inference.core.workflows.execution_engine.v1.dynamic_blocks.entities import (
BLOCK_SOURCE,
)
from inference.core.workflows.prototypes.block import WorkflowBlock

WORKFLOWS_PLUGINS_ENV = "WORKFLOWS_PLUGINS"
Expand Down Expand Up @@ -287,18 +290,27 @@ def _validate_loaded_blocks_manifest_type_identifiers(
for type_name in all_types:
if type_name in types_already_defined:
clashing_block = types_already_defined[type_name]
block_identifier = _produce_readable_block_identifier(block=block)
clashing_block_identifier = _produce_readable_block_identifier(
block=clashing_block
)
raise PluginLoadingError(
public_message=f"Block defined in {block.block_source} plugin with fully qualified class "
f"name {block.fully_qualified_block_class_name} clashes in terms of "
f"the manifest type identifier (or its alias): {type_name} - defined in "
f"{clashing_block.block_source} with fully qualified class name: "
f"{clashing_block.fully_qualified_block_class_name}.",
public_message=f"Block `{block_identifier}`, defined in `{block.block_source}` plugin,"
f"clashes in terms of the manifest type identifier (or its alias): "
f"`{type_name}` with `{clashing_block_identifier}` defined in "
f"`{clashing_block.block_source}` plugin.",
context="blocks_loading",
)
types_already_defined[type_name] = block
return None


def _produce_readable_block_identifier(block: BlockDescription) -> str:
if block.block_source == BLOCK_SOURCE:
return block.human_friendly_block_name
return block.fully_qualified_block_class_name


def _validate_used_kinds_uniqueness(declared_kinds: List[Kind]) -> None:
kinds_names_counter = Counter(k.name for k in declared_kinds)
non_unique_kinds = [k for k, v in kinds_names_counter.items() if v > 1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def assembly_dynamic_block_manifest(
json_schema_extra={
"name": build_human_friendly_block_name(
fully_qualified_name=manifest_description.block_type
)
),
"short_description": manifest_description.description,
},
),
name=(str, ...),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class ManifestDescription(BaseModel):
description="Field holds type of the bock to be dynamically created. Block can be initialised "
"as step using the type declared in the field."
)
description: Optional[str] = Field(
default=None, description="Description of the block to be used in manifest"
)
inputs: Dict[str, DynamicInputDefinition] = Field(
description="Mapping name -> input definition for block inputs (parameters for run() function of"
"dynamic block)"
Expand Down

0 comments on commit 489c242

Please sign in to comment.