The Swarms module provides a powerful framework for creating and managing swarms of autonomous agents to accomplish complex tasks. It consists of the `WorkerNode` and `BossNode` classes, along with the `LLM` utility class, which allow you to easily set up and run a swarm of agents to tackle any objective. The module is highly configurable and extensible, providing flexibility to accommodate various use cases.
## Usage example
```python
from swarms import Swarms
api_key = "your_openai_api_key"
# Initialize Swarms with your API key
swarm = Swarms(api_key=api_key)
# Define an objective
objective = "Please make a web GUI for using HTTP API server..."
# Run Swarms
result = swarm.run_swarms(objective)
print(result)
```
## Constructor
```python
def __init__(self, openai_api_key)
```
-`openai_api_key` (required): The API key for OpenAI's models.
## Methods
### run_swarms(objective)
Runs the swarm with the given objective by initializing the worker and boss nodes.
-`objective` (required): The objective or task to be accomplished by the swarm.
Returns the result of the swarm execution.
## Example Usage
```python
from swarms import Swarms
api_key = "your_openai_api_key"
# Initialize Swarms with your API key
swarm = Swarms(api_key=api_key)
# Define an objective
objective = "Please make a web GUI for using HTTP API server..."
The `WorkerNode` class represents an autonomous agent instance that functions as a worker to accomplish complex tasks. It has the ability to search the internet, process and generate images, text, audio, and more.
The `BossNode` class represents an agent responsible for creating and managing tasks for the worker agent(s). It interacts with the worker node(s) to delegate tasks and monitor their progress.
The `LLM` class is a utility class that provides an interface to different language models (LLMs) such as OpenAI's ChatGPT and Hugging Face models. It is used to initialize the language model for the worker and boss nodes.
For more advanced usage, you can customize the tools and parameters according to your specific requirements. The Swarms module provides flexibility and extensibility to accommodate various use cases.
For example, you can add your own custom tools by extending the `Tool` class and adding them to the worker node. You can also modify the prompt templates used by the boss node to customize the interaction between the boss and worker agents.
The Swarms module provides a powerful framework for creating and managing swarms of autonomous agents to accomplish complex tasks. With the `WorkerNode` and `BossNode` classes, along with the `LLM` utility class, you can easily set up and run a swarm of agents to tackle any objective. The module is highly configurable and extensible, allowing you to tailor it to your specific needs.
## LLM
### Purpose
The `LLM` class provides an interface to different language models (LLMs) such as OpenAI's ChatGPT and Hugging Face models. It allows you to initialize and run a language model with a given prompt and obtain the generated response.
### Systems Understanding
The `LLM` class takes an OpenAI API key or Hugging Face repository ID and API token as input. It uses these credentials to initialize the language model, either from OpenAI's models or from a specific Hugging Face repository. The language model can then be run with a prompt, and the generated response is returned.
-`openai_api_key` (optional): The API key for OpenAI's models.
-`hf_repo_id` (optional): The repository ID for the Hugging Face model.
-`hf_api_token` (optional): The API token for the Hugging Face model.
-`model_kwargs` (optional): Additional keyword arguments to pass to the language model.
### Methods
-`run(prompt: str) -> str`: Runs the language model with the given prompt and returns the generated response.
### Args
-`prompt` (str): The prompt to be passed to the language model.
### Returns
-`result` (str): The generated response from the language model.
## Conclusion
The `LLM` class provides a convenient way to initialize and run different language models using either OpenAI's API or Hugging Face models. By providing the necessary credentials and a prompt, you can obtain the generated response from the language model.