From 311d47ef4d3b7375d0813f313e29fea9963d350b Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 31 Dec 2023 14:24:07 -0500 Subject: [PATCH] [README] --- README.md | 44 ++++++++++++++++++++++++++++++++++++++---- concurrent_workflow.py | 9 +++++---- recursive_example.py | 26 +++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 recursive_example.py diff --git a/README.md b/README.md index be8a26f5..f0710fa3 100644 --- a/README.md +++ b/README.md @@ -128,24 +128,26 @@ for task in workflow.tasks: ### `ConcurrentWorkflow` +- Run all the tasks all at the same time ```python import os from dotenv import load_dotenv -from swarms.models import OpenAIChat, Task, ConcurrentWorkflow +from swarms import OpenAIChat, Task, ConcurrentWorkflow, Agent # Load environment variables from .env file load_dotenv() # Load environment variables llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")) +agent = Agent(llm=llm, max_loops=1) # 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") +task1 = Task(agent, "What's the weather in miami") +task2 = Task(agent, "What's the weather in new york") +task3 = Task(agent, "What's the weather in london") # Add tasks to the workflow workflow.add(task1) @@ -157,6 +159,40 @@ workflow.run() ``` +### `RecursiveWorkflow` +- Recursively iterate on a workflow until a specific token is detected. + +```python +import os +from dotenv import load_dotenv +from swarms import OpenAIChat, Task, RecursiveWorkflow, Agent + +# Load environment variables from .env file +load_dotenv() + +# Load environment variables +llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")) +agent = Agent(llm=llm, max_loops=1) + +# Create a workflow +workflow = RecursiveWorkflow(stop_token="") + +# Create tasks +task1 = Task(agent, "What's the weather in miami") +task2 = Task(agent, "What's the weather in new york") +task3 = Task(agent, "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() + + +``` + ### `ModelParallelizer` diff --git a/concurrent_workflow.py b/concurrent_workflow.py index 61c8fcf8..f152e4bb 100644 --- a/concurrent_workflow.py +++ b/concurrent_workflow.py @@ -1,20 +1,21 @@ import os from dotenv import load_dotenv -from swarms.models import OpenAIChat, Task, ConcurrentWorkflow +from swarms import OpenAIChat, Task, ConcurrentWorkflow, Agent # Load environment variables from .env file load_dotenv() # Load environment variables llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")) +agent = Agent(llm=llm, max_loops=1) # 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") +task1 = Task(agent, "What's the weather in miami") +task2 = Task(agent, "What's the weather in new york") +task3 = Task(agent, "What's the weather in london") # Add tasks to the workflow workflow.add(task1) diff --git a/recursive_example.py b/recursive_example.py new file mode 100644 index 00000000..9ec182e0 --- /dev/null +++ b/recursive_example.py @@ -0,0 +1,26 @@ +import os +from dotenv import load_dotenv +from swarms import OpenAIChat, Task, RecursiveWorkflow, Agent + +# Load environment variables from .env file +load_dotenv() + +# Load environment variables +llm = OpenAIChat(openai_api_key=os.getenv("OPENAI_API_KEY")) +agent = Agent(llm=llm, max_loops=1) + +# Create a workflow +workflow = RecursiveWorkflow(stop_token="") + +# Create tasks +task1 = Task(agent, "What's the weather in miami") +task2 = Task(agent, "What's the weather in new york") +task3 = Task(agent, "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()