diff --git a/__init__.py b/__init__.py index 3483a41..37dcabd 100644 --- a/__init__.py +++ b/__init__.py @@ -22,6 +22,7 @@ from .nodes.combine.gtUIModuleList import gtUIModuleList from .nodes.combine.MergeDictionary import MergeDictionary from .nodes.combine.MergeTexts import MergeTexts from .nodes.combine.RulesList import RulesList +from .nodes.combine.StringList import StringList from .nodes.combine.ToolList import ToolList # CONFIG @@ -281,6 +282,7 @@ from .nodes.tasks.gtUIInpaintingImageGenerationTask import ( gtUIInpaintingImageGenerationTask, ) from .nodes.tasks.gtUIParallelImageQueryTask import gtUIParallelImageQueryTask +from .nodes.tasks.gtUIParallelPromptTask import gtUIParallelPromptTask from .nodes.tasks.gtUIPromptImageGenerationTask import gtUIPromptImageGenerationTask from .nodes.tasks.gtUIPromptImageVariationTask import gtUIPromptImageVariationTask @@ -342,6 +344,7 @@ NODE_CLASS_MAPPINGS = { "Griptape Create: Agent from Config": gtUICreateAgentFromConfig, "Griptape Run: Agent": RunAgent, "Griptape Run: Task": gtUITask, + "Griptape Run: Parallel Prompt Task": gtUIParallelPromptTask, # "Griptape Run: Prompt Task": gtUIPromptTask, # "Griptape Run: Tool Task": gtUIToolTask, # "Griptape Run: Toolkit Task": gtUIToolkitTask, @@ -492,6 +495,7 @@ NODE_CLASS_MAPPINGS = { "Griptape Combine: Merge Dictionary": MergeDictionary, "Griptape Combine: Merge Texts": MergeTexts, "Griptape Combine: Merge Inputs": gtUIMergeInputs, + "Griptape Combine: String List": StringList, "Griptape Load: Text": gtUILoadText, "Griptape Save: Text": gtUISaveText, "Griptape Run: Text Extraction": gtUIExtractionTask, diff --git a/js/CombineNodes.js b/js/CombineNodes.js index 89f3edb..589fa2c 100644 --- a/js/CombineNodes.js +++ b/js/CombineNodes.js @@ -7,6 +7,7 @@ export function setupCombineNodes(nodeType, nodeData, app) { nodeData.name === "Griptape Combine: RAG Module List" || nodeData.name === "Griptape Util: Switch Node" || nodeData.name === "Griptape Combine: Merge Dictionary" || + nodeData.name === "Griptape Combine: String List" || nodeData.name === "Griptape Create: Pipeline" ) { setupCombineNode(nodeType, nodeData, app); diff --git a/js/DisplayNodes.js b/js/DisplayNodes.js index e6bb9bf..e722bb6 100644 --- a/js/DisplayNodes.js +++ b/js/DisplayNodes.js @@ -39,6 +39,7 @@ function setupArtifactDisplayNode(nodeType, nodeData, app) { function setupTextDisplayNode(nodeType, nodeData, app) { nodeType.prototype.onExecuted = function (message) { let stringWidget = this.widgets.find((w) => w.name === "STRING"); + if (stringWidget && message.hasOwnProperty("INPUT")) { let new_val = Array.isArray(message["INPUT"]) ? message["INPUT"].join("") diff --git a/nodes/combine/StringList.py b/nodes/combine/StringList.py new file mode 100644 index 0000000..9bbab3b --- /dev/null +++ b/nodes/combine/StringList.py @@ -0,0 +1,40 @@ +class StringList: + """ + Griptape Lists of Strings + """ + + DESCRIPTION = "Creates a list of strings" + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "optional": { + "input_1": ( + "STRING", + { + "tooltip": "A string to add to a list. Connect an input to dynamically create more strings.", + "forceInput": True, + }, + ), + } + } + + RETURN_TYPES = ("STRINGLIST",) + RETURN_NAMES = ("STRINGLIST",) + FUNCTION = "create" + # OUTPUT_IS_LIST = (True,) + CATEGORY = "Griptape/Text" + + def create(self, **kwargs): + # Clear the rule_list + string_list = [] + + strings = [value for value in kwargs.values()] + if len(strings) > 0: + for string in strings: + string_list.append(string) + # rule_list = [rule[0] for rule in [kwargs.values()] if rule is not None] + return (string_list,) diff --git a/nodes/tasks/gtUIParallelPromptTask.py b/nodes/tasks/gtUIParallelPromptTask.py new file mode 100644 index 0000000..639b8bb --- /dev/null +++ b/nodes/tasks/gtUIParallelPromptTask.py @@ -0,0 +1,52 @@ +from griptape.artifacts import TextArtifact +from griptape.drivers import LocalStructureRunDriver +from griptape.structures import Workflow +from griptape.tasks import StructureRunTask + +from ..agent.gtComfyAgent import gtComfyAgent as Agent +from .gtUIBaseTask import gtUIBaseTask + + +class gtUIParallelPromptTask(gtUIBaseTask): + DESCRIPTION = "Create a parallel prompt task for an agent." + CATEGORY = "Griptape/Agent" + + @classmethod + def INPUT_TYPES(cls): + inputs = super().INPUT_TYPES() + + # Update optional inputs to include 'agent' and adjust others as necessary + inputs["optional"].update( + { + "agent": ("AGENT",), + "string_list": ("STRING_LIST",), + } + ) + return inputs + + def run(self, **kwargs): + string_list = kwargs.get("string_list") + agent = kwargs.get("agent", None) + + # if the tool is provided, keep going + if not agent: + agent = Agent() + driver = LocalStructureRunDriver(create_structure=lambda: agent) + + workflow = Workflow() + + for prompt in string_list: + task = StructureRunTask(prompt, structure_run_driver=driver) + workflow.add_task(task) + result = workflow.run() + outputs = "\n\n".join([task.output.value for task in result.output_tasks]) + return (outputs, agent) + output = result.output_task.output.value + if isinstance(output, str): + return (output, agent) + elif isinstance(output, list): + output_list = [item.value for item in output] + output_str = "\n\n".join(output_list) + return (output_str, agent) + elif isinstance(output, TextArtifact): + return (output.value, agent)