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

Add optional descriptions to dynamic blocks #702

Merged
merged 4 commits into from
Oct 3, 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
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
Loading