Skip to content

Commit

Permalink
[FEAT][CLI] [DOCS][CLI]
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 9, 2024
1 parent 93c6442 commit 087d45f
Show file tree
Hide file tree
Showing 11 changed files with 6,238 additions and 188 deletions.
1 change: 1 addition & 0 deletions cache.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logged_in
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ nav:
- Onboarding:
- Installation: "swarms/install/install.md"
- Quickstart: "swarms/install/quickstart.md"
- Swarms CLI: "swarms/cli/main.md"
- Agents:
# - Overview: "swarms/structs/index.md"
# - Build Custom Agents: "swarms/structs/diy_your_own_agent.md"
Expand Down
104 changes: 104 additions & 0 deletions docs/swarms/cli/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Swarms CLI Documentation

The Swarms Command Line Interface (CLI) allows you to easily manage and run your Swarms of agents from the command line. This page will guide you through the installation process and provide a breakdown of the available commands.

## Installation

You can install the `swarms` package using `pip` or `poetry`.

### Using pip

```bash
pip3 install -U swarms
```

### Using poetry

```bash
poetry add swarms
```

Once installed, you can run the Swarms CLI with the following command:

```bash
poetry run swarms help
```

## Swarms CLI - Help

When running `swarms help`, you'll see the following output:

```
_________
/ _____/_ _ _______ _______ _____ ______
\_____ \ \/ \/ /\__ \_ __ \/ \ / ___/
/ \ / / __ \| | \/ Y Y \___ \
/_______ / \/\_/ (____ /__| |__|_| /____ >
\/ \/ \/ \/
Swarms CLI - Help
Commands:
onboarding : Starts the onboarding process
help : Shows this help message
get-api-key : Retrieves your API key from the platform
check-login : Checks if you're logged in and starts the cache
read-docs : Redirects you to swarms cloud documentation!
run-agents : Run your Agents from your agents.yaml
For more details, visit: https://docs.swarms.world
```

### CLI Commands

Below is a detailed explanation of the available commands:

- **onboarding**
Starts the onboarding process to help you set up your environment and configure your agents.

Usage:
```bash
swarms onboarding
```

- **help**
Displays the help message, including a list of available commands.

Usage:
```bash
swarms help
```

- **get-api-key**
Retrieves your API key from the platform, allowing your agents to communicate with the Swarms platform.

Usage:
```bash
swarms get-api-key
```

- **check-login**
Verifies if you are logged into the platform and starts the cache for storing your login session.

Usage:
```bash
swarms check-login
```

- **read-docs**
Redirects you to the official Swarms documentation on the web for further reading.

Usage:
```bash
swarms read-docs
```

- **run-agents**
Executes your agents from the `agents.yaml` configuration file, which defines the structure and behavior of your agents.

Usage:
```bash
swarms run-agents
```
115 changes: 115 additions & 0 deletions examples/distributed/exec_on_cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import logging
import os

from clusterops import (
execute_with_cpu_cores,
list_available_cpus,
)
from swarm_models import OpenAIChat

from swarms import Agent

# Configure logging
logging.basicConfig(level=logging.INFO)

api_key = os.getenv("OPENAI_API_KEY")

# Create an instance of the OpenAIChat class
model = OpenAIChat(
openai_api_key=api_key,
model_name="gpt-4o-mini",
temperature=0.1,
max_tokens=2000,
)


# Function for the director agent
def director_task(task: str):
logging.info(f"Running Director agent for task: {task}")
director = Agent(
agent_name="Director",
system_prompt="Directs the tasks for the workers",
llm=model,
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="director.json",
)
return director.run(task)


# Function for worker 1
def worker1_task(task: str):
logging.info(f"Running Worker1 agent for task: {task}")
worker1 = Agent(
agent_name="Worker1",
system_prompt="Generates a transcript for a youtube video on what swarms are",
llm=model,
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="worker1.json",
)
return worker1.run(task)


# Function for worker 2
def worker2_task(task: str):
logging.info(f"Running Worker2 agent for task: {task}")
worker2 = Agent(
agent_name="Worker2",
system_prompt="Summarizes the transcript generated by Worker1",
llm=model,
max_loops=1,
dashboard=False,
streaming_on=True,
verbose=True,
stopping_token="<DONE>",
state_save_file_type="json",
saved_state_path="worker2.json",
)
return worker2.run(task)


# CPU Core Assignment Example
def assign_tasks_to_cpus():
# List available CPUs
cpus = list_available_cpus()
logging.info(f"Available CPUs: {cpus}")

# Example: Assign Director task to 1 CPU core
logging.info("Executing Director task using 1 CPU core")
execute_with_cpu_cores(
1, director_task, "Direct the creation of swarm video format"
)

# Example: Assign Worker1 task to 2 CPU cores
logging.info("Executing Worker1 task using 2 CPU cores")
execute_with_cpu_cores(
2,
worker1_task,
"Generate transcript for youtube video on swarms",
)

# Example: Assign Worker2 task to 2 CPU cores
logging.info("Executing Worker2 task using 2 CPU cores")
execute_with_cpu_cores(
2,
worker2_task,
"Summarize the transcript generated by Worker1",
)

print("finished")


if __name__ == "__main__":
logging.info(
"Starting the CPU-based task assignment for agents..."
)
assign_tasks_to_cpus()
Loading

0 comments on commit 087d45f

Please sign in to comment.