From fd01d22e87ade435b595e027b0e2bcbe8475b3d7 Mon Sep 17 00:00:00 2001 From: Kye Date: Mon, 11 Sep 2023 12:16:56 -0400 Subject: [PATCH] worker --- playground/workflow.py | 6 ++++++ swarms/agents/aot.py | 6 ++++-- swarms/artifacts/__init__.py | 0 swarms/artifacts/error_artifact.py | 16 ++++++++++++++ swarms/orchestrator/autoscaler.py | 6 +++--- swarms/structs/task.py | 34 ++++++++++++++++++++++++++++-- swarms/workflows/main.py | 16 ++++++++++---- 7 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 playground/workflow.py create mode 100644 swarms/artifacts/__init__.py create mode 100644 swarms/artifacts/error_artifact.py diff --git a/playground/workflow.py b/playground/workflow.py new file mode 100644 index 00000000..54fdb1f3 --- /dev/null +++ b/playground/workflow.py @@ -0,0 +1,6 @@ +from swarms.workflows.main import Workflow + +workflow = Workflow() + +workflow.add('Find 50 ceos in linkedin in agriculture ') + diff --git a/swarms/agents/aot.py b/swarms/agents/aot.py index 005303cb..57d6daab 100644 --- a/swarms/agents/aot.py +++ b/swarms/agents/aot.py @@ -203,7 +203,8 @@ class AoTAgent: pruning_threshold=0.5, backtracking_threshold=0.4, initial_prompt=None, - openai_api_key: str = None + openai_api_key: str = None, + model = None, ): self.num_thoughts = num_thoughts self.max_steps = max_steps @@ -213,7 +214,8 @@ class AoTAgent: self.initial_prompt = initial_prompt self.output = [] self.openai_api_key = openai_api_key - self.model = OpenAI(api_key=self.openai_api_key) + self.model = model + self.model = self.model or OpenAI(api_key=self.openai_api_key) def solve(self): try: diff --git a/swarms/artifacts/__init__.py b/swarms/artifacts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/swarms/artifacts/error_artifact.py b/swarms/artifacts/error_artifact.py new file mode 100644 index 00000000..95c66bf6 --- /dev/null +++ b/swarms/artifacts/error_artifact.py @@ -0,0 +1,16 @@ +from shapeless import shapeless + +@shapeless +class ErrorArtifact: + def __init__( + self, + value + ): + self.value = value + + def __add__(self, other): + return ErrorArtififact(self.value + other.value) + + def to_text(self) -> str: + return self.value + \ No newline at end of file diff --git a/swarms/orchestrator/autoscaler.py b/swarms/orchestrator/autoscaler.py index 7fe5e12c..dbf58b9a 100644 --- a/swarms/orchestrator/autoscaler.py +++ b/swarms/orchestrator/autoscaler.py @@ -1,7 +1,7 @@ import threading import queue from time import sleep -from swarms.workers.autobot import AutoBot +from swarms.workers.worker import Worker from swarms.utils.decorators import error_decorator, log_decorator, timing_decorator @@ -20,7 +20,7 @@ class AutoScaler: busy_threshold=0.7, agent=None, ): - self.agent = agent or AutoBot + self.agent = agent or Worker self.agents_pool = [self.agent() for _ in range(initial_agents)] self.task_queue = queue.Queue() self.scale_up_factor = scale_up_factor @@ -37,7 +37,7 @@ class AutoScaler: with self.lock: new_agents_counts = len(self.agents_pool) * self.scale_up_factor for _ in range(new_agents_counts): - self.agents_pool.append(AutoBot()) + self.agents_pool.append(Worker()) def scale_down(self): with self.lock: diff --git a/swarms/structs/task.py b/swarms/structs/task.py index d1b621f6..3ab23f19 100644 --- a/swarms/structs/task.py +++ b/swarms/structs/task.py @@ -1,14 +1,44 @@ +from abc import ABC from shapeless import shapeless @shapeless -class Task: +class BaseTask(ABC): def __init__( self, id, ): self.id = id - def forward(self): + def add(self): + pass + + def schedule(self, time): + pass + + def parents(self): + pass + + def children(self): + pass + + def preprocess(self): + pass + + def add_parent(self): + pass + + def is_pending(self): + pass + + def is_finished(self): + pass + + def is_executing(self): + pass + + def run(self): pass + def reset(self): + pass \ No newline at end of file diff --git a/swarms/workflows/main.py b/swarms/workflows/main.py index b55c45d1..8c722f5d 100644 --- a/swarms/workflows/main.py +++ b/swarms/workflows/main.py @@ -1,13 +1,21 @@ from __future__ import annotations + +import concurrent.futures as futures import logging import uuid from abc import ABC, abstractmethod +from graphlib import TopologicalSorter from logging import Logger -from typing import Optional, Union, TYPE_CHECKING, Callable, Type +from typing import Optional, Union + from rich.logging import RichHandler -import concurrent.futures as futures -from graphlib import TopologicalSorter +from shapeless import shapeless + +from swarms.artifacts.error_artifact import ErrorArtifact +from swarms.structs.task import BaseTask + +@shapeless class Workflow(ABC): def __init__( self, @@ -72,7 +80,7 @@ class Workflow(ABC): } @abstractmethod - def add_task(self, task: BaseTask) -> BaseTask: + def add(self, task: BaseTask) -> BaseTask: task.preprocess(self) self.tasks.append(task) return task