mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-09 22:35:54 -05:00
Compare commits
16 Commits
fix/execut
...
zamilmajdy
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12bd53f0ab | ||
|
|
a16a2c7ec9 | ||
|
|
2f61b3a5c6 | ||
|
|
8830a7f412 | ||
|
|
a035b937ac | ||
|
|
009b369a57 | ||
|
|
a0ecaa3e4d | ||
|
|
04dbc16df8 | ||
|
|
7e1be857f0 | ||
|
|
252cd2aa1e | ||
|
|
6d3503b0f2 | ||
|
|
80d25ba9fd | ||
|
|
dff3e9fefb | ||
|
|
eba8acf13f | ||
|
|
976c8d5afb | ||
|
|
57ddeb4574 |
@@ -2,13 +2,28 @@ from typing import Any
|
|||||||
|
|
||||||
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
|
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
|
||||||
from backend.data.model import SchemaField
|
from backend.data.model import SchemaField
|
||||||
|
from backend.util.json import json
|
||||||
|
|
||||||
|
|
||||||
class StepThroughItemsBlock(Block):
|
class StepThroughItemsBlock(Block):
|
||||||
class Input(BlockSchema):
|
class Input(BlockSchema):
|
||||||
items: list | dict = SchemaField(
|
items: list = SchemaField(
|
||||||
|
advanced=False,
|
||||||
description="The list or dictionary of items to iterate over",
|
description="The list or dictionary of items to iterate over",
|
||||||
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
|
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
|
||||||
|
default=[],
|
||||||
|
)
|
||||||
|
items_object: dict = SchemaField(
|
||||||
|
advanced=False,
|
||||||
|
description="The list or dictionary of items to iterate over",
|
||||||
|
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
|
||||||
|
default={},
|
||||||
|
)
|
||||||
|
items_str: str = SchemaField(
|
||||||
|
advanced=False,
|
||||||
|
description="The list or dictionary of items to iterate over",
|
||||||
|
placeholder="[1, 2, 3, 4, 5] or {'key1': 'value1', 'key2': 'value2'}",
|
||||||
|
default="",
|
||||||
)
|
)
|
||||||
|
|
||||||
class Output(BlockSchema):
|
class Output(BlockSchema):
|
||||||
@@ -39,14 +54,20 @@ class StepThroughItemsBlock(Block):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def run(self, input_data: Input, **kwargs) -> BlockOutput:
|
def run(self, input_data: Input, **kwargs) -> BlockOutput:
|
||||||
items = input_data.items
|
for data in [input_data.items, input_data.items_object, input_data.items_str]:
|
||||||
if isinstance(items, dict):
|
if not data:
|
||||||
# If items is a dictionary, iterate over its values
|
continue
|
||||||
for item in items.values():
|
if isinstance(data, str):
|
||||||
yield "item", item
|
items = json.loads(data)
|
||||||
yield "key", item
|
else:
|
||||||
else:
|
items = data
|
||||||
# If items is a list, iterate over the list
|
if isinstance(items, dict):
|
||||||
for index, item in enumerate(items):
|
# If items is a dictionary, iterate over its values
|
||||||
yield "item", item
|
for item in items.values():
|
||||||
yield "key", index
|
yield "item", item
|
||||||
|
yield "key", item
|
||||||
|
else:
|
||||||
|
# If items is a list, iterate over the list
|
||||||
|
for index, item in enumerate(items):
|
||||||
|
yield "item", item
|
||||||
|
yield "key", index
|
||||||
|
|||||||
@@ -140,20 +140,25 @@ class GetCurrentDateAndTimeBlock(Block):
|
|||||||
class CountdownTimerBlock(Block):
|
class CountdownTimerBlock(Block):
|
||||||
class Input(BlockSchema):
|
class Input(BlockSchema):
|
||||||
input_message: Any = SchemaField(
|
input_message: Any = SchemaField(
|
||||||
|
advanced=False,
|
||||||
description="Message to output after the timer finishes",
|
description="Message to output after the timer finishes",
|
||||||
default="timer finished",
|
default="timer finished",
|
||||||
)
|
)
|
||||||
seconds: Union[int, str] = SchemaField(
|
seconds: Union[int, str] = SchemaField(
|
||||||
description="Duration in seconds", default=0
|
advanced=False, description="Duration in seconds", default=0
|
||||||
)
|
)
|
||||||
minutes: Union[int, str] = SchemaField(
|
minutes: Union[int, str] = SchemaField(
|
||||||
description="Duration in minutes", default=0
|
advanced=False, description="Duration in minutes", default=0
|
||||||
|
)
|
||||||
|
hours: Union[int, str] = SchemaField(
|
||||||
|
advanced=False, description="Duration in hours", default=0
|
||||||
|
)
|
||||||
|
days: Union[int, str] = SchemaField(
|
||||||
|
advanced=False, description="Duration in days", default=0
|
||||||
)
|
)
|
||||||
hours: Union[int, str] = SchemaField(description="Duration in hours", default=0)
|
|
||||||
days: Union[int, str] = SchemaField(description="Duration in days", default=0)
|
|
||||||
|
|
||||||
class Output(BlockSchema):
|
class Output(BlockSchema):
|
||||||
output_message: str = SchemaField(
|
output_message: Any = SchemaField(
|
||||||
description="Message after the timer finishes"
|
description="Message after the timer finishes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user