mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
Logic Blocks
This commit is contained in:
0
rnd/autogpt_server/autogpt_server/blocks/README.md
Normal file
0
rnd/autogpt_server/autogpt_server/blocks/README.md
Normal file
44
rnd/autogpt_server/autogpt_server/blocks/logic.py
Normal file
44
rnd/autogpt_server/autogpt_server/blocks/logic.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from typing import ClassVar, Any
|
||||
from autogpt_server.data.block import Block, BlockSchema, BlockData
|
||||
|
||||
|
||||
class IfBlock(Block):
|
||||
id: ClassVar[str] = "db7d8f02-2f44-4c55-ab7a-eae0941f0c31" # type: ignore
|
||||
input_schema: ClassVar[BlockSchema] = BlockSchema(
|
||||
{ # type: ignore
|
||||
"condition": "string",
|
||||
"variables": "Dict[string, Any]",
|
||||
}
|
||||
)
|
||||
output_schema: ClassVar[BlockSchema] = BlockSchema(
|
||||
{ # type: ignore
|
||||
"result": "bool",
|
||||
}
|
||||
)
|
||||
|
||||
async def run(self, input_data: BlockData) -> tuple[str, Any]:
|
||||
for key in input_data.keys():
|
||||
eval(f"{key} = {input_data[key]}")
|
||||
if eval(input_data["condition"]):
|
||||
return "result", True
|
||||
else:
|
||||
return "result", False
|
||||
|
||||
|
||||
class ForBlock(Block):
|
||||
id: ClassVar[str] = "db7d8f02-2f44-4c55-ab7a-eae0941f0c32" # type: ignore
|
||||
input_schema: ClassVar[BlockSchema] = BlockSchema(
|
||||
{ # type: ignore
|
||||
"data": "List[Any]"
|
||||
}
|
||||
)
|
||||
output_schema: ClassVar[BlockSchema] = BlockSchema(
|
||||
{ # type: ignore
|
||||
"result": "Any",
|
||||
}
|
||||
)
|
||||
|
||||
async def run(self, input_data: BlockData) -> tuple[str, Any]:
|
||||
# FIX: Current block does not support multiple returns...:W
|
||||
for element in input_data["data"]:
|
||||
return "result", element
|
||||
Reference in New Issue
Block a user