AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(rnd): Fix text blocks, make outbound links on ValueBlock static (#7796)
Zamil Majdy1e92c284d984
diff --git a/rnd/autogpt_server/autogpt_server/blocks/text.py b/rnd/autogpt_server/autogpt_server/blocks/text.pyindex 22299e4c81..9aef36efd2 100644--- a/rnd/autogpt_server/autogpt_server/blocks/text.py+++ b/rnd/autogpt_server/autogpt_server/blocks/text.py@@ -115,8 +115,8 @@ class TextParserBlock(Block):class TextFormatterBlock(Block):class Input(BlockSchema):- texts: list[str] = Field(description="Texts (list) to format", default=[])- named_texts: dict[str, str] = Field(+ texts: list[Any] = Field(description="Texts (list) to format", default=[])+ named_texts: dict[str, Any] = Field(description="Texts (dict) to format", default={})format: str = Field(@@ -150,16 +150,24 @@ class TextFormatterBlock(Block):)def run(self, input_data: Input) -> BlockOutput:- yield "output", input_data.format.format(- texts=input_data.texts,- **input_data.named_texts,- )+ texts = [+ text if isinstance(text, str) else json.dumps(text)+ for text in input_data.texts+ ]+ named_texts = {+ key: value if isinstance(value, str) else json.dumps(value)+ for key, value in input_data.named_texts.items()+ }+ yield "output", input_data.format.format(texts=texts, **named_texts)class TextCombinerBlock(Block):class Input(BlockSchema):- input1: str = Field(description="First text input", default="a")- input2: str = Field(description="Second text input", default="b")+ input1: str = Field(description="First text input", default="")+ input2: str = Field(description="Second text input", default="")+ input3: str = Field(description="Second text input", default="")+ input4: str = Field(description="Second text input", default="")+ delimiter: str = Field(description="Delimiter to combine texts", default="")class Output(BlockSchema):output: str = Field(description="Combined text")@@ -182,5 +190,14 @@ class TextCombinerBlock(Block):)def run(self, input_data: Input) -> BlockOutput:- combined_text = (input_data.input1 or "") + (input_data.input2 or "")+ combined_text = input_data.delimiter.join(+ text+ for text in [+ input_data.input1,+ input_data.input2,+ input_data.input3,+ input_data.input4,+ ]+ if text+ )yield "output", combined_textdiff --git a/rnd/autogpt_server/autogpt_server/data/graph.py b/rnd/autogpt_server/autogpt_server/data/graph.pyindex bdcaf21e81..e1fd8eaa60 100644--- a/rnd/autogpt_server/autogpt_server/data/graph.py+++ b/rnd/autogpt_server/autogpt_server/data/graph.py@@ -7,7 +7,7 @@ import prisma.typesfrom prisma.models import AgentGraph, AgentNode, AgentNodeLinkfrom pydantic import PrivateAttr-from autogpt_server.blocks.basic import InputBlock, OutputBlock+from autogpt_server.blocks.basic import InputBlock, OutputBlock, ValueBlockfrom autogpt_server.data.block import BlockInput, get_blockfrom autogpt_server.data.db import BaseDbModel, transactionfrom autogpt_server.data.user import DEFAULT_USER_ID@@ -175,6 +175,11 @@ class Graph(GraphMeta):)node_map = {v.id: v for v in self.nodes}+ def is_value_block(nid: str) -> bool:+ bid = node_map[nid].block_id+ b = get_block(bid)+ return isinstance(b, ValueBlock)+def is_input_output_block(nid: str) -> bool:bid = node_map[nid].block_idb = get_block(bid)@@ -217,6 +222,9 @@ class Graph(GraphMeta):):raise ValueError(f"{suffix}, Connecting nodes from different subgraph.")+ if is_value_block(link.source_id):+ link.is_static = True # Each value block output should be static.+# TODO: Add type compatibility check here.@staticmethod