From 95999b8dd86e7ebe6effe71206731e3ad8fc9ccc Mon Sep 17 00:00:00 2001 From: Luan Citta Date: Wed, 5 Jun 2024 10:17:57 +0100 Subject: [PATCH] tweak inputs config, adding text view node (WIP) --- __init__.py | 2 ++ agent_node.py | 11 ++++++----- crew_node.py | 13 +++++++------ task_node.py | 4 ++-- textview_node.py | 20 ++++++++++++++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 textview_node.py diff --git a/__init__.py b/__init__.py index bb9c1c2..00bb088 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,4 @@ +from .textview_node import TextViewNode from .agent_node import AgentNode from .task_node import TaskNode from .crew_node import CrewNode @@ -10,6 +11,7 @@ NODE_CLASS_MAPPINGS = { "📎CrewAI Crew": CrewNode, "📎CrewAI Task List": TaskList, "📎CrewAI Agent List": AgentList, + # "📎CrewAI View Text": TextViewNode, (WIP) } WEB_DIRECTORY = "./js" diff --git a/agent_node.py b/agent_node.py index 60ece1d..ea86c82 100644 --- a/agent_node.py +++ b/agent_node.py @@ -8,21 +8,22 @@ class AgentNode: def INPUT_TYPES(s): return { "required": { - "role": ("STRING", {"default": ""}), - "goal": ("STRING", {"default": ""}), - "backstory": ("STRING", {"default": ""}), + "role": ("STRING", {"forceInput": True, "multiline": True, "default": ""}), + "goal": ("STRING", {"forceInput": True, "multiline": True, "default": ""}), + "backstory": ("STRING", {"forceInput": True, "multiline": True, "default": ""}), }, "optional": { "verbose": ("BOOL", {"default": False}), - "allow_delegation": ("BOOL", {"default": False}), + "allow_delegation": ("BOOL", { "default": True}), }, } + OUTPUT_NODE = True RETURN_TYPES = ("AGENT",) FUNCTION = "create_agent" CATEGORY = "📎CrewAi" - def create_agent(self, role, goal, backstory, verbose, allow_delegation): + def create_agent(self, role, goal, backstory, verbose=False, allow_delegation=True): agent = Agent( role=role, diff --git a/crew_node.py b/crew_node.py index 2ebe9a3..a989d67 100644 --- a/crew_node.py +++ b/crew_node.py @@ -12,8 +12,8 @@ class CrewNode(BaseNode): "tasks": ("TASK", {"default": []}), }, "optional": { - "topic": ("STRING", {"default": ""}), - "agents": ("AGENT", {"default": []}), + "topic": ("STRING", {"forceInput": False, "multiline": True,"default": ""}), + "agents": ("AGENT", {"forceInput": False, "default": []}), "process": ("STRING", {"default": "sequential", "choices": ["sequential", "hierarchical"]}), }, } @@ -21,14 +21,15 @@ class CrewNode(BaseNode): RETURN_TYPES = ("STRING",) FUNCTION = "create_crew" - def create_crew(self, agents, tasks, process, topic): - process_type = Process.sequential if process == "sequential" else Process.hierarchical - print("\n\n📎Crew AI - input", agents, tasks, process, topic) + def create_crew(self, tasks, process, topic="", agents=[],): + process_type = Process.sequential if process[0] == "sequential" else Process.hierarchical crew = Crew( agents=agents, tasks=tasks, - process=process_type + process=process_type, + topic=topic, ) + result = crew.kickoff(inputs={'topic': topic}) print("\n\n📎Crew AI - result", result) return (result,) diff --git a/task_node.py b/task_node.py index 423c249..22c3e81 100644 --- a/task_node.py +++ b/task_node.py @@ -9,10 +9,10 @@ class TaskNode(BaseNode): def INPUT_TYPES(cls): return { "required": { - "description": ("STRING", {"default": ""}), + "description": ("STRING", {"forceInput": True, "multiline": True, "default": ""}), }, "optional": { - "expected_output": ("STRING", {"default": ""}), + "expected_output": ("STRING", {"forceInput": False, "multiline": True, "default": ""}), "agent": ("AGENT",), } } diff --git a/textview_node.py b/textview_node.py new file mode 100644 index 0000000..dcd6564 --- /dev/null +++ b/textview_node.py @@ -0,0 +1,20 @@ +class TextViewNode: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "text": ("STRING", {"forceInput": True}), + } + } + + OUTPUT_NODE = True + RETURN_TYPES = () + FUNCTION = "display_text" + CATEGORY = "📎CrewAi" + + def display_text(self, text): + self["widgets_values"] = [text] + return {"ui": {"text": text}, "result": (text,)} \ No newline at end of file