Skip to content

Commit

Permalink
[cleanup]
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Oct 12, 2024
1 parent 4cb0e3f commit b4766d7
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ nav:
- Philosophy: "swarms/concept/philosophy.md"
- Changelog:
- Swarms 5.6.8: "swarms/changelog/5_6_8.md"
- Swarms 5.8.1: "swarms/changelog/5_8_1.md"
- Swarm Models:
- Overview: "swarms/models/index.md"
- How to Create A Custom Language Model: "swarms/models/custom_model.md"
Expand Down
119 changes: 119 additions & 0 deletions docs/swarms/changelog/5_8_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Swarms 5.8.1 Feature Documentation

## 1. Enhanced Command Line Interface (CLI)

### 1.1 Integrated Onboarding Process

```bash
$ swarms onboarding
```

### 1.2 Run Agents Command

```bash
$ swarms run-agents --yaml-file agents.yaml
```

This command allows users to execute multiple agents defined in a YAML file. Here's the process:

1. The command reads the specified YAML file (`agents.yaml` in this case).
2. It parses the YAML content, extracting the configuration for each agent.
3. For each agent defined in the YAML:
- It creates an instance of the agent with the specified parameters.
- It sets up the agent's environment (model, temperature, max tokens, etc.).
- It assigns the given task to the agent.
- It executes the agent, respecting parameters like `max_loops`, `autosave`, and `verbose`.
4. The results from all agents are collected and presented to the user.

The YAML file structure allows users to define multiple agents with different configurations, making it easy to run complex, multi-agent tasks from the command line.

### 1.3 Generate Prompt Feature

```bash
$ swarms generate-prompt --prompt "Create a marketing strategy for a new product launch"
```

This feature leverages Swarms' language model to generate expanded or refined prompts:

1. The command takes the user's input prompt as a starting point.
2. It likely sends this prompt to a pre-configured language model (possibly GPT-4 or a similar model).
3. The model then generates an expanded or more detailed version of the prompt.
4. The generated prompt is returned to the user, possibly with options to further refine or save it.

This feature can help users create more effective prompts for their agents or other AI tasks.

## 2. New Prompt Management System

### 2.1 Prompt Class

The new `Prompt` class provides a robust system for managing and versioning prompts:

```python
from swarms import Prompt

marketing_prompt = Prompt(content="Initial marketing strategy draft", autosave=True)

print(marketing_prompt.get_prompt())
```

Key features of the `Prompt` class:

1. **Initialization**: The class is initialized with initial content and an `autosave` option.

2. **Editing**:
```python
marketing_prompt.edit_prompt("Updated marketing strategy with social media focus")
```
This method updates the prompt content and, if `autosave` is True, automatically saves the new version.

3. **Retrieval**:
```python
current_content = marketing_prompt.get_prompt()
```
This method returns the current content of the prompt.

4. **Version History**:
```python
print(f"Edit history: {marketing_prompt.edit_history}")
```
The class maintains a history of edits, allowing users to track changes over time.

5. **Rollback**:
```python
marketing_prompt.rollback(1)
```
This feature allows users to revert to a previous version of the prompt.

6. **Duplicate Prevention**:
The class includes logic to prevent duplicate edits, raising a `ValueError` if an attempt is made to save the same content twice in a row.

This system provides a powerful way to manage prompts, especially for complex projects where prompt engineering and iteration are crucial.

## 3. Upcoming Features Preview

### 3.1 Enhanced Agent Execution Capabilities

The preview code demonstrates planned enhancements for agent execution:

```python
from swarms import Agent, ExecutionEnvironment

my_agent = Agent(name="data_processor")

cpu_env = ExecutionEnvironment(type="cpu", cores=4)
my_agent.run(environment=cpu_env)

gpu_env = ExecutionEnvironment(type="gpu", device_id=0)
my_agent.run(environment=gpu_env)

fractional_env = ExecutionEnvironment(type="fractional", cpu_fraction=0.5, gpu_fraction=0.3)
my_agent.run(environment=fractional_env)
```

This upcoming feature will allow for more fine-grained control over the execution environment:

1. **CPU Execution**: Users can specify the number of CPU cores to use.
2. **GPU Execution**: Allows selection of a specific GPU device.
3. **Fractionalized Execution**: Enables partial allocation of CPU and GPU resources.

These features will provide users with greater flexibility in resource allocation, potentially improving performance and allowing for more efficient use of available hardware.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "swarms"
version = "5.7.8"
version = "5.8.1"
description = "Swarms - Pytorch"
license = "MIT"
authors = ["Kye Gomez <[email protected]>"]
Expand Down
35 changes: 31 additions & 4 deletions swarms/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
create_agents_from_yaml,
)
from swarms.agents.cli_prompt_generator_func import generate_prompt

import subprocess
console = Console()


Expand Down Expand Up @@ -44,6 +44,7 @@ def show_help():
[bold white]read-docs[/bold white] : Redirects you to swarms cloud documentation!
[bold white]run-agents[/bold white] : Run your Agents from your specified yaml file. Specify the yaml file with path the `--yaml-file` arg. Example: `--yaml-file agents.yaml`
[bold white]generate-prompt[/bold white] : Generate a prompt through automated prompt engineering. Requires an OPENAI Key in your `.env` Example: --prompt "Generate a prompt for an agent to analyze legal docs"
[bold white]auto-upgrade[/bold white] : Automatically upgrades Swarms to the latest version
For more details, visit: https://docs.swarms.world
"""
Expand Down Expand Up @@ -100,6 +101,29 @@ def check_login():
with open(cache_file, "w") as f:
f.write("logged_in")
console.print("[bold green]Login successful![/bold green]")

def check_and_upgrade_version():
console.print("[bold yellow]Checking for Swarms updates...[/bold yellow]")
try:
# Check for updates using pip
result = subprocess.run(
["pip", "list", "--outdated", "--format=freeze"],
capture_output=True,
text=True
)
outdated_packages = result.stdout.splitlines()

# Check if Swarms is outdated
for package in outdated_packages:
if package.startswith("swarms=="):
console.print("[bold magenta]New version available! Upgrading...[/bold magenta]")
subprocess.run(["pip", "install", "--upgrade", "swarms"], check=True)
console.print("[bold green]Swarms upgraded successfully![/bold green]")
return

console.print("[bold green]Swarms is up-to-date.[/bold green]")
except Exception as e:
console.print(f"[bold red]Error checking for updates: {e}[/bold red]")


# Main CLI handler
Expand All @@ -116,6 +140,7 @@ def main():
"check-login",
"run-agents",
"generate-prompt", # Added new command for generating prompts
"auto-upgrade", # Added new command for auto-upgrade
],
help="Command to run",
)
Expand Down Expand Up @@ -165,17 +190,19 @@ def main():
yaml_file=args.yaml_file, return_type="tasks"
)
elif args.command == "generate-prompt":
if args.prompt_task:
if args.prompt: # Corrected from args.prompt_task to args.prompt
generate_prompt(
num_loops=args.num_loops,
autosave=args.autosave,
save_to_yaml=args.save_to_yaml,
prompt=args.prompt_task,
prompt=args.prompt, # Corrected from args.prompt_task to args.prompt
)
else:
console.print(
"[bold red]Please specify a task for generating a prompt using '--prompt-task'.[/bold red]"
"[bold red]Please specify a task for generating a prompt using '--prompt'.[/bold red]"
)
elif args.command == "auto-upgrade":
check_and_upgrade_version()
else:
console.print(
"[bold red]Unknown command! Type 'help' for usage.[/bold red]"
Expand Down

0 comments on commit b4766d7

Please sign in to comment.