[REFACTOR][SequentialWorkflow] [README] [v]

pull/343/head
Kye 1 year ago
parent e4ee2cfab9
commit fb560bc1ce

@ -123,7 +123,37 @@ workflow.run()
# Output the results
for task in workflow.tasks:
print(f"Task: {task.description}, Result: {task.result}")
```
### `ConcurrentWorkflow`
```python
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat, Task, ConcurrentWorkflow
# Load environment variables from .env file
load_dotenv()
# Load environment variables
llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY"))
# Create a workflow
workflow = ConcurrentWorkflow(max_workers=5)
# Create tasks
task1 = Task(llm, "What's the weather in miami")
task2 = Task(llm, "What's the weather in new york")
task3 = Task(llm, "What's the weather in london")
# Add tasks to the workflow
workflow.add(task1)
workflow.add(task2)
workflow.add(task3)
# Run the workflow
workflow.run()
```

@ -0,0 +1,25 @@
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat, Task, ConcurrentWorkflow
# Load environment variables from .env file
load_dotenv()
# Load environment variables
llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY"))
# Create a workflow
workflow = ConcurrentWorkflow(max_workers=5)
# Create tasks
task1 = Task(llm, "What's the weather in miami")
task2 = Task(llm, "What's the weather in new york")
task3 = Task(llm, "What's the weather in london")
# Add tasks to the workflow
workflow.add(task1)
workflow.add(task2)
workflow.add(task3)
# Run the workflow
workflow.run()

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "swarms"
version = "3.1.3"
version = "3.1.5"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"]

@ -43,13 +43,22 @@ class ConcurrentWorkflow(BaseStruct):
return_results: bool = False
use_processes: bool = False
def add(self, task: Task):
def add(self, task: Task, tasks: List[Task] = None):
"""Adds a task to the workflow.
Args:
task (Task): _description_
tasks (List[Task]): _description_
"""
self.tasks.append(task)
try:
if tasks:
for task in tasks:
self.tasks.append(task)
else:
self.tasks.append(task)
except Exception as error:
print(f"[ERROR][ConcurrentWorkflow] {error}")
raise error
def run(self):
"""

@ -34,9 +34,24 @@ class RecursiveWorkflow(BaseStruct):
self.stop_token is not None
), "stop_token cannot be None"
def add(self, task: Task):
assert task is not None, "task cannot be None"
return self.tasks.appennd(task)
def add(self, task: Task, tasks: List[Task] = None):
"""Adds a task to the workflow.
Args:
task (Task): _description_
tasks (List[Task]): _description_
"""
try:
if tasks:
for task in tasks:
self.tasks.append(task)
else:
self.tasks.append(task)
except Exception as error:
print(f"[ERROR][ConcurrentWorkflow] {error}")
raise error
def run(self):
"""

@ -53,6 +53,7 @@ class SequentialWorkflow:
self,
agent: Union[Callable, Agent],
task: Optional[str] = None,
tasks: Optional[List[str]] = None,
*args,
**kwargs,
) -> None:

Loading…
Cancel
Save