[FEATS] [BlockList] [BlockDict] [block]

pull/339/head
Kye 1 year ago committed by evelynmitchell
parent 9622fd5d82
commit 61bbba4117

@ -28,6 +28,8 @@ from swarms.structs.utils import (
parse_tasks,
detect_markdown,
)
from swarms.structs.task import Task
from swarms.structs.block_wrapper import block
__all__ = [
"Agent",
@ -66,5 +68,10 @@ __all__ = [
=======
"BaseStructure",
"detect_markdown",
<<<<<<< HEAD
>>>>>>> 1df42a3 ([BUGFIX][Conversation] [swarm.tools])
=======
"Task",
"block"
>>>>>>> 8e1a024 ([FEATS] [BlockList] [BlockDict] [block])
]

@ -1,6 +1,5 @@
from typing import Callable, Any
import logging
from functools import wraps
from typing import Any, Callable
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@ -20,8 +19,6 @@ def block(
Returns:
Callable[..., Any]: The transformed function.
"""
@wraps(function)
def wrapper(*args, **kwargs):
# Here you can add code to execute the function on various hardwares
# For now, we'll just call the function normally

@ -36,15 +36,6 @@ class BlocksList(BaseStructure):
get_by_parent_name(parent_name: str): Get blocks by parent name.
get_by_parent_type(parent_type: str): Get blocks by parent type.
get_by_parent_description(parent_description: str): Get blocks by parent description.
Examples:
>>> from swarms.structs.block import Block
>>> from swarms.structs.blockslist import BlocksList
>>> block = Block("block", "A block")
>>> blockslist = BlocksList("blockslist", "A list of blocks", [block])
>>> blockslist
"""
def __init__(
@ -56,10 +47,8 @@ class BlocksList(BaseStructure):
**kwargs,
):
super().__init__(name=name, description=description, **kwargs)
self.name = name
self.description = description
self.blocks = blocks
self.parent = parent
self.blocks = blocks
def add(self, block: Any):
self.blocks.append(block)
@ -76,26 +65,6 @@ class BlocksList(BaseStructure):
def get_all(self):
return self.blocks
def run_block(self, block: Any, task: str, *args, **kwargs):
"""Run the block for the specified task.
Args:
task (str): The task to be performed by the block.
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
Returns:
The output of the block.
Raises:
Exception: If an error occurs during the execution of the block.
"""
try:
return block.run(task, *args, **kwargs)
except Exception as error:
print(f"[Error] [Block] {error}")
raise error
def get_by_name(self, name: str):
return [block for block in self.blocks if block.name == name]

Loading…
Cancel
Save