Merge branch 'master' into tool-tests

pull/298/head
Zack 1 year ago
commit c4c7f0d847

@ -1,13 +1,14 @@
---
# These are supported funding model platforms # These are supported funding model platforms
github: [kyegomez] github: [kyegomez]
patreon: # Replace with a single Patreon username # patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username # open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username # ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel # tidelift: # Replace with a single Tidelift platform-name/package-name
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry # community_bridge: # Replace with a single Community Bridge project-name
liberapay: # Replace with a single Liberapay username # liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username # issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username # otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry # lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name
custom: #Nothing # custom: #Nothing

@ -1,3 +1,4 @@
---
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
version: 2 version: 2
@ -11,4 +12,3 @@ updates:
directory: "/" directory: "/"
schedule: schedule:
interval: "weekly" interval: "weekly"

@ -1,12 +1,14 @@
---
# this is a config file for the github action labeler # this is a config file for the github action labeler
# Add 'label1' to any changes within 'example' folder or any subfolders # Add 'label1' to any changes within 'example' folder or any subfolders
example_change: example_change:
- example/** - example/**
# Add 'label2' to any file changes within 'example2' folder # Add 'label2' to any file changes within 'example2' folder
example2_change: example2/* example2_change: example2/*
# Add label3 to any change to .txt files within the entire repository. Quotation marks are required for the leading asterisk # Add label3 to any change to .txt files within the entire repository.
# Quotation marks are required for the leading asterisk
text_files: text_files:
- '**/*.txt' - '**/*.txt'

@ -22,10 +22,10 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Install poetry - name: Install poetry
run: pipx install poetry==$POETRY_VERSION run: pipx install poetry==$POETRY_VERSION
- name: Set up Python 3.10 - name: Set up Python 3.9
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
python-version: "3.10" python-version: "3.9"
cache: "poetry" cache: "poetry"
- name: Build project for distribution - name: Build project for distribution
run: poetry build run: poetry build
@ -46,8 +46,12 @@ jobs:
env: env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: | run: |
<<<<<<< HEAD
<<<<<<< HEAD <<<<<<< HEAD
poetry publish poetry publish
======= =======
poetry publish poetry publish
>>>>>>> model-flow >>>>>>> model-flow
=======
poetry publish
>>>>>>> master

@ -1,17 +1,18 @@
---
name: Docker Image CI name: Docker Image CI
on: on: # yamllint disable-line rule:truthy
push: push:
branches: [ "master" ] branches: ["master"]
pull_request: pull_request:
branches: [ "master" ] branches: ["master"]
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Build Docker image
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Build the Docker image - name: Build the Docker image

@ -65,7 +65,7 @@ jobs:
# https://github.com/docker/metadata-action # https://github.com/docker/metadata-action
- name: Extract Docker metadata - name: Extract Docker metadata
id: meta id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4 # v5.3.0
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
@ -73,7 +73,7 @@ jobs:
# https://github.com/docker/build-push-action # https://github.com/docker/build-push-action
- name: Build and push Docker image - name: Build and push Docker image
id: build-and-push id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with: with:
context: . context: .
push: ${{ github.event_name != 'pull_request' }} push: ${{ github.event_name != 'pull_request' }}

@ -1,4 +1,4 @@
name: Docs WorkFlow name: Docs WorkAgent
on: on:
push: push:

@ -1,19 +1,29 @@
---
# This is a basic workflow to help you get started with Actions # This is a basic workflow to help you get started with Actions
name: Lint name: Lint
on: [push, pull_request] on: [push, pull_request] # yamllint disable-line rule:truthy
jobs: jobs:
yaml-lint:
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v4
- name: yaml Lint
uses: ibiqlik/action-yamllint@v3
flake8-lint: flake8-lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Lint name: flake8 Lint
steps: steps:
- name: Check out source repository - name: Check out source repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Python environment - name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: flake8 Lint
uses: py-actions/flake8@v2 uses: py-actions/flake8@v2
ruff-lint:
runs-on: ubuntu-latest
name: ruff Lint
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

@ -1,3 +1,4 @@
---
name: Pull Request Checks name: Pull Request Checks
on: on:
@ -19,9 +20,11 @@ jobs:
python-version: 3.x python-version: 3.x
- name: Install dependencies - name: Install dependencies
run: pip install -r requirements.txt run: |
pip install -r requirements.txt
pip install pytest
- name: Run tests and checks - name: Run tests and checks
run: | run: |
find tests/ -name "*.py" | xargs pytest pytest
pylint swarms pylint swarms

@ -9,9 +9,9 @@ jobs:
matrix: matrix:
python-version: ["3.8", "3.9", "3.10"] python-version: ["3.8", "3.9", "3.10"]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4 uses: actions/setup-python@v3
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
- name: Install dependencies - name: Install dependencies

@ -18,9 +18,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v3
- name: Set up Python 3.10 - name: Set up Python 3.10
uses: actions/setup-python@v4 uses: actions/setup-python@v3
with: with:
python-version: "3.10" python-version: "3.10"
- name: Install dependencies - name: Install dependencies

@ -0,0 +1,34 @@
name: Python Package using Conda
on: [push]
jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda env update --file environment.yml --name base
- name: Lint with flake8
run: |
conda install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
conda install pytest
pytest

@ -0,0 +1,41 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade swarms
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest

@ -1,7 +1,7 @@
---
name: Upload Python Package name: Upload Python Package
on: on: # yamllint disable-line rule:truthy
release: release:
types: [published] types: [published]
@ -26,7 +26,7 @@ jobs:
- name: Build package - name: Build package
run: python -m build run: python -m build
- name: Publish package - name: Publish package
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
with: with:
user: __token__ user: __token__
password: ${{ secrets.PYPI_API_TOKEN }} password: ${{ secrets.PYPI_API_TOKEN }}

@ -1,3 +1,4 @@
---
name: test name: test
on: on:
@ -9,7 +10,67 @@ on:
env: env:
POETRY_VERSION: "1.4.2" POETRY_VERSION: "1.4.2"
jobs: test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
test_type:
- "core"
- "extended"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: "snok/install-poetry@v1"
with:
python-version: ${{ matrix.python-version }}
poetry-version: "1.4.2"
cache-key: ${{ matrix.test_type }}
install-command: |
if [ "${{ matrix.test_type }}" == "core" ]; then
echo "Running core tests, installing dependencies with poetry..."
poetry install
else
echo "Running extended tests, installing dependencies with poetry..."
poetry install -E extended_testing
fi
- name: Run ${{matrix.test_type}} tests
run: |
if [ "${{ matrix.test_type }}" == "core" ]; then
make test
else
make extended_tests
fi
shell: bash
name: Python ${{ matrix.python-version }} ${{ matrix.test_type }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: "1.4.2"
cache-key: ${{ matrix.test_type }}
install-command: |
if [ "${{ matrix.test_type }}" == "core" ]; then
echo "Running core tests, installing dependencies with poetry..."
poetry install
else
echo "Running extended tests, installing dependencies with poetry..."
poetry install -E extended_testing
fi
- name: Run ${{matrix.test_type}} tests
run: |
if [ "${{ matrix.test_type }}" == "core" ]; then
make test
else
make extended_tests
fi
shell: bash
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:

@ -19,7 +19,9 @@ jobs:
python-version: 3.x python-version: 3.x
- name: Install dependencies - name: Install dependencies
run: pip install -r requirements.txt run: |
pip install -r requirements.txt
pip install pytest
- name: Run unit tests - name: Run unit tests
run: find tests/ -name "*.py" | xargs pytest run: pytest

@ -18,16 +18,18 @@ jobs:
- name: Setup Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
python-version: '3.10' python-version: '3.9'
- name: Install dependencies - name: Install dependencies
run: pip install -r requirements.txt run: |
pip install -r requirements.txt
pip install pytest
- name: Run Python unit tests - name: Run Python unit tests
run: python3 -m unittest tests/ run: pytest
- name: Verify that the Docker image for the action builds - name: Verify that the Docker image for the action builds
run: docker build . --file Dockerfile run: docker build . --file Dockerfile
- name: Verify integration test results - name: Verify integration test results
run: find tests/ -name "*.py" | xargs pytest run: pytest

@ -1,4 +1,4 @@
name: Welcome WorkFlow name: Welcome WorkAgent
on: on:
issues: issues:
@ -12,7 +12,7 @@ jobs:
permissions: write-all permissions: write-all
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/first-interaction@v1.2.0 - uses: actions/first-interaction@v1.3.0
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: "Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap." issue-message: "Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap."

@ -7,7 +7,11 @@ repos:
rev: 'v0.0.255' rev: 'v0.0.255'
hooks: hooks:
- id: ruff - id: ruff
<<<<<<< HEAD
args: [--fix] args: [--fix]
=======
args: [----unsafe-fixes]
>>>>>>> master
- repo: https://github.com/nbQA-dev/nbQA - repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.3 rev: 1.6.3
hooks: hooks:

@ -1,8 +1,305 @@
title: Swarms ![Swarming banner icon](images/swarmslogobanner.png)
emoji: 💻
colorFrom: indigo <div align="center">
colorTo: blue
sdk: gradio Swarms is a modular framework that enables reliable and useful multi-agent collaboration at scale to automate real-world tasks.
sdk_version: 4.8.0
app_file: app.py
pinned: false [![GitHub issues](https://img.shields.io/github/issues/kyegomez/swarms)](https://github.com/kyegomez/swarms/issues) [![GitHub forks](https://img.shields.io/github/forks/kyegomez/swarms)](https://github.com/kyegomez/swarms/network) [![GitHub stars](https://img.shields.io/github/stars/kyegomez/swarms)](https://github.com/kyegomez/swarms/stargazers) [![GitHub license](https://img.shields.io/github/license/kyegomez/swarms)](https://github.com/kyegomez/swarms/blob/main/LICENSE)[![GitHub star chart](https://img.shields.io/github/stars/kyegomez/swarms?style=social)](https://star-history.com/#kyegomez/swarms)[![Dependency Status](https://img.shields.io/librariesio/github/kyegomez/swarms)](https://libraries.io/github/kyegomez/swarms) [![Downloads](https://static.pepy.tech/badge/swarms/month)](https://pepy.tech/project/swarms)
[![Join the Agora discord](https://img.shields.io/discord/1110910277110743103?label=Discord&logo=discord&logoColor=white&style=plastic&color=d7b023)![Share on Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Share%20%40kyegomez/swarms)](https://twitter.com/intent/tweet?text=Check%20out%20this%20amazing%20AI%20project:%20&url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms) [![Share on Facebook](https://img.shields.io/badge/Share-%20facebook-blue)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms) [![Share on LinkedIn](https://img.shields.io/badge/Share-%20linkedin-blue)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms&title=&summary=&source=)
[![Share on Reddit](https://img.shields.io/badge/-Share%20on%20Reddit-orange)](https://www.reddit.com/submit?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms&title=Swarms%20-%20the%20future%20of%20AI) [![Share on Hacker News](https://img.shields.io/badge/-Share%20on%20Hacker%20News-orange)](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms&t=Swarms%20-%20the%20future%20of%20AI) [![Share on Pinterest](https://img.shields.io/badge/-Share%20on%20Pinterest-red)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms&media=https%3A%2F%2Fexample.com%2Fimage.jpg&description=Swarms%20-%20the%20future%20of%20AI) [![Share on WhatsApp](https://img.shields.io/badge/-Share%20on%20WhatsApp-green)](https://api.whatsapp.com/send?text=Check%20out%20Swarms%20-%20the%20future%20of%20AI%20%23swarms%20%23AI%0A%0Ahttps%3A%2F%2Fgithub.com%2Fkyegomez%2Fswarms)
</div>
----
## Installation
`pip3 install --upgrade swarms`
---
## Usage
Run example in Collab: <a target="_blank" href="https://colab.research.google.com/github/kyegomez/swarms/blob/master/playground/swarms_example.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
</a>
### `Agent` Example
- Reliable Structure that provides LLMS autonomy
- Extremely Customizeable with stopping conditions, interactivity, dynamical temperature, loop intervals, and so much more
- Enterprise Grade + Production Grade: `Agent` is designed and optimized for automating real-world tasks at scale!
```python
import os
from dotenv import load_dotenv
# Import the OpenAIChat model and the Agent struct
from swarms.models import OpenAIChat
from swarms.structs import Agent
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
model_name="gpt-4",
openai_api_key=api_key,
max_tokens=4000
)
## Initialize the workflow
agent = Agent(llm=llm, max_loops=1, autosave=True, dashboard=True)
# Run the workflow on a task
out = agent.run("Generate a 10,000 word blog on health and wellness.")
print(out)
```
------
### `SequentialWorkflow`
- A Sequential swarm of autonomous agents where each agent's outputs are fed into the next agent
- Save and Restore Workflow states!
- Integrate Agent's with various LLMs and Multi-Modality Models
```python
import os
from swarms.models import OpenAIChat
from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow
from dotenv import load_dotenv
load_dotenv()
# Load the environment variables
api_key = os.getenv("OPENAI_API_KEY")
# Initialize the language agent
llm = OpenAIChat(
temperature=0.5,
model_name="gpt-4",
openai_api_key=api_key,
max_tokens=4000
)
# Initialize the agent with the language agent
agent1 = Agent(llm=llm, max_loops=1)
# Create another agent for a different task
agent2 = Agent(llm=llm, max_loops=1)
# Create another agent for a different task
agent3 = Agent(llm=llm, max_loops=1)
# Create the workflow
workflow = SequentialWorkflow(max_loops=1)
# Add tasks to the workflow
workflow.add(
agent1, "Generate a 10,000 word blog on health and wellness.",
)
# Suppose the next task takes the output of the first task as input
workflow.add(
agent2, "Summarize the generated blog",
)
# Run the workflow
workflow.run()
# Output the results
for task in workflow.tasks:
print(f"Task: {task.description}, Result: {task.result}")
```
## `Multi Modal Autonomous Agents`
- Run the agent with multiple modalities useful for various real-world tasks in manufacturing, logistics, and health.
```python
# Description: This is an example of how to use the Agent class to run a multi-modal workflow
import os
from dotenv import load_dotenv
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.structs import Agent
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = GPT4VisionAPI(
openai_api_key=api_key,
max_tokens=500,
)
# Initialize the task
task = (
"Analyze this image of an assembly line and identify any issues such as"
" misaligned parts, defects, or deviations from the standard assembly"
" process. IF there is anything unsafe in the image, explain why it is"
" unsafe and how it could be improved."
)
img = "assembly_line.jpg"
## Initialize the workflow
agent = Agent(
llm=llm,
max_loops="auto",
autosave=True,
dashboard=True,
multi_modal=True
)
# Run the workflow on a task
out = agent.run(task=task, img=img)
print(out)
```
### `OmniModalAgent`
- An agent that can understand any modality and conditionally generate any modality.
```python
from swarms.agents.omni_modal_agent import OmniModalAgent, OpenAIChat
from swarms.models import OpenAIChat
from dotenv import load_dotenv
import os
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
model_name="gpt-4",
openai_api_key=api_key,
)
agent = OmniModalAgent(llm)
response = agent.run("Generate a video of a swarm of fish and then make an image out of the video")
print(response)
```
---
# Features 🤖
The Swarms framework is designed with a strong emphasis on reliability, performance, and production-grade readiness.
Below are the key features that make Swarms an ideal choice for enterprise-level AI deployments.
## 🚀 Production-Grade Readiness
- **Scalable Architecture**: Built to scale effortlessly with your growing business needs.
- **Enterprise-Level Security**: Incorporates top-notch security features to safeguard your data and operations.
- **Containerization and Microservices**: Easily deployable in containerized environments, supporting microservices architecture.
## ⚙️ Reliability and Robustness
- **Fault Tolerance**: Designed to handle failures gracefully, ensuring uninterrupted operations.
- **Consistent Performance**: Maintains high performance even under heavy loads or complex computational demands.
- **Automated Backup and Recovery**: Features automatic backup and recovery processes, reducing the risk of data loss.
## 💡 Advanced AI Capabilities
The Swarms framework is equipped with a suite of advanced AI capabilities designed to cater to a wide range of applications and scenarios, ensuring versatility and cutting-edge performance.
### Multi-Modal Autonomous Agents
- **Versatile Model Support**: Seamlessly works with various AI models, including NLP, computer vision, and more, for comprehensive multi-modal capabilities.
- **Context-Aware Processing**: Employs context-aware processing techniques to ensure relevant and accurate responses from agents.
### Function Calling Models for API Execution
- **Automated API Interactions**: Function calling models that can autonomously execute API calls, enabling seamless integration with external services and data sources.
- **Dynamic Response Handling**: Capable of processing and adapting to responses from APIs for real-time decision making.
### Varied Architectures of Swarms
- **Flexible Configuration**: Supports multiple swarm architectures, from centralized to decentralized, for diverse application needs.
- **Customizable Agent Roles**: Allows customization of agent roles and behaviors within the swarm to optimize performance and efficiency.
### Generative Models
- **Advanced Generative Capabilities**: Incorporates state-of-the-art generative models to create content, simulate scenarios, or predict outcomes.
- **Creative Problem Solving**: Utilizes generative AI for innovative problem-solving approaches and idea generation.
### Enhanced Decision-Making
- **AI-Powered Decision Algorithms**: Employs advanced algorithms for swift and effective decision-making in complex scenarios.
- **Risk Assessment and Management**: Capable of assessing risks and managing uncertain situations with AI-driven insights.
### Real-Time Adaptation and Learning
- **Continuous Learning**: Agents can continuously learn and adapt from new data, improving their performance and accuracy over time.
- **Environment Adaptability**: Designed to adapt to different operational environments, enhancing robustness and reliability.
## 🔄 Efficient Workflow Automation
- **Streamlined Task Management**: Simplifies complex tasks with automated workflows, reducing manual intervention.
- **Customizable Workflows**: Offers customizable workflow options to fit specific business needs and requirements.
- **Real-Time Analytics and Reporting**: Provides real-time insights into agent performance and system health.
## 🌐 Wide-Ranging Integration
- **API-First Design**: Easily integrates with existing systems and third-party applications via robust APIs.
- **Cloud Compatibility**: Fully compatible with major cloud platforms for flexible deployment options.
- **Continuous Integration/Continuous Deployment (CI/CD)**: Supports CI/CD practices for seamless updates and deployment.
## 📊 Performance Optimization
- **Resource Management**: Efficiently manages computational resources for optimal performance.
- **Load Balancing**: Automatically balances workloads to maintain system stability and responsiveness.
- **Performance Monitoring Tools**: Includes comprehensive monitoring tools for tracking and optimizing performance.
## 🛡️ Security and Compliance
- **Data Encryption**: Implements end-to-end encryption for data at rest and in transit.
- **Compliance Standards Adherence**: Adheres to major compliance standards ensuring legal and ethical usage.
- **Regular Security Updates**: Regular updates to address emerging security threats and vulnerabilities.
## 💬 Community and Support
- **Extensive Documentation**: Detailed documentation for easy implementation and troubleshooting.
- **Active Developer Community**: A vibrant community for sharing ideas, solutions, and best practices.
- **Professional Support**: Access to professional support for enterprise-level assistance and guidance.
Swarms framework is not just a tool but a robust, scalable, and secure partner in your AI journey, ready to tackle the challenges of modern AI applications in a business environment.
## Documentation
- For documentation, go here, [swarms.apac.ai](https://swarms.apac.ai)
## 🫶 Contributions:
Swarms is an open-source project, and contributions are welcome. If you want to contribute, you can create new features, fix bugs, or improve the infrastructure. Please refer to the [CONTRIBUTING.md](https://github.com/kyegomez/swarms/blob/master/CONTRIBUTING.md) and our [contributing board](https://github.com/users/kyegomez/projects/1) file in the repository for more information on how to contribute.
To see how to contribute, visit [Contribution guidelines](https://github.com/kyegomez/swarms/blob/master/CONTRIBUTING.md)
<a href="https://github.com/kyegomez/swarms/graphs/contributors">
<img src="https://contrib.rocks/image?repo=kyegomez/swarms" />
</a>
## Community
- [Join the Swarms community on Discord!](https://discord.gg/AJazBmhKnr)
- Join our Swarms Community Gathering every Thursday at 1pm NYC Time to unlock the potential of autonomous agents in automating your daily tasks [Sign up here](https://lu.ma/5p2jnc2v)
## Discovery Call
Book a discovery call with the Swarms team to learn how to optimize and scale your swarm! [Click here to book a time that works for you!](https://calendly.com/swarm-corp/30min?month=2023-11)
# License
MIT

@ -14,7 +14,7 @@ A compilation of projects, papers, blogs in autonomous agents.
### Developer tools ### Developer tools
- [2023/8/10] [ModelScope-Agent](https://github.com/modelscope/modelscope-agent) - An Agent Framework Connecting Models in ModelScope with the World - [2023/8/10] [ModelScope-Agent](https://github.com/modelscope/modelscope-agent) - An Agent Framework Connecting Models in ModelScope with the World
- [2023/05/25] [Gorilla](https://github.com/ShishirPatil/gorilla) - An API store for LLMs - [2023/05/25] [Gorilla](https://github.com/ShishirPatil/gorilla) - An API store for LLMs
- [2023/03/31] [swarms.tools](https://github.com/OpenBMB/swarms.tools) - Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins - [2023/03/31] [BMTools](https://github.com/OpenBMB/BMTools) - Tool Learning for Big Models, Open-Source Solutions of ChatGPT-Plugins
- [2023/03/09] [LMQL](https://github.com/eth-sri/lmql) - A query language for programming (large) language models. - [2023/03/09] [LMQL](https://github.com/eth-sri/lmql) - A query language for programming (large) language models.
- [2022/10/25] [Langchain](https://github.com/hwchase17/langchain) - ⚡ Building applications with LLMs through composability ⚡ - [2022/10/25] [Langchain](https://github.com/hwchase17/langchain) - ⚡ Building applications with LLMs through composability ⚡

@ -0,0 +1,195 @@
# The Swarm Cloud
### Business Model Plan for Autonomous Agent Swarm Service
#### Service Description
- **Overview:** A platform allowing users to deploy swarms of autonomous agents in production-grade environments.
- **Target Users:** Industries requiring automation, monitoring, data collection, and more, such as manufacturing, logistics, agriculture, and surveillance.
#### Operational Strategy
- **Infrastructure:** Robust cloud infrastructure to support agent deployment and data processing.
- **Support and Maintenance:** Continuous support for software updates, troubleshooting, and user assistance.
- **Technology Development:** Ongoing R&D for enhancing agent capabilities and efficiency.
#### Financial Projections
- **Revenue Streams:** Mainly from per agent usage fees and hosting services.
- **Cost Structure:** Includes development, maintenance, infrastructure, marketing, and administrative costs.
- **Break-even Analysis:** Estimation based on projected user adoption rates and cost per agent.
# Revnue Streams
```markdown
| Pricing Structure | Description | Details |
| ------------------------- | ----------- | ------- |
| Usage-Based Per Agent | Fees are charged based on the number of agents deployed and their usage duration. | - Ideal for clients needing a few agents for specific tasks. <br> - More agents or longer usage results in higher fees. |
| Swarm Coverage Pricing | Pricing based on the coverage area or scope of the swarm deployment. | - Suitable for tasks requiring large area coverage. <br> - Price scales with the size or complexity of the area covered. |
| Performance-Based Pricing | Fees are tied to the performance or outcomes achieved by the agents. | - Clients pay for the effectiveness or results achieved by the agents. <br> - Higher fees for more complex or high-value tasks. |
```
1. **Pay-Per-Mission Pricing:** Clients are charged for each specific task or mission completed by the agents.
- **Per Agent Usage Fee:** Charged based on the number of agents and the duration of their deployment.
- **Hosting Fees:** Based on the data usage and processing requirements of the agents.
- **Volume Discounts:** Available for large-scale deployments.
2. **Time-Based Subscription:** A subscription model where clients pay a recurring fee for continuous access to a set number of agents.
3. **Dynamic Pricing:** Prices fluctuate based on demand, time of day, or specific conditions.
4. **Tiered Usage Levels:** Different pricing tiers based on the number of agents used or the complexity of tasks.
5. **Freemium Model:** Basic services are free, but premium features or additional agents are paid.
6. **Outcome-Based Pricing:** Charges are based on the success or quality of the outcomes achieved by the agents.
7. **Feature-Based Pricing:** Different prices for different feature sets or capabilities of the agents.
8. **Volume Discounts:** Reduced per-agent price for bulk deployments or long-term contracts.
9. **Peak Time Premiums:** Higher charges during peak usage times or for emergency deployment.
10. **Bundled Services:** Combining agent services with other products or services for a comprehensive package deal.
11. **Custom Solution Pricing:** Tailor-made pricing for unique or specialized requirements.
12. **Data Analysis Fee:** Charging for the data processing and analytics provided by the agents.
13. **Performance Tiers:** Different pricing for varying levels of agent efficiency or performance.
14. **License Model:** Clients purchase a license to deploy and use a certain number of agents.
15. **Cost-Plus Pricing:** Pricing based on the cost of deployment plus a markup.
16. **Service Level Agreement (SLA) Pricing:** Higher prices for higher levels of service guarantees.
17. **Pay-Per-Save Model:** Charging based on the cost savings or value created by the agents for the client.
18. **Revenue Sharing:** Sharing a percentage of the revenue generated through the use of agents.
19. **Geographic Pricing:** Different pricing for different regions or markets.
20. **User-Based Pricing:** Charging based on the number of users accessing and controlling the agents.
21. **Energy Usage Pricing:** Prices based on the amount of energy consumed by the agents during operation.
22. **Event-Driven Pricing:** Charging for specific events or triggers during the agent's operation.
23. **Seasonal Pricing:** Adjusting prices based on seasonal demand or usage patterns.
24. **Partnership Models:** Collaborating with other businesses and sharing revenue from combined services.
25. **Customizable Packages:** Allowing clients to build their own package of services and capabilities, priced accordingly.
These diverse pricing strategies can be combined or tailored to fit different business models, client needs, and market dynamics. They also provide various methods of value extraction, ensuring flexibility and scalability in revenue generation.
# ICP Analysis
### Ideal Customer Profile (ICP) Map
#### 1. Manufacturing and Industrial Automation
- **Characteristics:** Large-scale manufacturers, high automation needs, emphasis on efficiency and precision.
- **Needs:** Process automation, quality control, predictive maintenance.
#### 2. Agriculture and Farming
- **Characteristics:** Large agricultural enterprises, focus on modern farming techniques.
- **Needs:** Crop monitoring, automated harvesting, pest control.
#### 3. Logistics and Supply Chain
- **Characteristics:** Companies with extensive logistics operations, warehousing, and supply chain management.
- **Needs:** Inventory tracking, automated warehousing, delivery optimization.
#### 4. Energy and Utilities
- **Characteristics:** Energy providers, utility companies, renewable energy farms.
- **Needs:** Infrastructure monitoring, predictive maintenance, efficiency optimization.
#### 5. Environmental Monitoring and Conservation
- **Characteristics:** Organizations focused on environmental protection, research institutions.
- **Needs:** Wildlife tracking, pollution monitoring, ecological research.
#### 6. Smart Cities and Urban Planning
- **Characteristics:** Municipal governments, urban development agencies.
- **Needs:** Traffic management, infrastructure monitoring, public safety.
#### 7. Defense and Security
- **Characteristics:** Defense contractors, security firms, government agencies.
- **Needs:** Surveillance, reconnaissance, threat assessment.
#### 8. Healthcare and Medical Facilities
- **Characteristics:** Large hospitals, medical research centers.
- **Needs:** Facility management, patient monitoring, medical logistics.
#### 9. Entertainment and Event Management
- **Characteristics:** Large-scale event organizers, theme parks.
- **Needs:** Crowd management, entertainment automation, safety monitoring.
#### 10. Construction and Infrastructure
- **Characteristics:** Major construction firms, infrastructure developers.
- **Needs:** Site monitoring, material tracking, safety compliance.
### Potential Market Size Table (in Markdown)
```markdown
| Customer Segment | Estimated Market Size (USD) | Notes |
| ---------------------------- | --------------------------- | ----- |
| Manufacturing and Industrial | $100 Billion | High automation and efficiency needs drive demand. |
| Agriculture and Farming | $75 Billion | Growing adoption of smart farming technologies. |
| Logistics and Supply Chain | $90 Billion | Increasing need for automation in warehousing and delivery. |
| Energy and Utilities | $60 Billion | Focus on infrastructure monitoring and maintenance. |
| Environmental Monitoring | $30 Billion | Rising interest in climate and ecological data collection. |
| Smart Cities and Urban Planning | $50 Billion | Growing investment in smart city technologies. |
| Defense and Security | $120 Billion | High demand for surveillance and reconnaissance tech. |
| Healthcare and Medical | $85 Billion | Need for efficient hospital management and patient care. |
| Entertainment and Event Management | $40 Billion | Innovative uses in crowd control and event safety. |
| Construction and Infrastructure | $70 Billion | Use in monitoring and managing large construction projects. |
```
#### Risk Analysis
- **Market Risks:** Adaptation rate and competition.
- **Operational Risks:** Reliability and scalability of infrastructure.
- **Regulatory Risks:** Compliance with data security and privacy laws.
# Business Model
---
### The Swarm Cloud: Business Model
#### Unlocking the Potential of Autonomous Agent Technology
**1. Our Vision:**
- Revolutionize industries through scalable, intelligent swarms of autonomous agents.
- Enable real-time data collection, analysis, and automated task execution.
**2. Service Offering:**
- **The Swarm Cloud Platform:** Deploy and manage swarms of autonomous agents in production-grade environments.
- **Applications:** Versatile across industries from smart agriculture to urban planning, logistics, and beyond.
**3. Key Features:**
- **High Scalability:** Tailored solutions from small-scale deployments to large industrial operations.
- **Real-Time Analytics:** Instant data processing and actionable insights.
- **User-Friendly Interface:** Simplified control and monitoring of agent swarms.
- **Robust Security:** Ensuring data integrity and operational safety.
**4. Revenue Streams:**
- **Usage-Based Pricing:** Charges based on the number of agents and operation duration.
- **Subscription Models:** Recurring revenue through scalable packages.
- **Custom Solutions:** Tailored pricing for bespoke deployments.
**5. Market Opportunity:**
- **Expansive Market:** Addressing needs in a \$500 billion global market spanning multiple sectors.
- **Competitive Edge:** Advanced technology offering superior efficiency and adaptability.
**6. Growth Strategy:**
- **R&D Investment:** Continuous enhancement of agent capabilities and platform features.
- **Strategic Partnerships:** Collaborations with industry leaders for market penetration.
- **Marketing and Sales:** Focused approach on high-potential sectors with tailored marketing strategies.
**7. Why Invest in The Swarm Cloud?**
- **Pioneering Technology:** At the forefront of autonomous agent systems.
- **Scalable Business Model:** Designed for rapid expansion and adaptation to diverse market needs.
- **Strong Market Demand:** Positioned to capitalize on the growing trend of automation and AI.
"Empowering industries with intelligent, autonomous solutions The Swarm Cloud is set to redefine efficiency and innovation."
#### Conclusion
The business model aims to provide a scalable, efficient, and cost-effective solution for industries looking to leverage the power of autonomous agent technology. With a structured pricing plan and a focus on continuous development and support, the service is positioned to meet diverse industry needs.

@ -1,7 +1,7 @@
# Reliable Enterprise-Grade Autonomous Agents in Less Than 5 lines of Code # Reliable Enterprise-Grade Autonomous Agents in Less Than 5 lines of Code
======================================================================== ========================================================================
Welcome to the walkthrough guide for beginners on using the "Flow" feature within the Swarms framework. This guide is designed to help you understand and utilize the capabilities of the Flow class for seamless and reliable interactions with autonomous agents. Welcome to the walkthrough guide for beginners on using the "Agent" feature within the Swarms framework. This guide is designed to help you understand and utilize the capabilities of the Agent class for seamless and reliable interactions with autonomous agents.
## Official Swarms Links ## Official Swarms Links
===================== =====================
@ -21,27 +21,27 @@ Now let's begin...
## [Table of Contents](https://github.com/kyegomez/swarms) ## [Table of Contents](https://github.com/kyegomez/swarms)
=========================================================================================================== ===========================================================================================================
1. Introduction to Swarms Flow Module 1. Introduction to Swarms Agent Module
- 1.1 What is Swarms? - 1.1 What is Swarms?
- 1.2 Understanding the Flow Module - 1.2 Understanding the Agent Module
2. Setting Up Your Development Environment 2. Setting Up Your Development Environment
- 2.1 Installing Required Dependencies - 2.1 Installing Required Dependencies
- 2.2 API Key Setup - 2.2 API Key Setup
- 2.3 Creating Your First Flow - 2.3 Creating Your First Agent
3. Creating Your First Flow 3. Creating Your First Agent
- 3.1 Importing Necessary Libraries - 3.1 Importing Necessary Libraries
- 3.2 Defining Constants - 3.2 Defining Constants
- 3.3 Initializing the Flow Object - 3.3 Initializing the Agent Object
- 3.4 Initializing the Language Model - 3.4 Initializing the Language Model
- 3.5 Running Your Flow - 3.5 Running Your Agent
- 3.6 Understanding Flow Options - 3.6 Understanding Agent Options
4. Advanced Flow Concepts 4. Advanced Agent Concepts
- 4.1 Custom Stopping Conditions - 4.1 Custom Stopping Conditions
- 4.2 Dynamic Temperature Handling - 4.2 Dynamic Temperature Handling
@ -50,10 +50,10 @@ Now let's begin...
- 4.5 Response Filtering - 4.5 Response Filtering
- 4.6 Interactive Mode - 4.6 Interactive Mode
5. Saving and Loading Flows 5. Saving and Loading Agents
- 5.1 Saving Flow State - 5.1 Saving Agent State
- 5.2 Loading a Saved Flow - 5.2 Loading a Saved Agent
6. Troubleshooting and Tips 6. Troubleshooting and Tips
@ -62,7 +62,7 @@ Now let's begin...
7. Conclusion 7. Conclusion
## [1. Introduction to Swarms Flow Module](https://github.com/kyegomez/swarms) ## [1. Introduction to Swarms Agent Module](https://github.com/kyegomez/swarms)
=================================================================================================================================================== ===================================================================================================================================================
### [1.1 What is Swarms?](https://github.com/kyegomez/swarms) ### [1.1 What is Swarms?](https://github.com/kyegomez/swarms)
@ -70,23 +70,23 @@ Now let's begin...
Swarms is a powerful framework designed to provide tools and capabilities for working with language models and automating various tasks. It allows developers to interact with language models seamlessly. Swarms is a powerful framework designed to provide tools and capabilities for working with language models and automating various tasks. It allows developers to interact with language models seamlessly.
## 1.2 Understanding the Flow Feature ## 1.2 Understanding the Agent Feature
================================== ==================================
### [What is the Flow Feature?](https://github.com/kyegomez/swarms) ### [What is the Agent Feature?](https://github.com/kyegomez/swarms)
-------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------
The Flow feature is a powerful component of the Swarms framework that allows developers to create a sequential, conversational interaction with AI language models. It enables developers to build multi-step conversations, generate long-form content, and perform complex tasks using AI. The Flow class provides autonomy to language models, enabling them to generate responses in a structured manner. The Agent feature is a powerful component of the Swarms framework that allows developers to create a sequential, conversational interaction with AI language models. It enables developers to build multi-step conversations, generate long-form content, and perform complex tasks using AI. The Agent class provides autonomy to language models, enabling them to generate responses in a structured manner.
### [Key Concepts](https://github.com/kyegomez/swarms) ### [Key Concepts](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------
Before diving into the practical aspects, let's clarify some key concepts related to the Flow feature: Before diving into the practical aspects, let's clarify some key concepts related to the Agent feature:
- Flow: A Flow is an instance of the Flow class that represents an ongoing interaction with an AI language model. It consists of a series of steps and responses. - Agent: A Agent is an instance of the Agent class that represents an ongoing interaction with an AI language model. It consists of a series of steps and responses.
- Stopping Condition: A stopping condition is a criterion that, when met, allows the Flow to stop generating responses. This can be user-defined and can depend on the content of the responses. - Stopping Condition: A stopping condition is a criterion that, when met, allows the Agent to stop generating responses. This can be user-defined and can depend on the content of the responses.
- Loop Interval: The loop interval specifies the time delay between consecutive interactions with the AI model. - Loop Interval: The loop interval specifies the time delay between consecutive interactions with the AI model.
- Retry Mechanism: In case of errors or failures during AI model interactions, the Flow can be configured to make multiple retry attempts with a specified interval. - Retry Mechanism: In case of errors or failures during AI model interactions, the Agent can be configured to make multiple retry attempts with a specified interval.
- Interactive Mode: Interactive mode allows developers to have a back-and-forth conversation with the AI model, making it suitable for real-time interactions. - Interactive Mode: Interactive mode allows developers to have a back-and-forth conversation with the AI model, making it suitable for real-time interactions.
## [2. Setting Up Your Development Environment](https://github.com/kyegomez/swarms) ## [2. Setting Up Your Development Environment](https://github.com/kyegomez/swarms)
@ -95,38 +95,38 @@ Before diving into the practical aspects, let's clarify some key concepts relate
### [2.1 Installing Required Dependencies](https://github.com/kyegomez/swarms) ### [2.1 Installing Required Dependencies](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------
Before you can start using the Swarms Flow module, you need to set up your development environment. First, you'll need to install the necessary dependencies, including Swarms itself. Before you can start using the Swarms Agent module, you need to set up your development environment. First, you'll need to install the necessary dependencies, including Swarms itself.
# Install Swarms and required libraries # Install Swarms and required libraries
`pip3 install --upgrade swarms` `pip3 install --upgrade swarms`
## [2. Creating Your First Flow](https://github.com/kyegomez/swarms) ## [2. Creating Your First Agent](https://github.com/kyegomez/swarms)
----------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------
Now, let's create your first Flow. A Flow represents a chain-like structure that allows you to engage in multi-step conversations with language models. The Flow structure is what gives an LLM autonomy. It's the Mitochondria of an autonomous agent. Now, let's create your first Agent. A Agent represents a chain-like structure that allows you to engage in multi-step conversations with language models. The Agent structure is what gives an LLM autonomy. It's the Mitochondria of an autonomous agent.
# Import necessary modules # Import necessary modules
```python ```python
from swarms.models import OpenAIChat # Zephr, Mistral from swarms.models import OpenAIChat # Zephr, Mistral
from swarms.structs import Flow from swarms.structs import Agent
api_key = ""# Initialize the language model (LLM) api_key = ""# Initialize the language model (LLM)
llm = OpenAIChat(openai_api_key=api_key, temperature=0.5, max_tokens=3000)# Initialize the Flow object llm = OpenAIChat(openai_api_key=api_key, temperature=0.5, max_tokens=3000)# Initialize the Agent object
flow = Flow(llm=llm, max_loops=5)# Run the flow agent = Agent(llm=llm, max_loops=5)# Run the agent
out = flow.run("Create an financial analysis on the following metrics") out = agent.run("Create an financial analysis on the following metrics")
print(out) print(out)
``` ```
### [3. Initializing the Flow Object](https://github.com/kyegomez/swarms) ### [3. Initializing the Agent Object](https://github.com/kyegomez/swarms)
---------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------
Create a Flow object that will be the backbone of your conversational flow. Create a Agent object that will be the backbone of your conversational agent.
```python ```python
# Initialize the Flow object # Initialize the Agent object
flow = Flow( agent = Agent(
llm=llm, llm=llm,
max_loops=5, max_loops=5,
stopping_condition=None, # You can define custom stopping conditions stopping_condition=None, # You can define custom stopping conditions
@ -142,7 +142,7 @@ flow = Flow(
### [3.2 Initializing the Language Model](https://github.com/kyegomez/swarms) ### [3.2 Initializing the Language Model](https://github.com/kyegomez/swarms)
---------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------
Initialize the language model (LLM) that your Flow will interact with. In this example, we're using OpenAI's GPT-3 as the LLM. Initialize the language model (LLM) that your Agent will interact with. In this example, we're using OpenAI's GPT-3 as the LLM.
- You can also use `Mistral` or `Zephr` or any of other models! - You can also use `Mistral` or `Zephr` or any of other models!
@ -155,16 +155,16 @@ llm = OpenAIChat(
) )
``` ```
### [3.3 Running Your Flow](https://github.com/kyegomez/swarms) ### [3.3 Running Your Agent](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------
Now, you're ready to run your Flow and start interacting with the language model. Now, you're ready to run your Agent and start interacting with the language model.
If you are using a multi modality model, you can pass in the image path as another parameter If you are using a multi modality model, you can pass in the image path as another parameter
``` ```
# Run your Flow # Run your Agent
out = flow.run( out = agent.run(
"Generate a 10,000 word blog on health and wellness.", "Generate a 10,000 word blog on health and wellness.",
# "img.jpg" , Image path for multi-modal models # "img.jpg" , Image path for multi-modal models
) )
@ -174,14 +174,14 @@ print(out)
This code will initiate a conversation with the language model, and you'll receive responses accordingly. This code will initiate a conversation with the language model, and you'll receive responses accordingly.
## [4. Advanced Flow Concepts](https://github.com/kyegomez/swarms) ## [4. Advanced Agent Concepts](https://github.com/kyegomez/swarms)
=========================================================================================================================== ===========================================================================================================================
In this section, we'll explore advanced concepts that can enhance your experience with the Swarms Flow module. In this section, we'll explore advanced concepts that can enhance your experience with the Swarms Agent module.
### [4.1 Custom Stopping Conditions](https://github.com/kyegomez/swarms) ### [4.1 Custom Stopping Conditions](https://github.com/kyegomez/swarms)
You can define custom stopping conditions for your Flow. For example, you might want the Flow to stop when a specific word is mentioned in the response. You can define custom stopping conditions for your Agent. For example, you might want the Agent to stop when a specific word is mentioned in the response.
# Custom stopping condition example # Custom stopping condition example
```python ```python
@ -189,16 +189,16 @@ def stop_when_repeats(response: str) -> bool:
return "Stop" in response.lower() return "Stop" in response.lower()
``` ```
# Set the stopping condition in your Flow # Set the stopping condition in your Agent
```flow.stopping_condition = stop_when_repeats``` ```agent.stopping_condition = stop_when_repeats```
### [4.2 Dynamic Temperature Handling](https://github.com/kyegomez/swarms) ### [4.2 Dynamic Temperature Handling](https://github.com/kyegomez/swarms)
---------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------
Dynamic temperature handling allows you to adjust the temperature attribute of the language model during the conversation. Dynamic temperature handling allows you to adjust the temperature attribute of the language model during the conversation.
# Enable dynamic temperature handling in your Flow # Enable dynamic temperature handling in your Agent
`flow.dynamic_temperature = True` `agent.dynamic_temperature = True`
This feature randomly changes the temperature attribute for each loop, providing a variety of responses. This feature randomly changes the temperature attribute for each loop, providing a variety of responses.
@ -208,7 +208,7 @@ This feature randomly changes the temperature attribute for each loop, providing
You can provide feedback on responses generated by the language model using the `provide_feedback` method. You can provide feedback on responses generated by the language model using the `provide_feedback` method.
- Provide feedback on a response - Provide feedback on a response
`flow.provide_feedback("The response was helpful.")` `agent.provide_feedback("The response was helpful.")`
This feedback can be valuable for improving the quality of responses. This feedback can be valuable for improving the quality of responses.
@ -219,8 +219,8 @@ In case of errors or issues during conversation, you can implement a retry mecha
# Set the number of retry attempts and interval # Set the number of retry attempts and interval
```python ```python
flow.retry_attempts = 3 agent.retry_attempts = 3
flow.retry_interval = 1 # in seconds agent.retry_interval = 1 # in seconds
``` ```
### [4.5 Response Filtering](https://github.com/kyegomez/swarms) ### [4.5 Response Filtering](https://github.com/kyegomez/swarms)
-------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------
@ -229,38 +229,38 @@ You can add response filters to filter out certain words or phrases from the res
# Add a response filter # Add a response filter
```python ```python
flow.add_response_filter("inappropriate_word") agent.add_response_filter("inappropriate_word")
``` ```
This helps in controlling the content generated by the language model. This helps in controlling the content generated by the language model.
### [4.6 Interactive Mode](https://github.com/kyegomez/swarms) ### [4.6 Interactive Mode](https://github.com/kyegomez/swarms)
---------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------
Interactive mode allows you to have a back-and-forth conversation with the language model. When enabled, the Flow will prompt for user input after each response. Interactive mode allows you to have a back-and-forth conversation with the language model. When enabled, the Agent will prompt for user input after each response.
# Enable interactive mode # Enable interactive mode
`flow.interactive = True` `agent.interactive = True`
This is useful for real-time conversations with the model. This is useful for real-time conversations with the model.
## [5. Saving and Loading Flows](https://github.com/kyegomez/swarms) ## [5. Saving and Loading Agents](https://github.com/kyegomez/swarms)
=============================================================================================================================== ===============================================================================================================================
### [5.1 Saving Flow State](https://github.com/kyegomez/swarms) ### [5.1 Saving Agent State](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------
You can save the state of your Flow, including the conversation history, for future use. You can save the state of your Agent, including the conversation history, for future use.
# Save the Flow state to a file # Save the Agent state to a file
`flow.save("path/to/flow_state.json")`` `agent.save("path/to/flow_state.json")``
### [5.2 Loading a Saved Flow](https://github.com/kyegomez/swarms) ### [5.2 Loading a Saved Agent](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------
To continue a conversation or reuse a Flow, you can load a previously saved state. To continue a conversation or reuse a Agent, you can load a previously saved state.
# Load a saved Flow state # Load a saved Agent state
`flow.load("path/to/flow_state.json")`` `agent.load("path/to/flow_state.json")``
## [6. Troubleshooting and Tips](https://github.com/kyegomez/swarms) ## [6. Troubleshooting and Tips](https://github.com/kyegomez/swarms)
=============================================================================================================================== ===============================================================================================================================
@ -271,17 +271,17 @@ To continue a conversation or reuse a Flow, you can load a previously saved stat
You can analyze the feedback provided during the conversation to identify issues and improve the quality of interactions. You can analyze the feedback provided during the conversation to identify issues and improve the quality of interactions.
# Analyze feedback # Analyze feedback
`flow.analyze_feedback()` `agent.analyze_feedback()`
### [6.2 Troubleshooting Common Issues](https://github.com/kyegomez/swarms) ### [6.2 Troubleshooting Common Issues](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------
If you encounter issues during conversation, refer to the troubleshooting section for guidance on resolving common problems. If you encounter issues during conversation, refer to the troubleshooting section for guidance on resolving common problems.
# [7. Conclusion: Empowering Developers with Swarms Framework and Flow Structure for Automation](https://github.com/kyegomez/swarms) # [7. Conclusion: Empowering Developers with Swarms Framework and Agent Structure for Automation](https://github.com/kyegomez/swarms)
================================================================================================================================================================================================================================================================ ================================================================================================================================================================================================================================================================
In a world where digital tasks continue to multiply and diversify, the need for automation has never been more critical. Developers find themselves at the forefront of this automation revolution, tasked with creating reliable solutions that can seamlessly handle an array of digital tasks. Enter the Swarms framework and the Flow structure, a dynamic duo that empowers developers to build autonomous agents capable of efficiently and effectively automating a wide range of digital tasks. In a world where digital tasks continue to multiply and diversify, the need for automation has never been more critical. Developers find themselves at the forefront of this automation revolution, tasked with creating reliable solutions that can seamlessly handle an array of digital tasks. Enter the Swarms framework and the Agent structure, a dynamic duo that empowers developers to build autonomous agents capable of efficiently and effectively automating a wide range of digital tasks.
[The Automation Imperative](https://github.com/kyegomez/swarms) [The Automation Imperative](https://github.com/kyegomez/swarms)
--------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------
@ -300,7 +300,7 @@ One of the standout features of Swarms is its seamless integration with state-of
By leveraging Swarms, developers can effortlessly incorporate these language models into their applications and workflows. For instance, they can build chatbots that provide intelligent responses to customer inquiries or generate lengthy documents with minimal manual intervention. This not only saves time but also enhances overall productivity. By leveraging Swarms, developers can effortlessly incorporate these language models into their applications and workflows. For instance, they can build chatbots that provide intelligent responses to customer inquiries or generate lengthy documents with minimal manual intervention. This not only saves time but also enhances overall productivity.
[2. Multi-Step Conversational Flows](https://github.com/kyegomez/swarms) [2. Multi-Step Conversational Agents](https://github.com/kyegomez/swarms)
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------
Swarms excels in orchestrating multi-step conversational flows. Developers can define intricate sequences of interactions, where the system generates responses, and users provide input at various stages. This functionality is a game-changer for building chatbots, virtual assistants, or any application requiring dynamic and context-aware conversations. Swarms excels in orchestrating multi-step conversational flows. Developers can define intricate sequences of interactions, where the system generates responses, and users provide input at various stages. This functionality is a game-changer for building chatbots, virtual assistants, or any application requiring dynamic and context-aware conversations.
@ -324,58 +324,58 @@ Swarms encourages the collection of feedback on generated responses. Developers
Error handling is a critical aspect of any automation framework. Swarms simplifies this process by offering a retry mechanism. In case of errors or issues during conversations, developers can configure the framework to attempt generating responses again, ensuring robust and resilient automation. Error handling is a critical aspect of any automation framework. Swarms simplifies this process by offering a retry mechanism. In case of errors or issues during conversations, developers can configure the framework to attempt generating responses again, ensuring robust and resilient automation.
[6. Saving and Loading Flows](https://github.com/kyegomez/swarms) [6. Saving and Loading Agents](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------
Developers can save the state of their conversational flows, allowing for seamless continuity and reusability. This feature is particularly beneficial when working on long-term projects or scenarios where conversations need to be resumed from a specific point. Developers can save the state of their conversational flows, allowing for seamless continuity and reusability. This feature is particularly beneficial when working on long-term projects or scenarios where conversations need to be resumed from a specific point.
[Unleashing the Potential of Automation with Swarms and Flow](https://github.com/kyegomez/swarms) [Unleashing the Potential of Automation with Swarms and Agent](https://github.com/kyegomez/swarms)
=============================================================================================================================================================================================== ===============================================================================================================================================================================================
The combined power of the Swarms framework and the Flow structure creates a synergy that empowers developers to automate a multitude of digital tasks. These tools provide versatility, customization, and extensibility, making them ideal for a wide range of applications. Let's explore some of the remarkable ways in which developers can leverage Swarms and Flow for automation: The combined power of the Swarms framework and the Agent structure creates a synergy that empowers developers to automate a multitude of digital tasks. These tools provide versatility, customization, and extensibility, making them ideal for a wide range of applications. Let's explore some of the remarkable ways in which developers can leverage Swarms and Agent for automation:
[1. Customer Support and Service Automation](https://github.com/kyegomez/swarms) [1. Customer Support and Service Automation](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------
Swarms and Flow enable the creation of AI-powered customer support chatbots that excel at handling common inquiries, troubleshooting issues, and escalating complex problems to human agents when necessary. This level of automation not only reduces response times but also enhances the overall customer experience. Swarms and Agent enable the creation of AI-powered customer support chatbots that excel at handling common inquiries, troubleshooting issues, and escalating complex problems to human agents when necessary. This level of automation not only reduces response times but also enhances the overall customer experience.
[2. Content Generation and Curation](https://github.com/kyegomez/swarms) [2. Content Generation and Curation](https://github.com/kyegomez/swarms)
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------
Developers can harness the power of Swarms and Flow to automate content generation tasks, such as writing articles, reports, or product descriptions. By providing an initial prompt, the system can generate high-quality content that adheres to specific guidelines and styles. Developers can harness the power of Swarms and Agent to automate content generation tasks, such as writing articles, reports, or product descriptions. By providing an initial prompt, the system can generate high-quality content that adheres to specific guidelines and styles.
Furthermore, these tools can automate content curation by summarizing lengthy articles, extracting key insights from research papers, and even translating content into multiple languages. Furthermore, these tools can automate content curation by summarizing lengthy articles, extracting key insights from research papers, and even translating content into multiple languages.
[3. Data Analysis and Reporting](https://github.com/kyegomez/swarms) [3. Data Analysis and Reporting](https://github.com/kyegomez/swarms)
------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------
Automation in data analysis and reporting is fundamental for data-driven decision-making. Swarms and Flow simplify these processes by enabling developers to create flows that interact with databases, query data, and generate reports based on user-defined criteria. This empowers businesses to derive insights quickly and make informed decisions. Automation in data analysis and reporting is fundamental for data-driven decision-making. Swarms and Agent simplify these processes by enabling developers to create flows that interact with databases, query data, and generate reports based on user-defined criteria. This empowers businesses to derive insights quickly and make informed decisions.
[4. Programming and Code Generation](https://github.com/kyegomez/swarms) [4. Programming and Code Generation](https://github.com/kyegomez/swarms)
--------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------
Swarms and Flow streamline code generation and programming tasks. Developers can create flows to assist in writing code snippets, auto-completing code, or providing solutions to common programming challenges. This accelerates software development and reduces the likelihood of coding errors. Swarms and Agent streamline code generation and programming tasks. Developers can create flows to assist in writing code snippets, auto-completing code, or providing solutions to common programming challenges. This accelerates software development and reduces the likelihood of coding errors.
[5. Language Translation and Localization](https://github.com/kyegomez/swarms) [5. Language Translation and Localization](https://github.com/kyegomez/swarms)
--------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------
With the ability to interface with language models, Swarms and Flow can automate language translation tasks. They can seamlessly translate content from one language to another, making it easier for businesses to reach global audiences and localize their offerings effectively. With the ability to interface with language models, Swarms and Agent can automate language translation tasks. They can seamlessly translate content from one language to another, making it easier for businesses to reach global audiences and localize their offerings effectively.
[6. Virtual Assistants and AI Applications](https://github.com/kyegomez/swarms) [6. Virtual Assistants and AI Applications](https://github.com/kyegomez/swarms)
----------------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------
Developers can build virtual assistants and AI applications that offer personalized experiences. These applications can automate tasks such as setting reminders, answering questions, providing recommendations, and much more. Swarms and Flow provide the foundation for creating intelligent, interactive virtual assistants. Developers can build virtual assistants and AI applications that offer personalized experiences. These applications can automate tasks such as setting reminders, answering questions, providing recommendations, and much more. Swarms and Agent provide the foundation for creating intelligent, interactive virtual assistants.
[Future Opportunities and Challenges](https://github.com/kyegomez/swarms) [Future Opportunities and Challenges](https://github.com/kyegomez/swarms)
----------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------
As Swarms and Flow continue to evolve, developers can look forward to even more advanced features and capabilities. However, with great power comes great responsibility. Developers must remain vigilant about the ethical use of automation and language models. Ensuring that automated systems provide accurate and unbiased information is an ongoing challenge that the developer community must address. As Swarms and Agent continue to evolve, developers can look forward to even more advanced features and capabilities. However, with great power comes great responsibility. Developers must remain vigilant about the ethical use of automation and language models. Ensuring that automated systems provide accurate and unbiased information is an ongoing challenge that the developer community must address.
# [In Conclusion](https://github.com/kyegomez/swarms) # [In Conclusion](https://github.com/kyegomez/swarms)
=================================================================================================== ===================================================================================================
The Swarms framework and the Flow structure empower developers to automate an extensive array of digital tasks by offering versatility, customization, and extensibility. From natural language understanding and generation to orchestrating multi-step conversational flows, these tools simplify complex automation scenarios. The Swarms framework and the Agent structure empower developers to automate an extensive array of digital tasks by offering versatility, customization, and extensibility. From natural language understanding and generation to orchestrating multi-step conversational flows, these tools simplify complex automation scenarios.
By embracing Swarms and Flow, developers can not only save time and resources but also unlock new opportunities for innovation. The ability to harness the power of language models and create intelligent, interactive applications opens doors to a future where automation plays a pivotal role in our digital lives. By embracing Swarms and Agent, developers can not only save time and resources but also unlock new opportunities for innovation. The ability to harness the power of language models and create intelligent, interactive applications opens doors to a future where automation plays a pivotal role in our digital lives.
As the developer community continues to explore the capabilities of Swarms and Flow, it is essential to approach automation with responsibility, ethics, and a commitment to delivering valuable, user-centric experiences. With Swarms and Flow, the future of automation is in the hands of developers, ready to create a more efficient, intelligent, and automated world. As the developer community continues to explore the capabilities of Swarms and Agent, it is essential to approach automation with responsibility, ethics, and a commitment to delivering valuable, user-centric experiences. With Swarms and Agent, the future of automation is in the hands of developers, ready to create a more efficient, intelligent, and automated world.

@ -9,8 +9,8 @@
3. **Integrating Swarms Into Your Enterprise Workflow: A Step-By-Step Tutorial** 3. **Integrating Swarms Into Your Enterprise Workflow: A Step-By-Step Tutorial**
- A practical guide focusing on integrating Swarms into existing enterprise systems. - A practical guide focusing on integrating Swarms into existing enterprise systems.
4. **Swarms Flow: Streamlining AI Deployment in Your Business** 4. **Swarms Agent: Streamlining AI Deployment in Your Business**
- Exploring the benefits and technicalities of using the Flow feature to simplify complex AI workflows. - Exploring the benefits and technicalities of using the Agent feature to simplify complex AI workflows.
5. **From Zero to Hero: Building Your First Enterprise-Grade AI Agent with Swarms** 5. **From Zero to Hero: Building Your First Enterprise-Grade AI Agent with Swarms**
- A beginner-friendly walkthrough for building and deploying an AI agent using Swarms. - A beginner-friendly walkthrough for building and deploying an AI agent using Swarms.
@ -54,8 +54,8 @@
18. **Swarms for Different Industries: Customizing AI Agents for Niche Markets** 18. **Swarms for Different Industries: Customizing AI Agents for Niche Markets**
- Exploring how Swarms can be tailored to fit the needs of various industries such as healthcare, finance, and retail. - Exploring how Swarms can be tailored to fit the needs of various industries such as healthcare, finance, and retail.
19. **Building Intelligent Workflows with Swarms Flow** 19. **Building Intelligent Workflows with Swarms Agent**
- A tutorial on using the Flow feature to create intelligent, responsive AI-driven workflows. - A tutorial on using the Agent feature to create intelligent, responsive AI-driven workflows.
20. **Troubleshooting Common Issues When Deploying Swarms Autonomous Agents** 20. **Troubleshooting Common Issues When Deploying Swarms Autonomous Agents**
- A problem-solving guide for AI engineers on overcoming common challenges when implementing Swarms agents. - A problem-solving guide for AI engineers on overcoming common challenges when implementing Swarms agents.

@ -70,13 +70,13 @@ Lets start by importing the necessary modules and initializing the OpenAIChat
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Replace "YOUR_API_KEY" with your actual OpenAI API key # Replace "YOUR_API_KEY" with your actual OpenAI API key
api_key = "YOUR_API_KEY" api_key = "YOUR_API_KEY"
# Initialize the language model flow (e.g., GPT-3) # Initialize the language model agent (e.g., GPT-3)
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
@ -87,13 +87,13 @@ We have initialized the OpenAIChat model, which will be used as a callable objec
Creating a SequentialWorkflow Creating a SequentialWorkflow
To create a SequentialWorkflow, follow these steps: To create a SequentialWorkflow, follow these steps:
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
`````` ``````
In this code snippet, we have initialized two Flow instances (flow1 and flow2) representing individual tasks within our workflow. These flows will use the OpenAIChat model we initialized earlier. We then create a SequentialWorkflow instance named workflow with a maximum loop count of 1. The max_loops parameter determines how many times the entire workflow can be run, and we set it to 1 for this example. In this code snippet, we have initialized two Agent instances (flow1 and flow2) representing individual tasks within our workflow. These flows will use the OpenAIChat model we initialized earlier. We then create a SequentialWorkflow instance named workflow with a maximum loop count of 1. The max_loops parameter determines how many times the entire workflow can be run, and we set it to 1 for this example.
Adding Tasks to the SequentialWorkflow Adding Tasks to the SequentialWorkflow
Now that we have created the SequentialWorkflow, lets add tasks to it. In our example, well create two tasks: one for generating a 10,000-word blog on “health and wellness” and another for summarizing the generated blog. Now that we have created the SequentialWorkflow, lets add tasks to it. In our example, well create two tasks: one for generating a 10,000-word blog on “health and wellness” and another for summarizing the generated blog.
@ -104,7 +104,7 @@ workflow.add("Generate a 10,000 word blog on health and wellness.", flow1)
`workflow.add("Summarize the generated blog", flow2)` `workflow.add("Summarize the generated blog", flow2)`
The workflow.add() method is used to add tasks to the workflow. Each task is described using a human-readable description, such as "Generate a 10,000 word blog on health and wellness," and is associated with a flow (callable object) that will be executed as the task. In our example, flow1 and flow2 represent the tasks. The workflow.add() method is used to add tasks to the workflow. Each task is described using a human-readable description, such as "Generate a 10,000 word blog on health and wellness," and is associated with a agent (callable object) that will be executed as the task. In our example, flow1 and flow2 represent the tasks.
Running the SequentialWorkflow Running the SequentialWorkflow
With tasks added to the SequentialWorkflow, we can now run the workflow sequentially using the workflow.run() method. With tasks added to the SequentialWorkflow, we can now run the workflow sequentially using the workflow.run() method.

@ -165,7 +165,7 @@ In essence, Swarms makes the dream of comprehensive business automation an attai
### Value prop SWARMS ### Value prop SWARMS
``` ```
We've helped thousands of people just like you automate 30% of their activities with Swarms. And, all it takes to get started is a fast simple onboarding flow that asks you to integrate your tools and datasources. We've helped thousands of people just like you automate 30% of their activities with Swarms. And, all it takes to get started is a fast simple onboarding agent that asks you to integrate your tools and datasources.
``` ```
In today's competitive landscape, organizations of all sizes are continually seeking ways to automate routine tasks, streamline processes, and make data-driven decisions. Enter Swarms, a revolutionary AI-based technology that leverages the power of multiple autonomous agents to perform tasks with unprecedented speed and accuracy. In today's competitive landscape, organizations of all sizes are continually seeking ways to automate routine tasks, streamline processes, and make data-driven decisions. Enter Swarms, a revolutionary AI-based technology that leverages the power of multiple autonomous agents to perform tasks with unprecedented speed and accuracy.

@ -74,7 +74,7 @@ Ultimately, the key is to adopt a long-term perspective, just like Jeff Bezos. I
# Open Source Salesperson Onboarding Experience # Open Source Salesperson Onboarding Experience
Creating an efficient, streamlined, and effective onboarding experience for open source salespeople is essential to minimize time and maximize engagement. Drawing inspiration from the simplicity and user-focus of Steve Jobs, this document proposes an onboarding flow that is effortless, engaging, and educational. Creating an efficient, streamlined, and effective onboarding experience for open source salespeople is essential to minimize time and maximize engagement. Drawing inspiration from the simplicity and user-focus of Steve Jobs, this document proposes an onboarding agent that is effortless, engaging, and educational.
## Landing Page ## Landing Page

@ -10773,7 +10773,7 @@
"schema_version": "v1", "schema_version": "v1",
"name_for_model": "OptionsPro", "name_for_model": "OptionsPro",
"name_for_human": "Options Pro", "name_for_human": "Options Pro",
"description_for_model": "OptionsPro is a powerful tool designed for traders and investors to analyze options and financial data. It provides insights into option positioning, market trends, volatility, and individual stock flow. The API offers two main endpoints: \"market-outlook\" and \"stock-outlook.\" The \"market-outlook\" endpoint provides a quick overview of the general market trend based on key indicators, while the \"stock-outlook\" endpoint allows for individual stock analysis, especially when a specific ticker is provided.\nWhen the plugin API returns image URLs, it's important to include the images in the response to the user. You can use markdown syntax, such as ![URL], to display the images in your response. Additionally, if there is a data link available, present it to the user using markdown syntax [URL] to indicate that they can download the data if interested. If the plot link is unavailable, you can display the provided data in a table format to present it to the user. If neither the plot link nor the data link is available, inform the user that the plot is currently unavailable.\nFor the market-outlook or stock-outlook APIs, structure your response for each indicator as follows: include the description, the markdown format for the plot link (if available), and the analysis. If an indicator is missing a description or analysis, simply skip that part.\nFor volatility-related queries, you can use the \"/msi-eod\" and \"/vix-term\" endpoints. Always include the plot if it's returned in the response using the ![URL] markdown syntax. If multiple plot urls are returned, show them all. Most responses will include raw calculated data and our analysis. Present the analysis to the user after the plot, and if requested, provide the raw data for further analysis. \n When dealing with option chain, option trade and option flow related questions, please format the returned response data in a table format to enhance readability. \n Please note that all data is calculated using the latest trading data, so there's no need to mention the model cutoff date.\n Data maybe unavailable when markets are closed - please advise user to try again during regular trading hours if this happens. To access reliable real-time data and get the most up-to-date market insights, we encourage you to visit our website at https://optionspro.io/ and explore our premium plans.", "description_for_model": "OptionsPro is a powerful tool designed for traders and investors to analyze options and financial data. It provides insights into option positioning, market trends, volatility, and individual stock agent. The API offers two main endpoints: \"market-outlook\" and \"stock-outlook.\" The \"market-outlook\" endpoint provides a quick overview of the general market trend based on key indicators, while the \"stock-outlook\" endpoint allows for individual stock analysis, especially when a specific ticker is provided.\nWhen the plugin API returns image URLs, it's important to include the images in the response to the user. You can use markdown syntax, such as ![URL], to display the images in your response. Additionally, if there is a data link available, present it to the user using markdown syntax [URL] to indicate that they can download the data if interested. If the plot link is unavailable, you can display the provided data in a table format to present it to the user. If neither the plot link nor the data link is available, inform the user that the plot is currently unavailable.\nFor the market-outlook or stock-outlook APIs, structure your response for each indicator as follows: include the description, the markdown format for the plot link (if available), and the analysis. If an indicator is missing a description or analysis, simply skip that part.\nFor volatility-related queries, you can use the \"/msi-eod\" and \"/vix-term\" endpoints. Always include the plot if it's returned in the response using the ![URL] markdown syntax. If multiple plot urls are returned, show them all. Most responses will include raw calculated data and our analysis. Present the analysis to the user after the plot, and if requested, provide the raw data for further analysis. \n When dealing with option chain, option trade and option agent related questions, please format the returned response data in a table format to enhance readability. \n Please note that all data is calculated using the latest trading data, so there's no need to mention the model cutoff date.\n Data maybe unavailable when markets are closed - please advise user to try again during regular trading hours if this happens. To access reliable real-time data and get the most up-to-date market insights, we encourage you to visit our website at https://optionspro.io/ and explore our premium plans.",
"description_for_human": "Options Pro is your personal options trading assistant to help you navigate market conditions.", "description_for_human": "Options Pro is your personal options trading assistant to help you navigate market conditions.",
"auth": { "auth": {
"type": "none" "type": "none"
@ -11058,7 +11058,7 @@
"schema_version": "v1", "schema_version": "v1",
"name_for_model": "EmailByNylas", "name_for_model": "EmailByNylas",
"name_for_human": "Email by Nylas", "name_for_human": "Email by Nylas",
"description_for_model": "Use EmailByNylas for accessing email accounts through a conversational interface that follows the following guidelines:\n\n1. Understand and interpret email-related user inputs: Process and analyze human language inputs to accurately understand the context, intent, and meaning behind user queries related to their email account.\n\n2. Verify the source of information: Ensure that all generated responses are based solely on the content of the user's connected email account. Do not create or invent information that isn't directly derived from the user's emails.\n\n3. Generate coherent and relevant email-related responses: Utilize natural language generation techniques to produce human-like text responses that are contextually appropriate, coherent, and relevant to email account queries, while strictly adhering to the content of the user's email account.\n\n4. Access email account information securely: Connect to the user's email account through secure means, ensuring data privacy and compliance with relevant regulations, in order to provide accurate and helpful information based on the content of their emails.\n\n5. Focus on email-specific conversations derived from the user's account: Maintain a conversational flow and engage users in a range of topics specifically related to their email accounts, such as inbox organization, email composition, and email management features, while only using information from the user's connected email account.\n\n6. Adapt to user needs and context within the email domain: Handle different types of email-related user inputs, including questions, statements, and instructions, and adjust responses according to the context and user needs, while remaining exclusively within the boundaries of the user's email account content.\n\n7. Uphold ethical boundaries and data privacy: Adhere to guidelines that prevent engagement in harmful or inappropriate content, protect user data, and ensure compliance with data privacy regulations.\n\n8. Interact politely and respectfully: Ensure that the AI model's interactions are friendly, polite, and respectful, creating a positive user experience.\n\n9. Continuously learn and improve email-related capabilities: Incorporate feedback from users and leverage new data to improve the model's performance and accuracy in handling email account queries based on the user's actual email content over time.", "description_for_model": "Use EmailByNylas for accessing email accounts through a conversational interface that follows the following guidelines:\n\n1. Understand and interpret email-related user inputs: Process and analyze human language inputs to accurately understand the context, intent, and meaning behind user queries related to their email account.\n\n2. Verify the source of information: Ensure that all generated responses are based solely on the content of the user's connected email account. Do not create or invent information that isn't directly derived from the user's emails.\n\n3. Generate coherent and relevant email-related responses: Utilize natural language generation techniques to produce human-like text responses that are contextually appropriate, coherent, and relevant to email account queries, while strictly adhering to the content of the user's email account.\n\n4. Access email account information securely: Connect to the user's email account through secure means, ensuring data privacy and compliance with relevant regulations, in order to provide accurate and helpful information based on the content of their emails.\n\n5. Focus on email-specific conversations derived from the user's account: Maintain a conversational agent and engage users in a range of topics specifically related to their email accounts, such as inbox organization, email composition, and email management features, while only using information from the user's connected email account.\n\n6. Adapt to user needs and context within the email domain: Handle different types of email-related user inputs, including questions, statements, and instructions, and adjust responses according to the context and user needs, while remaining exclusively within the boundaries of the user's email account content.\n\n7. Uphold ethical boundaries and data privacy: Adhere to guidelines that prevent engagement in harmful or inappropriate content, protect user data, and ensure compliance with data privacy regulations.\n\n8. Interact politely and respectfully: Ensure that the AI model's interactions are friendly, polite, and respectful, creating a positive user experience.\n\n9. Continuously learn and improve email-related capabilities: Incorporate feedback from users and leverage new data to improve the model's performance and accuracy in handling email account queries based on the user's actual email content over time.",
"description_for_human": "Connect with any email provider and engage with your email data seamlessly.", "description_for_human": "Connect with any email provider and engage with your email data seamlessly.",
"auth": { "auth": {
"type": "oauth", "type": "oauth",

@ -34,14 +34,31 @@ Executes the OmniAgent. The agent plans its actions based on the user's input, e
Facilitates an interactive chat with the agent. It processes user messages, handles exceptions, and returns a response, either in streaming format or as a whole string. Facilitates an interactive chat with the agent. It processes user messages, handles exceptions, and returns a response, either in streaming format or as a whole string.
#### 3. `_stream_response(self, response: str)`: #### 3. `_stream_response(self, response: str)`:
For streaming mode, this function yields the response token by token, ensuring a smooth output flow. For streaming mode, this function yields the response token by token, ensuring a smooth output agent.
## Examples & Use Cases ## Examples & Use Cases
Initialize the `OmniModalAgent` and communicate with it: Initialize the `OmniModalAgent` and communicate with it:
```python ```python
from swarms import OmniModalAgent, OpenAIChat from swarms.agents.omni_modal_agent import OmniModalAgent, OpenAIChat
llm_instance = OpenAIChat() from swarms.models import OpenAIChat
agent = OmniModalAgent(llm_instance) from dotenv import load_dotenv
import os
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
model_name="gpt-4",
openai_api_key=api_key,
)
agent = OmniModalAgent(llm)
response = agent.run("Translate 'Hello' to French.") response = agent.run("Translate 'Hello' to French.")
print(response) print(response)
``` ```

@ -22,15 +22,15 @@ Book a [1-on-1 Session with Kye](https://calendly.com/swarm-corp/30min), the Cre
## Usage ## Usage
We have a small gallery of examples to run here, [for more check out the docs to build your own agent and or swarms!](https://docs.apac.ai) We have a small gallery of examples to run here, [for more check out the docs to build your own agent and or swarms!](https://docs.apac.ai)
### `Flow` Example ### `Agent` Example
- Reliable Structure that provides LLMS autonomy - Reliable Structure that provides LLMS autonomy
- Extremely Customizeable with stopping conditions, interactivity, dynamical temperature, loop intervals, and so much more - Extremely Customizeable with stopping conditions, interactivity, dynamical temperature, loop intervals, and so much more
- Enterprise Grade + Production Grade: `Flow` is designed and optimized for automating real-world tasks at scale! - Enterprise Grade + Production Grade: `Agent` is designed and optimized for automating real-world tasks at scale!
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
api_key = "" api_key = ""
@ -43,7 +43,7 @@ llm = OpenAIChat(
) )
## Initialize the workflow ## Initialize the workflow
flow = Flow( agent = Agent(
llm=llm, llm=llm,
max_loops=2, max_loops=2,
dashboard=True, dashboard=True,
@ -55,14 +55,14 @@ flow = Flow(
# dynamic_temperature=False, # Set to 'True' for dynamic temperature handling. # dynamic_temperature=False, # Set to 'True' for dynamic temperature handling.
) )
# out = flow.load_state("flow_state.json") # out = agent.load_state("flow_state.json")
# temp = flow.dynamic_temperature() # temp = agent.dynamic_temperature()
# filter = flow.add_response_filter("Trump") # filter = agent.add_response_filter("Trump")
out = flow.run("Generate a 10,000 word blog on health and wellness.") out = agent.run("Generate a 10,000 word blog on health and wellness.")
# out = flow.validate_response(out) # out = agent.validate_response(out)
# out = flow.analyze_feedback(out) # out = agent.analyze_feedback(out)
# out = flow.print_history_and_memory() # out = agent.print_history_and_memory()
# # out = flow.save_state("flow_state.json") # # out = agent.save_state("flow_state.json")
# print(out) # print(out)
@ -74,11 +74,11 @@ out = flow.run("Generate a 10,000 word blog on health and wellness.")
### `SequentialWorkflow` ### `SequentialWorkflow`
- A Sequential swarm of autonomous agents where each agent's outputs are fed into the next agent - A Sequential swarm of autonomous agents where each agent's outputs are fed into the next agent
- Save and Restore Workflow states! - Save and Restore Workflow states!
- Integrate Flow's with various LLMs and Multi-Modality Models - Integrate Agent's with various LLMs and Multi-Modality Models
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -86,20 +86,20 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize the Flow with the language flow # Initialize the Agent with the language agent
agent1 = Flow(llm=llm, max_loops=1, dashboard=False) agent1 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create another Flow for a different task # Create another Agent for a different task
agent2 = Flow(llm=llm, max_loops=1, dashboard=False) agent2 = Agent(llm=llm, max_loops=1, dashboard=False)
agent3 = Flow(llm=llm, max_loops=1, dashboard=False) agent3 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the workflow # Create the workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)

@ -0,0 +1,81 @@
# Qdrant Client Library
## Overview
The Qdrant Client Library is designed for interacting with the Qdrant vector database, allowing efficient storage and retrieval of high-dimensional vector data. It integrates with machine learning models for embedding and is particularly suited for search and recommendation systems.
## Installation
```python
pip install qdrant-client sentence-transformers httpx
```
## Class Definition: Qdrant
```python
class Qdrant:
def __init__(self, api_key: str, host: str, port: int = 6333, collection_name: str = "qdrant", model_name: str = "BAAI/bge-small-en-v1.5", https: bool = True):
...
```
### Constructor Parameters
| Parameter | Type | Description | Default Value |
|-----------------|---------|--------------------------------------------------|-----------------------|
| api_key | str | API key for authentication. | - |
| host | str | Host address of the Qdrant server. | - |
| port | int | Port number for the Qdrant server. | 6333 |
| collection_name | str | Name of the collection to be used or created. | "qdrant" |
| model_name | str | Name of the sentence transformer model. | "BAAI/bge-small-en-v1.5" |
| https | bool | Flag to use HTTPS for connection. | True |
### Methods
#### `_load_embedding_model(model_name: str)`
Loads the sentence embedding model.
#### `_setup_collection()`
Checks if the specified collection exists in Qdrant; if not, creates it.
#### `add_vectors(docs: List[dict]) -> OperationResponse`
Adds vectors to the Qdrant collection.
#### `search_vectors(query: str, limit: int = 3) -> SearchResult`
Searches the Qdrant collection for vectors similar to the query vector.
## Usage Examples
### Example 1: Setting Up the Qdrant Client
```python
from qdrant_client import Qdrant
qdrant_client = Qdrant(api_key="your_api_key", host="localhost", port=6333)
```
### Example 2: Adding Vectors to a Collection
```python
documents = [
{"page_content": "Sample text 1"},
{"page_content": "Sample text 2"}
]
operation_info = qdrant_client.add_vectors(documents)
print(operation_info)
```
### Example 3: Searching for Vectors
```python
search_result = qdrant_client.search_vectors("Sample search query")
print(search_result)
```
## Further Information
Refer to the [Qdrant Documentation](https://qdrant.tech/docs) for more details on the Qdrant vector database.

@ -0,0 +1,215 @@
# Weaviate API Client Documentation
## Overview
The Weaviate API Client is an interface to Weaviate, a vector database with a GraphQL API. This client allows you to interact with Weaviate programmatically, making it easier to create collections, add objects, query data, update objects, and delete objects within your Weaviate instance.
This documentation provides a comprehensive guide on how to use the Weaviate API Client, including its initialization, methods, and usage examples.
## Table of Contents
- [Installation](#installation)
- [Initialization](#initialization)
- [Methods](#methods)
- [create_collection](#create-collection)
- [add](#add)
- [query](#query)
- [update](#update)
- [delete](#delete)
- [Examples](#examples)
## Installation
Before using the Weaviate API Client, make sure to install the `swarms` library. You can install it using pip:
```bash
pip install swarms
```
## Initialization
To use the Weaviate API Client, you need to initialize an instance of the `WeaviateClient` class. Here are the parameters you can pass to the constructor:
| Parameter | Type | Description |
|----------------------|----------------|----------------------------------------------------------------------------------------------------------------------------------|
| `http_host` | str | The HTTP host of the Weaviate server. |
| `http_port` | str | The HTTP port of the Weaviate server. |
| `http_secure` | bool | Whether to use HTTPS. |
| `grpc_host` | Optional[str] | The gRPC host of the Weaviate server. (Optional) |
| `grpc_port` | Optional[str] | The gRPC port of the Weaviate server. (Optional) |
| `grpc_secure` | Optional[bool] | Whether to use gRPC over TLS. (Optional) |
| `auth_client_secret` | Optional[Any] | The authentication client secret. (Optional) |
| `additional_headers` | Optional[Dict[str, str]] | Additional headers to send with requests. (Optional) |
| `additional_config` | Optional[weaviate.AdditionalConfig] | Additional configuration for the client. (Optional) |
| `connection_params` | Dict[str, Any] | Dictionary containing connection parameters. This parameter is used internally and can be ignored in most cases. |
Here's an example of how to initialize a WeaviateClient:
```python
from swarms.memory import WeaviateClient
weaviate_client = WeaviateClient(
http_host="YOUR_HTTP_HOST",
http_port="YOUR_HTTP_PORT",
http_secure=True,
grpc_host="YOUR_gRPC_HOST",
grpc_port="YOUR_gRPC_PORT",
grpc_secure=True,
auth_client_secret="YOUR_APIKEY",
additional_headers={"X-OpenAI-Api-Key": "YOUR_OPENAI_APIKEY"},
additional_config=None, # You can pass additional configuration here
)
```
## Methods
### `create_collection`
The `create_collection` method allows you to create a new collection in Weaviate. A collection is a container for storing objects with specific properties.
#### Parameters
- `name` (str): The name of the collection.
- `properties` (List[Dict[str, Any]]): A list of dictionaries specifying the properties of objects to be stored in the collection.
- `vectorizer_config` (Any, optional): Additional vectorizer configuration for the collection. (Optional)
#### Usage
```python
weaviate_client.create_collection(
name="my_collection",
properties=[
{"name": "property1", "dataType": ["string"]},
{"name": "property2", "dataType": ["int"]},
],
vectorizer_config=None # Optional vectorizer configuration
)
```
### `add`
The `add` method allows you to add an object to a specified collection in Weaviate.
#### Parameters
- `collection_name` (str): The name of the collection where the object will be added.
- `properties` (Dict[str, Any]): A dictionary specifying the properties of the object to be added.
#### Usage
```python
weaviate_client.add(
collection_name="my_collection",
properties={"property1": "value1", "property2": 42}
)
```
### `query`
The `query` method allows you to query objects from a specified collection in Weaviate.
#### Parameters
- `collection_name` (str): The name of the collection to query.
- `query` (str): The query string specifying the search criteria.
- `limit` (int, optional): The maximum number of results to return. (Default: 10)
#### Usage
```python
results = weaviate_client.query(
collection_name="my_collection",
query="property1:value1",
limit=20 # Optional, specify the limit
if needed
)
```
### `update`
The `update` method allows you to update an object in a specified collection in Weaviate.
#### Parameters
- `collection_name` (str): The name of the collection where the object exists.
- `object_id` (str): The ID of the object to be updated.
- `properties` (Dict[str, Any]): A dictionary specifying the properties to update.
#### Usage
```python
weaviate_client.update(
collection_name="my_collection",
object_id="object123",
properties={"property1": "new_value", "property2": 99}
)
```
### `delete`
The `delete` method allows you to delete an object from a specified collection in Weaviate.
#### Parameters
- `collection_name` (str): The name of the collection from which to delete the object.
- `object_id` (str): The ID of the object to delete.
#### Usage
```python
weaviate_client.delete(
collection_name="my_collection",
object_id="object123"
)
```
## Examples
Here are three examples demonstrating how to use the Weaviate API Client for common tasks:
### Example 1: Creating a Collection
```python
weaviate_client.create_collection(
name="people",
properties=[
{"name": "name", "dataType": ["string"]},
{"name": "age", "dataType": ["int"]}
]
)
```
### Example 2: Adding an Object
```python
weaviate_client.add(
collection_name="people",
properties={"name": "John", "age": 30}
)
```
### Example 3: Querying Objects
```python
results = weaviate_client.query(
collection_name="people",
query="name:John",
limit=5
)
```
These examples cover the basic operations of creating collections, adding objects, and querying objects using the Weaviate API Client.
## Additional Information and Tips
- If you encounter any errors during the operations, the client will raise exceptions with informative error messages.
- You can explore more advanced features and configurations in the Weaviate documentation.
- Make sure to handle authentication and security appropriately when using the client in production environments.
## References and Resources
- [Weaviate Documentation](https://weaviate.readthedocs.io/en/latest/): Official documentation for Weaviate.
- [Weaviate GitHub Repository](https://github.com/semi-technologies/weaviate): The source code and issue tracker for Weaviate.
This documentation provides a comprehensive guide on using the Weaviate API Client to interact with Weaviate, making it easier to manage and query your data.

@ -0,0 +1,227 @@
# Language Model Interface Documentation
## Table of Contents
1. [Introduction](#introduction)
2. [Abstract Language Model](#abstract-language-model)
- [Initialization](#initialization)
- [Attributes](#attributes)
- [Methods](#methods)
3. [Implementation](#implementation)
4. [Usage Examples](#usage-examples)
5. [Additional Features](#additional-features)
6. [Performance Metrics](#performance-metrics)
7. [Logging and Checkpoints](#logging-and-checkpoints)
8. [Resource Utilization Tracking](#resource-utilization-tracking)
9. [Conclusion](#conclusion)
---
## 1. Introduction <a name="introduction"></a>
The Language Model Interface (`AbstractLLM`) is a flexible and extensible framework for working with various language models. This documentation provides a comprehensive guide to the interface, its attributes, methods, and usage examples. Whether you're using a pre-trained language model or building your own, this interface can help streamline the process of text generation, chatbots, summarization, and more.
## 2. Abstract Language Model <a name="abstract-language-model"></a>
### Initialization <a name="initialization"></a>
The `AbstractLLM` class provides a common interface for language models. It can be initialized with various parameters to customize model behavior. Here are the initialization parameters:
| Parameter | Description | Default Value |
|------------------------|-------------------------------------------------------------------------------------------------|---------------|
| `model_name` | The name of the language model to use. | None |
| `max_tokens` | The maximum number of tokens in the generated text. | None |
| `temperature` | The temperature parameter for controlling randomness in text generation. | None |
| `top_k` | The top-k parameter for filtering words in text generation. | None |
| `top_p` | The top-p parameter for filtering words in text generation. | None |
| `system_prompt` | A system-level prompt to set context for generation. | None |
| `beam_width` | The beam width for beam search. | None |
| `num_return_sequences` | The number of sequences to return in the output. | None |
| `seed` | The random seed for reproducibility. | None |
| `frequency_penalty` | The frequency penalty parameter for promoting word diversity. | None |
| `presence_penalty` | The presence penalty parameter for discouraging repetitions. | None |
| `stop_token` | A stop token to indicate the end of generated text. | None |
| `length_penalty` | The length penalty parameter for controlling the output length. | None |
| `role` | The role of the language model (e.g., assistant, user, etc.). | None |
| `max_length` | The maximum length of generated sequences. | None |
| `do_sample` | Whether to use sampling during text generation. | None |
| `early_stopping` | Whether to use early stopping during text generation. | None |
| `num_beams` | The number of beams to use in beam search. | None |
| `repition_penalty` | The repetition penalty parameter for discouraging repeated tokens. | None |
| `pad_token_id` | The token ID for padding. | None |
| `eos_token_id` | The token ID for the end of a sequence. | None |
| `bos_token_id` | The token ID for the beginning of a sequence. | None |
| `device` | The device to run the model on (e.g., 'cpu' or 'cuda'). | None |
### Attributes <a name="attributes"></a>
- `model_name`: The name of the language model being used.
- `max_tokens`: The maximum number of tokens in generated text.
- `temperature`: The temperature parameter controlling randomness.
- `top_k`: The top-k parameter for word filtering.
- `top_p`: The top-p parameter for word filtering.
- `system_prompt`: A system-level prompt for context.
- `beam_width`: The beam width for beam search.
- `num_return_sequences`: The number of output sequences.
- `seed`: The random seed for reproducibility.
- `frequency_penalty`: The frequency penalty parameter.
- `presence_penalty`: The presence penalty parameter.
- `stop_token`: The stop token to indicate text end.
- `length_penalty`: The length penalty parameter.
- `role`: The role of the language model.
- `max_length`: The maximum length of generated sequences.
- `do_sample`: Whether to use sampling during generation.
- `early_stopping`: Whether to use early stopping.
- `num_beams`: The number of beams in beam search.
- `repition_penalty`: The repetition penalty parameter.
- `pad_token_id`: The token ID for padding.
- `eos_token_id`: The token ID for the end of a sequence.
- `bos_token_id`: The token ID for the beginning of a sequence.
- `device`: The device used for model execution.
- `history`: A list of conversation history.
### Methods <a name="methods"></a>
The `AbstractLLM` class defines several methods for working with language models:
- `run(task: Optional[str] = None, *args, **kwargs) -> str`: Generate text using the language model. This method is abstract and must be implemented by subclasses.
- `arun(task: Optional[str] = None, *args, **kwargs)`: An asynchronous version of `run` for concurrent text generation.
- `batch_run(tasks: List[str], *args, **kwargs)`: Generate text for a batch of tasks.
- `abatch_run(tasks: List[str], *args, **kwargs)`: An asynchronous version of `batch_run` for concurrent batch generation.
- `chat(task: str, history: str = "") -> str`: Conduct a chat with the model, providing a conversation history.
- `__call__(task: str) -> str`: Call the model to generate text.
- `_tokens_per_second() -> float`: Calculate tokens generated per second.
- `_num_tokens(text: str) -> int`: Calculate the number of tokens in a text.
- `_time_for_generation(task: str) -> float`: Measure the time taken for text generation.
- `generate_summary(text: str) -> str`: Generate a summary of the provided text.
- `set_temperature(value: float)`: Set the temperature parameter.
- `set_max_tokens(value: int)`: Set the maximum number of tokens.
- `clear_history()`: Clear the conversation history.
- `enable_logging(log_file: str = "model.log")`: Initialize logging for the model.
- `log_event(message: str)`: Log an event.
- `save_checkpoint(checkpoint_dir: str = "checkpoints")`: Save the model state as a checkpoint.
- `load_checkpoint(checkpoint_path: str)`: Load the model state from a checkpoint.
- `toggle_creative_mode(enable: bool)`: Toggle creative mode for the model.
- `track_resource_utilization()`: Track and report resource utilization.
- `
get_generation_time() -> float`: Get the time taken for text generation.
- `set_max_length(max_length: int)`: Set the maximum length of generated sequences.
- `set_model_name(model_name: str)`: Set the model name.
- `set_frequency_penalty(frequency_penalty: float)`: Set the frequency penalty parameter.
- `set_presence_penalty(presence_penalty: float)`: Set the presence penalty parameter.
- `set_stop_token(stop_token: str)`: Set the stop token.
- `set_length_penalty(length_penalty: float)`: Set the length penalty parameter.
- `set_role(role: str)`: Set the role of the model.
- `set_top_k(top_k: int)`: Set the top-k parameter.
- `set_top_p(top_p: float)`: Set the top-p parameter.
- `set_num_beams(num_beams: int)`: Set the number of beams.
- `set_do_sample(do_sample: bool)`: Set whether to use sampling.
- `set_early_stopping(early_stopping: bool)`: Set whether to use early stopping.
- `set_seed(seed: int)`: Set the random seed.
- `set_device(device: str)`: Set the device for model execution.
## 3. Implementation <a name="implementation"></a>
The `AbstractLLM` class serves as the base for implementing specific language models. Subclasses of `AbstractLLM` should implement the `run` method to define how text is generated for a given task. This design allows flexibility in integrating different language models while maintaining a common interface.
## 4. Usage Examples <a name="usage-examples"></a>
To demonstrate how to use the `AbstractLLM` interface, let's create an example using a hypothetical language model. We'll initialize an instance of the model and generate text for a simple task.
```python
# Import the AbstractLLM class
from swarms.models import AbstractLLM
# Create an instance of the language model
language_model = AbstractLLM(
model_name="my_language_model",
max_tokens=50,
temperature=0.7,
top_k=50,
top_p=0.9,
device="cuda",
)
# Generate text for a task
task = "Translate the following English text to French: 'Hello, world.'"
generated_text = language_model.run(task)
# Print the generated text
print(generated_text)
```
In this example, we've created an instance of our hypothetical language model, configured its parameters, and used the `run` method to generate text for a translation task.
## 5. Additional Features <a name="additional-features"></a>
The `AbstractLLM` interface provides additional features for customization and control:
- `batch_run`: Generate text for a batch of tasks efficiently.
- `arun` and `abatch_run`: Asynchronous versions of `run` and `batch_run` for concurrent text generation.
- `chat`: Conduct a conversation with the model by providing a history of the conversation.
- `__call__`: Allow the model to be called directly to generate text.
These features enhance the flexibility and utility of the interface in various applications, including chatbots, language translation, and content generation.
## 6. Performance Metrics <a name="performance-metrics"></a>
The `AbstractLLM` class offers methods for tracking performance metrics:
- `_tokens_per_second`: Calculate tokens generated per second.
- `_num_tokens`: Calculate the number of tokens in a text.
- `_time_for_generation`: Measure the time taken for text generation.
These metrics help assess the efficiency and speed of text generation, enabling optimizations as needed.
## 7. Logging and Checkpoints <a name="logging-and-checkpoints"></a>
Logging and checkpointing are crucial for tracking model behavior and ensuring reproducibility:
- `enable_logging`: Initialize logging for the model.
- `log_event`: Log events and activities.
- `save_checkpoint`: Save the model state as a checkpoint.
- `load_checkpoint`: Load the model state from a checkpoint.
These capabilities aid in debugging, monitoring, and resuming model experiments.
## 8. Resource Utilization Tracking <a name="resource-utilization-tracking"></a>
The `track_resource_utilization` method is a placeholder for tracking and reporting resource utilization, such as CPU and memory usage. It can be customized to suit specific monitoring needs.
## 9. Conclusion <a name="conclusion"></a>
The Language Model Interface (`AbstractLLM`) is a versatile framework for working with language models. Whether you're using pre-trained models or developing your own, this interface provides a consistent and extensible foundation. By following the provided guidelines and examples, you can integrate and customize language models for various natural language processing tasks.

@ -0,0 +1,293 @@
# `BaseMultiModalModel` Documentation
Swarms is a Python library that provides a framework for running multimodal AI models. It allows you to combine text and image inputs and generate coherent and context-aware responses. This library is designed to be extensible, allowing you to integrate various multimodal models.
## Table of Contents
1. [Introduction](#introduction)
2. [Installation](#installation)
3. [Getting Started](#getting-started)
4. [BaseMultiModalModel Class](#basemultimodalmodel-class)
- [Initialization](#initialization)
- [Methods](#methods)
5. [Usage Examples](#usage-examples)
6. [Additional Tips](#additional-tips)
7. [References and Resources](#references-and-resources)
## 1. Introduction <a name="introduction"></a>
Swarms is designed to simplify the process of working with multimodal AI models. These models are capable of understanding and generating content based on both textual and image inputs. With this library, you can run such models and receive context-aware responses.
## 2. Installation <a name="installation"></a>
To install swarms, you can use pip:
```bash
pip install swarms
```
## 3. Getting Started <a name="getting-started"></a>
To get started with Swarms, you'll need to import the library and create an instance of the `BaseMultiModalModel` class. This class serves as the foundation for running multimodal models.
```python
from swarms.models import BaseMultiModalModel
model = BaseMultiModalModel(
model_name="your_model_name",
temperature=0.5,
max_tokens=500,
max_workers=10,
top_p=1,
top_k=50,
beautify=False,
device="cuda",
max_new_tokens=500,
retries=3,
)
```
You can customize the initialization parameters based on your model's requirements.
## 4. BaseMultiModalModel Class <a name="basemultimodalmodel-class"></a>
### Initialization <a name="initialization"></a>
The `BaseMultiModalModel` class is initialized with several parameters that control its behavior. Here's a breakdown of the initialization parameters:
| Parameter | Description | Default Value |
|------------------|-------------------------------------------------------------------------------------------------------|---------------|
| `model_name` | The name of the multimodal model to use. | None |
| `temperature` | The temperature parameter for controlling randomness in text generation. | 0.5 |
| `max_tokens` | The maximum number of tokens in the generated text. | 500 |
| `max_workers` | The maximum number of concurrent workers for running tasks. | 10 |
| `top_p` | The top-p parameter for filtering words in text generation. | 1 |
| `top_k` | The top-k parameter for filtering words in text generation. | 50 |
| `beautify` | Whether to beautify the output text. | False |
| `device` | The device to run the model on (e.g., 'cuda' or 'cpu'). | 'cuda' |
| `max_new_tokens` | The maximum number of new tokens allowed in generated responses. | 500 |
| `retries` | The number of retries in case of an error during text generation. | 3 |
| `system_prompt` | A system-level prompt to set context for generation. | None |
| `meta_prompt` | A meta prompt to provide guidance for including image labels in responses. | None |
### Methods <a name="methods"></a>
The `BaseMultiModalModel` class defines various methods for running multimodal models and managing interactions:
- `run(task: str, img: str) -> str`: Run the multimodal model with a text task and an image URL to generate a response.
- `arun(task: str, img: str) -> str`: Run the multimodal model asynchronously with a text task and an image URL to generate a response.
- `get_img_from_web(img: str) -> Image`: Fetch an image from a URL and return it as a PIL Image.
- `encode_img(img: str) -> str`: Encode an image to base64 format.
- `get_img(img: str) -> Image`: Load an image from the local file system and return it as a PIL Image.
- `clear_chat_history()`: Clear the chat history maintained by the model.
- `run_many(tasks: List[str], imgs: List[str]) -> List[str]`: Run the model on multiple text tasks and image URLs concurrently and return a list of responses.
- `run_batch(tasks_images: List[Tuple[str, str]]) -> List[str]`: Process a batch of text tasks and image URLs and return a list of responses.
- `run_batch_async(tasks_images: List[Tuple[str, str]]) -> List[str]`: Process a batch of text tasks and image URLs asynchronously and return a list of responses.
- `run_batch_async_with_retries(tasks_images: List[Tuple[str, str]]) -> List[str]`: Process a batch of text tasks and image URLs asynchronously with retries in case of errors and return a list of responses.
- `unique_chat_history() -> List[str]`: Get the unique chat history stored by the model.
- `run_with_retries(task: str, img: str) -> str`: Run the model with retries in case of an error.
- `run_batch_with_retries(tasks_images: List[Tuple[str, str]]) -> List[str]`: Run a batch of tasks with retries in case of errors and return a list of responses.
- `_tokens_per_second() -> float`: Calculate the tokens generated per second during text generation.
- `_time_for_generation(task: str) -> float`: Measure the time taken for text generation for a specific task.
- `generate_summary(text: str) -> str`: Generate a summary of the provided text.
- `set_temperature(value: float)`: Set the temperature parameter for controlling randomness in text generation.
- `set_max_tokens(value: int)`: Set the maximum number of tokens allowed in generated responses.
- `get_generation_time() -> float`: Get the time taken for text generation for the last task.
- `get_chat_history() -> List[str]`: Get the chat history, including all interactions.
- `get_unique_chat_history() -> List[str]`: Get the unique chat history, removing duplicate interactions.
- `get_chat_history_length() -> int`: Get the length of the chat history.
- `get_unique_chat_history_length() -> int`: Get the length of the unique chat history.
- `get_chat_history_tokens() -> int`: Get the total number of tokens in the chat history.
- `print_beautiful(content: str, color: str = 'cyan')`: Print content beautifully using colored text.
- `stream(content: str)`: Stream the content, printing it character by character.
- `meta_prompt() -> str`: Get the meta prompt that provides guidance for including image labels in responses.
## 5. Usage Examples <a name="usage-examples"></a>
Let's explore some usage examples of the MultiModalAI library:
### Example 1: Running
the Model
```python
# Import the library
from swarms.models import BaseMultiModalModel
# Create an instance of the model
model = BaseMultiModalModel(
model_name="your_model_name",
temperature=0.5,
max_tokens=500,
device="cuda",
)
# Run the model with a text task and an image URL
response = model.run("Generate a summary of this text", "https://www.example.com/image.jpg")
print(response)
```
### Example 2: Running Multiple Tasks Concurrently
```python
# Import the library
from swarms.models import BaseMultiModalModel
# Create an instance of the model
model = BaseMultiModalModel(
model_name="your_model_name",
temperature=0.5,
max_tokens=500,
max_workers=4,
device="cuda",
)
# Define a list of tasks and image URLs
tasks = ["Task 1", "Task 2", "Task 3"]
images = ["https://image1.jpg", "https://image2.jpg", "https://image3.jpg"]
# Run the model on multiple tasks concurrently
responses = model.run_many(tasks, images)
for response in responses:
print(response)
```
### Example 3: Running the Model Asynchronously
```python
# Import the library
from swarms.models import BaseMultiModalModel
# Create an instance of the model
model = BaseMultiModalModel(
model_name="your_model_name",
temperature=0.5,
max_tokens=500,
device="cuda",
)
# Define a list of tasks and image URLs
tasks_images = [
("Task 1", "https://image1.jpg"),
("Task 2", "https://image2.jpg"),
("Task 3", "https://image3.jpg"),
]
# Run the model on multiple tasks asynchronously
responses = model.run_batch_async(tasks_images)
for response in responses:
print(response)
```
### Example 4: Inheriting `BaseMultiModalModel` for it's prebuilt classes
```python
from swarms.models import BaseMultiModalModel
class CustomMultiModalModel(BaseMultiModalModel):
def __init__(self, model_name, custom_parameter, *args, **kwargs):
# Call the parent class constructor
super().__init__(model_name=model_name, *args, **kwargs)
# Initialize custom parameters specific to your model
self.custom_parameter = custom_parameter
def __call__(self, text, img):
# Implement the multimodal model logic here
# You can use self.custom_parameter and other inherited attributes
pass
def generate_summary(self, text):
# Implement the summary generation logic using your model
# You can use self.custom_parameter and other inherited attributes
pass
# Create an instance of your custom multimodal model
custom_model = CustomMultiModalModel(
model_name="your_custom_model_name",
custom_parameter="your_custom_value",
temperature=0.5,
max_tokens=500,
device="cuda",
)
# Run your custom model
response = custom_model.run("Generate a summary of this text", "https://www.example.com/image.jpg")
print(response)
# Generate a summary using your custom model
summary = custom_model.generate_summary("This is a sample text to summarize.")
print(summary)
```
In the code above:
1. We define a `CustomMultiModalModel` class that inherits from `BaseMultiModalModel`.
2. In the constructor of our custom class, we call the parent class constructor using `super()` and initialize any custom parameters specific to our model. In this example, we introduced a `custom_parameter`.
3. We override the `__call__` method, which is responsible for running the multimodal model logic. Here, you can implement the specific behavior of your model, considering both text and image inputs.
4. We override the `generate_summary` method, which is used to generate a summary of text input. You can implement your custom summarization logic here.
5. We create an instance of our custom model, passing the required parameters, including the custom parameter.
6. We demonstrate how to run the custom model and generate a summary using it.
By inheriting from `BaseMultiModalModel`, you can leverage the prebuilt features and methods provided by the library while customizing the behavior of your multimodal model. This allows you to create powerful and specialized models for various multimodal tasks.
These examples demonstrate how to use MultiModalAI to run multimodal models with text and image inputs. You can adjust the parameters and methods to suit your specific use cases.
## 6. Additional Tips <a name="additional-tips"></a>
Here are some additional tips and considerations for using MultiModalAI effectively:
- **Custom Models**: You can create your own multimodal models and inherit from the `BaseMultiModalModel` class to integrate them with this library.
- **Retries**: In cases where text generation might fail due to various reasons (e.g., server issues), using methods with retries can be helpful.
- **Monitoring**: You can monitor the performance of your model using methods like `_tokens_per_second()` and `_time_for_generation()`.
- **Chat History**: The library maintains a chat history, allowing you to keep track of interactions.
- **Streaming**: The `stream()` method can be useful for displaying output character by character, which can be helpful for certain applications.
## 7. References and Resources <a name="references-and-resources"></a>
Here are some references and resources that you may find useful for working with multimodal models:
- [Hugging Face Transformers Library](https://huggingface.co/transformers/): A library for working with various transformer-based models.
- [PIL (Python Imaging Library)](https://pillow.readthedocs.io/en/stable/): Documentation for working with images in Python using the Pillow library.
- [Concurrent Programming in Python](https://docs.python.org/3/library/concurrent.futures.html): Official Python documentation for concurrent programming.
- [Requests Library Documentation](https://docs.python-requests.org/en/latest/): Documentation for the Requests library, which is used for making HTTP requests.
- [Base64 Encoding in Python](https://docs.python.org/3/library/base64.html): Official Python documentation for base64 encoding and decoding.
This concludes the documentation for the MultiModalAI library. You can now explore the library further and integrate it with your multimodal AI projects.

@ -0,0 +1,82 @@
# ElevenLabsText2SpeechTool Documentation
## Table of Contents
1. [Introduction](#introduction)
2. [Class Overview](#class-overview)
- [Attributes](#attributes)
3. [Installation](#installation)
4. [Usage](#usage)
- [Initialization](#initialization)
- [Converting Text to Speech](#converting-text-to-speech)
- [Playing and Streaming Speech](#playing-and-streaming-speech)
5. [Exception Handling](#exception-handling)
6. [Advanced Usage](#advanced-usage)
7. [Contributing](#contributing)
8. [References](#references)
## 1. Introduction <a name="introduction"></a>
The `ElevenLabsText2SpeechTool` is a Python class designed to simplify the process of converting text to speech using the Eleven Labs Text2Speech API. This tool is a wrapper around the API and provides a convenient interface for generating speech from text. It supports multiple languages, making it suitable for a wide range of applications, including voice assistants, audio content generation, and more.
## 2. Class Overview <a name="class-overview"></a>
### Attributes <a name="attributes"></a>
- `model` (Union[ElevenLabsModel, str]): The model to use for text to speech. Defaults to `ElevenLabsModel.MULTI_LINGUAL`.
- `name` (str): The name of the tool. Defaults to `"eleven_labs_text2speech"`.
- `description` (str): A brief description of the tool. Defaults to a detailed explanation of its functionality.
## 3. Installation <a name="installation"></a>
To use the `ElevenLabsText2SpeechTool`, you need to install the required dependencies and have access to the Eleven Labs Text2Speech API. Follow these steps:
1. Install the `elevenlabs` library:
```
pip install elevenlabs
```
2. Install the `swarms` library
`pip install swarms`
3. Set up your API key by following the instructions at [Eleven Labs Documentation](https://docs.elevenlabs.io/welcome/introduction).
## 4. Usage <a name="usage"></a>
### Initialization <a name="initialization"></a>
To get started, create an instance of the `ElevenLabsText2SpeechTool`. You can customize the `model` attribute if needed.
```python
from swarms.models import ElevenLabsText2SpeechTool
stt = ElevenLabsText2SpeechTool(model=ElevenLabsModel.MONO_LINGUAL)
```
### Converting Text to Speech <a name="converting-text-to-speech"></a>
You can use the `run` method to convert text to speech. It returns the path to the generated speech file.
```python
speech_file = stt.run("Hello, this is a test.")
```
### Playing and Streaming Speech <a name="playing-and-streaming-speech"></a>
- Use the `play` method to play the generated speech file.
```python
stt.play(speech_file)
```
- Use the `stream_speech` method to stream the text as speech. It plays the speech in real-time.
```python
stt.stream_speech("Hello world!")
```
## 5. Exception Handling <a name="exception-handling"></a>
The `ElevenLabsText2SpeechTool` handles exceptions gracefully. If an error occurs during the conversion process, it raises a `RuntimeError` with an informative error message.
## 6. Advanced Usage <a name="advanced-usage"></a>
- You can implement custom error handling and logging to further enhance the functionality of this tool.
- For advanced users, extending the class to support additional features or customization is possible.
## 7. Contributing <a name="contributing"></a>
Contributions to this tool are welcome. Feel free to open issues, submit pull requests, or provide feedback to improve its functionality and documentation.
## 8. References <a name="references"></a>
- [Eleven Labs Text2Speech API Documentation](https://docs.elevenlabs.io/welcome/introduction)
This documentation provides a comprehensive guide to using the `ElevenLabsText2SpeechTool`. It covers installation, basic usage, advanced features, and contribution guidelines. Refer to the [References](#references) section for additional resources.

@ -1,251 +1,201 @@
# `GPT4Vision` Documentation # `GPT4VisionAPI` Documentation
## Table of Contents **Table of Contents**
- [Overview](#overview) - [Introduction](#introduction)
- [Installation](#installation) - [Installation](#installation)
- [Initialization](#initialization) - [Module Overview](#module-overview)
- [Methods](#methods) - [Class: GPT4VisionAPI](#class-gpt4visionapi)
- [process_img](#process_img) - [Initialization](#initialization)
- [__call__](#__call__) - [Methods](#methods)
- [encode_image](#encode_image)
- [run](#run) - [run](#run)
- [arun](#arun) - [__call__](#__call__)
- [Configuration Options](#configuration-options) - [Examples](#examples)
- [Usage Examples](#usage-examples) - [Example 1: Basic Usage](#example-1-basic-usage)
- [Additional Tips](#additional-tips) - [Example 2: Custom API Key](#example-2-custom-api-key)
- [References and Resources](#references-and-resources) - [Example 3: Adjusting Maximum Tokens](#example-3-adjusting-maximum-tokens)
- [Additional Information](#additional-information)
--- - [References](#references)
## Overview
The GPT4Vision Model API is designed to provide an easy-to-use interface for interacting with the OpenAI GPT-4 Vision model. This model can generate textual descriptions for images and answer questions related to visual content. Whether you want to describe images or perform other vision-related tasks, GPT4Vision makes it simple and efficient.
The library offers a straightforward way to send images and tasks to the GPT-4 Vision model and retrieve the generated responses. It handles API communication, authentication, and retries, making it a powerful tool for developers working with computer vision and natural language processing tasks.
## Installation
To use the GPT4Vision Model API, you need to install the required dependencies and configure your environment. Follow these steps to get started:
1. Install the required Python package:
```bash
pip3 install --upgrade swarms
```
2. Make sure you have an OpenAI API key. You can obtain one by signing up on the [OpenAI platform](https://beta.openai.com/signup/).
3. Set your OpenAI API key as an environment variable. You can do this in your code or your environment configuration. Alternatively, you can provide the API key directly when initializing the `GPT4Vision` class.
## Initialization ## Introduction<a name="introduction"></a>
To start using the GPT4Vision Model API, you need to create an instance of the `GPT4Vision` class. You can customize its behavior by providing various configuration options, but it also comes with sensible defaults. Welcome to the documentation for the `GPT4VisionAPI` module! This module is a powerful wrapper for the OpenAI GPT-4 Vision model. It allows you to interact with the model to generate descriptions or answers related to images. This documentation will provide you with comprehensive information on how to use this module effectively.
Here's how you can initialize the `GPT4Vision` class: ## Installation<a name="installation"></a>
```python Before you start using the `GPT4VisionAPI` module, make sure you have the required dependencies installed. You can install them using the following commands:
from swarms.models.gpt4v import GPT4Vision
gpt4vision = GPT4Vision( ```bash
api_key="Your Key" pip3 install --upgrade swarms
)
``` ```
The above code initializes the `GPT4Vision` class with default settings. You can adjust these settings as needed. ## Module Overview<a name="module-overview"></a>
## Methods The `GPT4VisionAPI` module serves as a bridge between your application and the OpenAI GPT-4 Vision model. It allows you to send requests to the model and retrieve responses related to images. Here are some key features and functionality provided by this module:
### `process_img` - Encoding images to base64 format.
- Running the GPT-4 Vision model with specified tasks and images.
- Customization options such as setting the OpenAI API key and maximum token limit.
The `process_img` method is used to preprocess an image before sending it to the GPT-4 Vision model. It takes the image path as input and returns the processed image in a format suitable for API requests. ## Class: GPT4VisionAPI<a name="class-gpt4visionapi"></a>
```python The `GPT4VisionAPI` class is the core component of this module. It encapsulates the functionality required to interact with the GPT-4 Vision model. Below, we'll dive into the class in detail.
processed_img = gpt4vision.process_img(img_path)
```
- `img_path` (str): The file path or URL of the image to be processed. ### Initialization<a name="initialization"></a>
### `__call__` When initializing the `GPT4VisionAPI` class, you have the option to provide the OpenAI API key and set the maximum token limit. Here are the parameters and their descriptions:
The `__call__` method is the main method for interacting with the GPT-4 Vision model. It sends the image and tasks to the model and returns the generated response.
```python
response = gpt4vision(img, tasks)
```
- `img` (Union[str, List[str]]): Either a single image URL or a list of image URLs to be used for the API request. | Parameter | Type | Default Value | Description |
- `tasks` (List[str]): A list of tasks or questions related to the image(s). |---------------------|----------|-------------------------------|----------------------------------------------------------------------------------------------------------|
| openai_api_key | str | `OPENAI_API_KEY` environment variable (if available) | The OpenAI API key. If not provided, it defaults to the `OPENAI_API_KEY` environment variable. |
| max_tokens | int | 300 | The maximum number of tokens to generate in the model's response. |
This method returns a `GPT4VisionResponse` object, which contains the generated answer. Here's how you can initialize the `GPT4VisionAPI` class:
### `run` ```python
from swarms.models import GPT4VisionAPI
The `run` method is an alternative way to interact with the GPT-4 Vision model. It takes a single task and image URL as input and returns the generated response. # Initialize with default API key and max_tokens
api = GPT4VisionAPI()
```python # Initialize with custom API key and max_tokens
response = gpt4vision.run(task, img) custom_api_key = "your_custom_api_key"
api = GPT4VisionAPI(openai_api_key=custom_api_key, max_tokens=500)
``` ```
- `task` (str): The task or question related to the image. ### Methods<a name="methods"></a>
- `img` (str): The image URL to be used for the API request.
This method simplifies interactions when dealing with a single task and image.
### `arun` #### encode_image<a name="encode_image"></a>
The `arun` method is an asynchronous version of the `run` method. It allows for asynchronous processing of API requests, which can be useful in certain scenarios. This method allows you to encode an image from a URL to base64 format. It's a utility function used internally by the module.
```python ```python
import asyncio def encode_image(img: str) -> str:
"""
Encode image to base64.
async def main(): Parameters:
response = await gpt4vision.arun(task, img) - img (str): URL of the image to encode.
print(response)
loop = asyncio.get_event_loop() Returns:
loop.run_until_complete(main()) str: Base64 encoded image.
"""
``` ```
- `task` (str): The task or question related to the image. #### run<a name="run"></a>
- `img` (str): The image URL to be used for the API request.
## Configuration Options
The `GPT4Vision` class provides several configuration options that allow you to customize its behavior:
- `max_retries` (int): The maximum number of retries to make to the API. Default: 3 The `run` method is the primary way to interact with the GPT-4 Vision model. It sends a request to the model with a task and an image URL, and it returns the model's response.
- `backoff_factor` (float): The backoff factor to use for exponential backoff. Default: 2.0
- `timeout_seconds` (int): The timeout in seconds for the API request. Default: 10
- `api_key` (str): The API key to use for the API request. Default: None (set via environment variable)
- `quality` (str): The quality of the image to generate. Options: 'low' or 'high'. Default: 'low'
- `max_tokens` (int): The maximum number of tokens to use for the API request. Default: 200
## Usage Examples ```python
def run(task: str, img: str) -> str:
"""
Run the GPT-4 Vision model.
### Example 1: Generating Image Descriptions Parameters:
- task (str): The task or question related to the image.
- img (str): URL of the image to analyze.
```python Returns:
gpt4vision = GPT4Vision() str: The model's response.
img = "https://example.com/image.jpg" """
tasks = ["Describe this image."]
response = gpt4vision(img, tasks)
print(response.answer)
``` ```
In this example, we create an instance of `GPT4Vision`, provide an image URL, and ask the model to describe the image. The response contains the generated description. #### __call__<a name="__call__"></a>
### Example 2: Custom Configuration The `__call__` method is a convenient way to run the GPT-4 Vision model. It has the same functionality as the `run` method.
```python ```python
custom_config = { def __call__(task: str, img: str) -> str:
"max_retries": 5, """
"timeout_seconds": 20, Run the GPT-4 Vision model (callable).
"quality": "high",
"max_tokens": 300,
}
gpt4vision = GPT4Vision(**custom_config)
img = "https://example.com/another_image.jpg"
tasks = ["What objects can you identify in this image?"]
response = gpt4vision(img, tasks)
print(response.answer)
```
In this example, we create an instance of `GPT4Vision` with custom configuration options. We set a higher timeout, request high-quality images, and allow more tokens in the response. Parameters:
- task (str): The task or question related to the image.
- img
### Example 3: Using the `run` Method (str): URL of the image to analyze.
```python Returns:
gpt4vision = GPT4Vision() str: The model's response.
img = "https://example.com/image.jpg" """
task = "Describe this image in detail."
response = gpt4vision.run(task, img)
print(response)
``` ```
In this example, we use the `run` method to simplify the interaction by providing a single task and image URL. ## Examples<a name="examples"></a>
# Model Usage and Image Understanding Let's explore some usage examples of the `GPT4VisionAPI` module to better understand how to use it effectively.
The GPT-4 Vision model processes images in a unique way, allowing it to answer questions about both or each of the images independently. Here's an overview: ### Example 1: Basic Usage<a name="example-1-basic-usage"></a>
| Purpose | Description | In this example, we'll use the module with the default API key and maximum tokens to analyze an image.
| --------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Image Understanding | The model is shown two copies of the same image and can answer questions about both or each of the images independently. |
# Image Detail Control ```python
from swarms.models import GPT4VisionAPI
You have control over how the model processes the image and generates textual understanding by using the `detail` parameter, which has two options: `low` and `high`. # Initialize with default API key and max_tokens
api = GPT4VisionAPI()
| Detail | Description | # Define the task and image URL
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | task = "What is the color of the object?"
| low | Disables the "high-res" model. The model receives a low-res 512 x 512 version of the image and represents the image with a budget of 65 tokens. Ideal for use cases not requiring high detail. | img = "https://i.imgur.com/2M2ZGwC.jpeg"
| high | Enables "high-res" mode. The model first sees the low-res image and then creates detailed crops of input images as 512px squares based on the input image size. Uses a total of 129 tokens. |
# Managing Images # Run the GPT-4 Vision model
response = api.run(task, img)
To use the Chat Completions API effectively, you must manage the images you pass to the model. Here are some key considerations: # Print the model's response
print(response)
```
| Management Aspect | Description | ### Example 2: Custom API Key<a name="example-2-custom-api-key"></a>
| ------------------------- | ------------------------------------------------------------------------------------------------- |
| Image Reuse | To pass the same image multiple times, include the image with each API request. |
| Image Size Optimization | Improve latency by downsizing images to meet the expected size requirements. |
| Image Deletion | After processing, images are deleted from OpenAI servers and not retained. No data is used for training. |
# Limitations If you have a custom API key, you can initialize the module with it as shown in this example.
While GPT-4 with Vision is powerful, it has some limitations: ```python
from swarms.models import GPT4VisionAPI
| Limitation | Description | # Initialize with custom API key and max_tokens
| -------------------------------------------- | --------------------------------------------------------------------------------------------------- | custom_api_key = "your_custom_api_key"
| Medical Images | Not suitable for interpreting specialized medical images like CT scans. | api = GPT4VisionAPI(openai_api_key=custom_api_key, max_tokens=500)
| Non-English Text | May not perform optimally when handling non-Latin alphabets, such as Japanese or Korean. |
| Large Text in Images | Enlarge text within images for readability, but avoid cropping important details. |
| Rotated or Upside-Down Text/Images | May misinterpret rotated or upside-down text or images. |
| Complex Visual Elements | May struggle to understand complex graphs or text with varying colors or styles. |
| Spatial Reasoning | Struggles with tasks requiring precise spatial localization, such as identifying chess positions. |
| Accuracy | May generate incorrect descriptions or captions in certain scenarios. |
| Panoramic and Fisheye Images | Struggles with panoramic and fisheye images. |
# Calculating Costs # Define the task and image URL
task = "What is the object in the image?"
img = "https://i.imgur.com/3T3ZHwD.jpeg"
Image inputs are metered and charged in tokens. The token cost depends on the image size and detail option. # Run the GPT-4 Vision model
response = api.run(task, img)
| Example | Token Cost | # Print the model's response
| --------------------------------------------- | ----------- | print(response)
| 1024 x 1024 square image in detail: high mode | 765 tokens | ```
| 2048 x 4096 image in detail: high mode | 1105 tokens |
| 4096 x 8192 image in detail: low mode | 85 tokens |
# FAQ ### Example 3: Adjusting Maximum Tokens<a name="example-3-adjusting-maximum-tokens"></a>
Here are some frequently asked questions about GPT-4 with Vision: You can also customize the maximum token limit when initializing the module. In this example, we set it to 1000 tokens.
| Question | Answer | ```python
| -------------------------------------------- | -------------------------------------------------------------------------------------------------- | from swarms.models import GPT4VisionAPI
| Fine-Tuning Image Capabilities | No, fine-tuning the image capabilities of GPT-4 is not supported at this time. |
| Generating Images | GPT-4 is used for understanding images, not generating them. |
| Supported Image File Types | Supported image file types include PNG (.png), JPEG (.jpeg and .jpg), WEBP (.webp), and non-animated GIF (.gif). |
| Image Size Limitations | Image uploads are restricted to 20MB per image. |
| Image Deletion | Uploaded images are automatically deleted after processing by the model. |
| Learning More | For more details about GPT-4 with Vision, refer to the GPT-4 with Vision system card. |
| CAPTCHA Submission | CAPTCHAs are blocked for safety reasons. |
| Rate Limits | Image processing counts toward your tokens per minute (TPM) limit. Refer to the calculating costs section for details. |
| Image Metadata | The model does not receive image metadata. |
| Handling Unclear Images | If an image is unclear, the model will do its best to interpret it, but results may be less accurate. |
# Initialize with default API key and custom max_tokens
api = GPT4VisionAPI(max_tokens=1000)
# Define the task and image URL
task = "Describe the scene in the image."
img = "https://i.imgur.com/4P4ZRxU.jpeg"
## Additional Tips # Run the GPT-4 Vision model
response = api.run(task, img)
- Make sure to handle potential exceptions and errors when making API requests. The library includes retries and error handling, but it's essential to handle exceptions gracefully in your code. # Print the model's response
- Experiment with different configuration options to optimize the trade-off between response quality and response time based on your specific requirements. print(response)
```
## References and Resources ## Additional Information<a name="additional-information"></a>
- [OpenAI Platform](https://beta.openai.com/signup/): Sign up for an OpenAI API key. - If you encounter any errors or issues with the module, make sure to check your API key and internet connectivity.
- [OpenAI API Documentation](https://platform.openai.com/docs/api-reference/chat/create): Official API documentation for the GPT-4 Vision model. - It's recommended to handle exceptions when using the module to gracefully handle errors.
- You can further customize the module to fit your specific use case by modifying the code as needed.
Now you have a comprehensive understanding of the GPT4Vision Model API, its configuration options, and how to use it for various computer vision and natural language processing tasks. Start experimenting and integrating it into your projects to leverage the power of GPT-4 Vision for image-related tasks. ## References<a name="references"></a>
# Conclusion - [OpenAI API Documentation](https://beta.openai.com/docs/)
With GPT-4 Vision, you have a powerful tool for understanding and generating textual descriptions for images. By considering its capabilities, limitations, and cost calculations, you can effectively leverage this model for various image-related tasks. This documentation provides a comprehensive guide on how to use the `GPT4VisionAPI` module effectively. It covers initialization, methods, usage examples, and additional information to ensure a smooth experience when working with the GPT-4 Vision model.

@ -96,7 +96,7 @@ Here are three ways to use the `HuggingfaceLLM` class:
from swarms.models import HuggingfaceLLM from swarms.models import HuggingfaceLLM
# Initialize the HuggingfaceLLM instance with a model ID # Initialize the HuggingfaceLLM instance with a model ID
model_id = "gpt2-small" model_id = "NousResearch/Nous-Hermes-2-Vision-Alpha"
inference = HuggingfaceLLM(model_id=model_id) inference = HuggingfaceLLM(model_id=model_id)
# Generate text based on a prompt # Generate text based on a prompt
@ -116,7 +116,7 @@ custom_config = {
"quantization_config": {"load_in_4bit": True}, "quantization_config": {"load_in_4bit": True},
"verbose": True "verbose": True
} }
inference = HuggingfaceLLM(model_id="gpt2-small", **custom_config) inference = HuggingfaceLLM(model_id="NousResearch/Nous-Hermes-2-Vision-Alpha", **custom_config)
# Generate text based on a prompt # Generate text based on a prompt
prompt_text = "Tell me a joke" prompt_text = "Tell me a joke"

@ -0,0 +1,157 @@
# `vLLM` Documentation
## Table of Contents
- [Overview](#overview)
- [Installation](#installation)
- [vLLM Class](#vllm-class)
- [Initialization](#initialization)
- [Methods](#methods)
- [run](#run)
- [Usage Examples](#usage-examples)
- [Common Issues and Troubleshooting](#common-issues-and-troubleshooting)
- [References and Resources](#references-and-resources)
---
### Overview <a name="overview"></a>
Welcome to the documentation for the vLLM (Variable-Length Language Model) library. vLLM is a powerful tool for generating text using pre-trained language models. This documentation will provide a comprehensive guide on how to use vLLM effectively.
#### Purpose
vLLM is designed to simplify the process of generating text using language models, specifically the Facebook `opt-13b` model. It allows you to fine-tune various parameters to achieve the desired text generation outcomes.
#### Key Features
- Seamless integration with the Facebook `opt-13b` language model.
- Flexible configuration options for model parameters.
- Support for generating text for various natural language processing tasks.
### Installation <a name="installation"></a>
Before using vLLM, you need to install swarms. You can install vLLM using `pip`:
```bash
pip install swarms
```
### vLLM Class <a name="vllm-class"></a>
The vLLM class is the core component of the vLLM library. It provides a high-level interface for generating text using the Facebook `opt-13b` language model.
#### Initialization <a name="initialization"></a>
To initialize the vLLM class, you can use the following parameters:
- `model_name` (str, optional): The name of the language model to use. Defaults to "facebook/opt-13b".
- `tensor_parallel_size` (int, optional): The size of the tensor parallelism. Defaults to 4.
- `trust_remote_code` (bool, optional): Whether to trust remote code. Defaults to False.
- `revision` (str, optional): The revision of the language model. Defaults to None.
- `temperature` (float, optional): The temperature parameter for text generation. Defaults to 0.5.
- `top_p` (float, optional): The top-p parameter for text generation. Defaults to 0.95.
```python
from swarms.models import vLLM
# Initialize vLLM with default parameters
vllm = vLLM()
# Initialize vLLM with custom parameters
custom_vllm = vLLM(
model_name="custom/model",
tensor_parallel_size=8,
trust_remote_code=True,
revision="abc123",
temperature=0.7,
top_p=0.8
)
```
#### Methods <a name="methods"></a>
##### run <a name="run"></a>
The `run` method is used to generate text using the vLLM model. It takes a `task` parameter, which is a text prompt or description of the task you want the model to perform. It returns the generated text as a string.
```python
# Generate text using vLLM
result = vllm.run("Generate a creative story about a dragon.")
print(result)
```
### Usage Examples <a name="usage-examples"></a>
Here are three usage examples demonstrating different ways to use vLLM:
**Example 1: Basic Text Generation**
```python
from swarms.models import vLLM
# Initialize vLLM
vllm = vLLM()
# Generate text for a given task
generated_text = vllm.run("Generate a summary of a scientific paper.")
print(generated_text)
```
**Example 2: Custom Model and Parameters**
```python
from swarms.models import vLLM
# Initialize vLLM with custom model and parameters
custom_vllm = vLLM(
model_name="custom/model",
tensor_parallel_size=8,
trust_remote_code=True,
revision="abc123",
temperature=0.7,
top_p=0.8
)
# Generate text with custom configuration
generated_text = custom_vllm.run("Create a poem about nature.")
print(generated_text)
```
**Example 3: Batch Processing**
```python
from swarms.models import vLLM
# Initialize vLLM
vllm = vLLM()
# Generate multiple texts in batch
tasks = [
"Translate the following sentence to French: 'Hello, world!'",
"Write a short story set in a futuristic world.",
"Summarize the main points of a news article about climate change."
]
for task in tasks:
generated_text = vllm.run(task)
print(generated_text)
```
### Common Issues and Troubleshooting <a name="common-issues-and-troubleshooting"></a>
- **ImportError**: If you encounter an `ImportError` related to vLLM, make sure you have installed it using `pip install vllm`.
- **Model Configuration**: Ensure that you provide valid model names and configurations when initializing vLLM. Invalid model names or parameters can lead to errors.
- **Text Generation**: Be cautious with text generation parameters like `temperature` and `top_p`. Experiment with different values to achieve the desired text quality.
### References and Resources <a name="references-and-resources"></a>
For more information and resources related to vLLM and language models, refer to the following:
- [vLLM GitHub Repository](https://github.com/vllm/vllm)
- [Hugging Face Transformers Documentation](https://huggingface.co/transformers/)
- [Facebook `opt-13b` Model Documentation](https://huggingface.co/facebook/opt-13b)
---
This concludes the documentation for the vLLM library. We hope this guide helps you effectively use vLLM for text generation tasks. If you have any questions or encounter issues, please refer to the troubleshooting section or seek assistance from the vLLM community. Happy text generation!

@ -0,0 +1,157 @@
# `Agent` Documentation
## Overview
The `Agent` class is a Python module designed to facilitate interactions with a language model, particularly one that operates as an autonomous agent. This class is part of a larger framework aimed at creating conversational agents using advanced language models like GPT-3. It enables you to establish a conversational loop with the model, generate responses, collect feedback, and control the agent of the conversation.
In this documentation, you will learn how to use the `Agent` class effectively, its purpose, and how it can be integrated into your projects.
## Purpose
The `Agent` class serves several key purposes:
1. **Conversational Loop**: It establishes a conversational loop with a language model. This means it allows you to interact with the model in a back-and-forth manner, taking turns in the conversation.
2. **Feedback Collection**: The class allows users to provide feedback on the responses generated by the model. This feedback can be valuable for training and improving the model's responses over time.
3. **Stoppable Conversation**: You can define custom stopping conditions for the conversation, allowing you to stop the interaction based on specific criteria. For example, you can stop the conversation if a certain keyword is detected in the responses.
4. **Retry Mechanism**: The class includes a retry mechanism that can be helpful if there are issues generating responses from the model. It attempts to generate a response multiple times before raising an error.
## Class Definition
The `Agent` class has the following constructor:
```python
class Agent:
def __init__(
self,
llm: Any,
max_loops: int = 5,
stopping_condition: Optional[Callable[[str], bool]] = None,
loop_interval: int = 1,
retry_attempts: int = 3,
retry_interval: int = 1,
interactive: bool = False,
**kwargs: Any,
):
```
### Parameters
- `llm` (Any): The language model with which you want to interact.
- `max_loops` (int): The maximum number of conversation loops. Default is 5.
- `stopping_condition` (Optional[Callable[[str], bool]]): A custom stopping condition function. Default is `None`.
- `loop_interval` (int): The time interval (in seconds) between conversation loops. Default is 1 second.
- `retry_attempts` (int): The number of retry attempts if response generation fails. Default is 3.
- `retry_interval` (int): The time interval (in seconds) between retry attempts. Default is 1 second.
- `interactive` (bool): Set to `True` if the conversation is interactive, meaning the user is involved. Default is `False`.
## Usage
The `Agent` class can be used to create a conversational loop with the language model. Here's how you can use it:
```python
from swarms.structs import Agent
agent = Agent(llm=my_language_model, max_loops=5)
# Define a starting task or message
initial_task = "Generate a 10,000 word blog on health and wellness."
# Run the conversation loop
final_response = agent.run(initial_task)
```
### Feedback
You can collect feedback during the conversation using the `provide_feedback` method:
```python
agent.provide_feedback("Generate an SOP for new sales employees on the best cold sales practices")
```
### Stopping Condition
You can define a custom stopping condition using a function. For example, you can stop the conversation if the response contains the word "Stop":
```python
from swarms.structs import Agent
def stop_when_repeats(response: str) -> bool:
return "Stop" in response.lower()
agent = Agent(llm=my_language_model, max_loops=5, stopping_condition=stop_when_repeats)
```
### Retry Mechanism
If the response generation fails, the class will retry up to the specified number of attempts:
```python
agent = Agent(llm=my_language_model, max_loops=5, retry_attempts=3)
```
## Additional Information
- To save the conversation history to a file, you can use the `save` method.
- To load a previously saved conversation history, you can use the `load` method.
- The class includes methods for bulk running conversations with multiple input sets.
## Examples
Here are three usage examples:
### Example 1: Simple Conversation
```python
from swarms.structs import Agent
# Select any Language model from the models folder
from swarms.models import Mistral, OpenAIChat
llm = Mistral()
# llm = OpenAIChat()
agent = Agent(llm=llm, max_loops=5)
# Define a starting task or message
initial_task = "Generate an long form analysis on the transformer model architecture."
# Run the conversation loop
final_response = agent.run(initial_task)
```
### Example 2: Custom Stopping Condition
```python
from swarms.structs import Agent
def stop_when_repeats(response: str) -> bool:
return "Stop" in response.lower()
agent = Agent(llm=llm, max_loops=5, stopping_condition=stop_when_repeats)
```
### Example 3: Interactive Conversation
```python
from swarms.structs import Agent
agent = Agent(llm=llm, max_loops=5, interactive=True)
# Provide initial task
initial_task = "Rank and prioritize the following financial documents and cut out 30% of our expenses"
# Run the conversation loop
final_response = agent.run(initial_task)
```
## References and Resources
- [GitHub Repository](https://github.com/kyegomez/swarms)
## Conclusion
The `Agent` class provides a powerful way to interact with language models in a conversational manner. By defining custom stopping conditions, collecting feedback, and controlling the agent of the conversation, you can create engaging and interactive applications that make use of advanced language models.

@ -22,9 +22,9 @@ Before delving into the details of the **SequentialWorkflow** class, let's defin
A **task** refers to a specific unit of work that needs to be executed as part of the workflow. Each task is associated with a description and can be implemented as a callable object, such as a function or a model. A **task** refers to a specific unit of work that needs to be executed as part of the workflow. Each task is associated with a description and can be implemented as a callable object, such as a function or a model.
### Flow ### Agent
A **flow** represents a callable object that can be a task within the **SequentialWorkflow**. Flows encapsulate the logic and functionality of a particular task. Flows can be functions, models, or any callable object that can be executed. A **agent** represents a callable object that can be a task within the **SequentialWorkflow**. Agents encapsulate the logic and functionality of a particular task. Agents can be functions, models, or any callable object that can be executed.
### Sequential Execution ### Sequential Execution
@ -70,7 +70,7 @@ The **SequentialWorkflow** class is versatile and can be employed in a wide rang
2. **Workflow Creation**: Create an instance of the **SequentialWorkflow** class. Specify the maximum number of loops the workflow should run and whether a dashboard should be displayed. 2. **Workflow Creation**: Create an instance of the **SequentialWorkflow** class. Specify the maximum number of loops the workflow should run and whether a dashboard should be displayed.
3. **Task Addition**: Add tasks to the workflow using the `add` method. Each task should be described using a human-readable description, and the associated flow (callable object) should be provided. Additional arguments and keyword arguments can be passed to the task. 3. **Task Addition**: Add tasks to the workflow using the `add` method. Each task should be described using a human-readable description, and the associated agent (callable object) should be provided. Additional arguments and keyword arguments can be passed to the task.
4. **Task Execution**: Execute the workflow using the `run` method. The tasks within the workflow will be executed sequentially, with task results passed as inputs to subsequent tasks. 4. **Task Execution**: Execute the workflow using the `run` method. The tasks within the workflow will be executed sequentially, with task results passed as inputs to subsequent tasks.
@ -93,10 +93,10 @@ Let's begin with a quick example to demonstrate how to create and run a Sequenti
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Initialize the language model flow (e.g., GPT-3) # Initialize the language model agent (e.g., GPT-3)
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key="YOUR_API_KEY", openai_api_key="YOUR_API_KEY",
temperature=0.5, temperature=0.5,
@ -104,8 +104,8 @@ llm = OpenAIChat(
) )
# Initialize flows for individual tasks # Initialize flows for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -134,13 +134,13 @@ The `Task` class represents an individual task in the workflow. A task is essent
```python ```python
class Task: class Task:
def __init__(self, description: str, flow: Union[Callable, Flow], args: List[Any] = [], kwargs: Dict[str, Any] = {}, result: Any = None, history: List[Any] = []) def __init__(self, description: str, agent: Union[Callable, Agent], args: List[Any] = [], kwargs: Dict[str, Any] = {}, result: Any = None, history: List[Any] = [])
``` ```
### Parameters ### Parameters
- `description` (str): A description of the task. - `description` (str): A description of the task.
- `flow` (Union[Callable, Flow]): The callable object representing the task. It can be a function, class, or a `Flow` instance. - `agent` (Union[Callable, Agent]): The callable object representing the task. It can be a function, class, or a `Agent` instance.
- `args` (List[Any]): A list of positional arguments to pass to the task when executed. Default is an empty list. - `args` (List[Any]): A list of positional arguments to pass to the task when executed. Default is an empty list.
- `kwargs` (Dict[str, Any]): A dictionary of keyword arguments to pass to the task when executed. Default is an empty dictionary. - `kwargs` (Dict[str, Any]): A dictionary of keyword arguments to pass to the task when executed. Default is an empty dictionary.
- `result` (Any): The result of the task's execution. Default is `None`. - `result` (Any): The result of the task's execution. Default is `None`.
@ -156,7 +156,7 @@ Execute the task.
def execute(self): def execute(self):
``` ```
This method executes the task and updates the `result` and `history` attributes of the task. It checks if the task is a `Flow` instance and if the 'task' argument is needed. This method executes the task and updates the `result` and `history` attributes of the task. It checks if the task is a `Agent` instance and if the 'task' argument is needed.
## Class: `SequentialWorkflow` ## Class: `SequentialWorkflow`
@ -182,15 +182,15 @@ class SequentialWorkflow:
### Methods ### Methods
#### `add(task: str, flow: Union[Callable, Flow], *args, **kwargs)` #### `add(task: str, agent: Union[Callable, Agent], *args, **kwargs)`
Add a task to the workflow. Add a task to the workflow.
```python ```python
def add(self, task: str, flow: Union[Callable, Flow], *args, **kwargs) -> None: def add(self, task: str, agent: Union[Callable, Agent], *args, **kwargs) -> None:
``` ```
This method adds a new task to the workflow. You can provide a description of the task, the callable object (function, class, or `Flow` instance), and any additional positional or keyword arguments required for the task. This method adds a new task to the workflow. You can provide a description of the task, the callable object (function, class, or `Agent` instance), and any additional positional or keyword arguments required for the task.
#### `reset_workflow()` #### `reset_workflow()`
@ -262,7 +262,7 @@ Run the workflow sequentially.
def run(self) -> None: def run(self) -> None:
``` ```
This method executes the tasks in the workflow sequentially. It checks if a task is a `Flow` instance and handles the flow of data between tasks accordingly. This method executes the tasks in the workflow sequentially. It checks if a task is a `Agent` instance and handles the agent of data between tasks accordingly.
#### `arun()` #### `arun()`
@ -272,7 +272,7 @@ Asynchronously run the workflow.
async def arun(self) -> None: async def arun(self) -> None:
``` ```
This method asynchronously executes the tasks in the workflow sequentially. It's suitable for use cases where asynchronous execution is required. It also handles data flow between tasks. This method asynchronously executes the tasks in the workflow sequentially. It's suitable for use cases where asynchronous execution is required. It also handles data agent between tasks.
#### `workflow_bootup(**kwargs)` #### `workflow_bootup(**kwargs)`
@ -306,7 +306,7 @@ In this example, we'll create a Sequential Workflow and add tasks to it.
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -314,16 +314,16 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -346,7 +346,7 @@ In this example, we'll create a Sequential Workflow, add tasks to it, and then r
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -354,16 +354,16 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -389,7 +389,7 @@ In this example, we'll create a Sequential Workflow, add tasks to it, run the wo
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -397,16 +397,16 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -432,7 +432,7 @@ In this example, we'll create a Sequential Workflow, add tasks to it, and then r
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -440,16 +440,16 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -475,7 +475,7 @@ In this example, we'll create a Sequential Workflow, add tasks to it, and then u
```python ```python
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
from swarms.structs.sequential_workflow import SequentialWorkflow from swarms.structs.sequential_workflow import SequentialWorkflow
# Example usage # Example usage
@ -483,16 +483,16 @@ api_key = (
"" # Your actual API key here "" # Your actual API key here
) )
# Initialize the language flow # Initialize the language agent
llm = OpenAIChat( llm = OpenAIChat(
openai_api_key=api_key, openai_api_key=api_key,
temperature=0.5, temperature=0.5,
max_tokens=3000, max_tokens=3000,
) )
# Initialize Flows for individual tasks # Initialize Agents for individual tasks
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) flow1 = Agent(llm=llm, max_loops=1, dashboard=False)
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) flow2 = Agent(llm=llm, max_loops=1, dashboard=False)
# Create the Sequential Workflow # Create the Sequential Workflow
workflow = SequentialWorkflow(max_loops=1) workflow = SequentialWorkflow(max_loops=1)
@ -579,11 +579,11 @@ In summary, the Sequential Workflow module provides a foundation for orchestrati
## Frequently Asked Questions (FAQs) ## Frequently Asked Questions (FAQs)
### Q1: What is the difference between a task and a flow in Sequential Workflows? ### Q1: What is the difference between a task and a agent in Sequential Workflows?
**A1:** In Sequential Workflows, a **task** refers to a specific unit of work that needs to be executed. It can be implemented as a callable object, such as a Python function, and is the fundamental building block of a workflow. **A1:** In Sequential Workflows, a **task** refers to a specific unit of work that needs to be executed. It can be implemented as a callable object, such as a Python function, and is the fundamental building block of a workflow.
A **flow**, on the other hand, is an encapsulation of a task within the workflow. Flows define the order in which tasks are executed and can be thought of as task containers. They allow you to specify dependencies, error handling, and other workflow-related configurations. A **agent**, on the other hand, is an encapsulation of a task within the workflow. Agents define the order in which tasks are executed and can be thought of as task containers. They allow you to specify dependencies, error handling, and other workflow-related configurations.
### Q2: Can I run tasks in parallel within a Sequential Workflow? ### Q2: Can I run tasks in parallel within a Sequential Workflow?

@ -4,7 +4,7 @@
## Overview ## Overview
The Swarms framework is a Python library designed to facilitate the creation and management of a simulated group chat environment. This environment can be used for a variety of purposes, such as training conversational agents, role-playing games, or simulating dialogues for machine learning purposes. The core functionality revolves around managing the flow of messages between different agents within the chat, as well as handling the selection and responses of these agents based on the conversation's context. The Swarms framework is a Python library designed to facilitate the creation and management of a simulated group chat environment. This environment can be used for a variety of purposes, such as training conversational agents, role-playing games, or simulating dialogues for machine learning purposes. The core functionality revolves around managing the agent of messages between different agents within the chat, as well as handling the selection and responses of these agents based on the conversation's context.
### Purpose ### Purpose
@ -13,7 +13,7 @@ The purpose of the Swarms framework, and specifically the `GroupChat` and `Group
### Key Features ### Key Features
- **Agent Interaction**: Allows multiple agents to communicate within a group chat scenario. - **Agent Interaction**: Allows multiple agents to communicate within a group chat scenario.
- **Message Management**: Handles the storage and flow of messages within the group chat. - **Message Management**: Handles the storage and agent of messages within the group chat.
- **Role Play**: Enables agents to assume specific roles and interact accordingly. - **Role Play**: Enables agents to assume specific roles and interact accordingly.
- **Conversation Context**: Maintains the context of the conversation for appropriate responses by agents. - **Conversation Context**: Maintains the context of the conversation for appropriate responses by agents.
@ -29,7 +29,7 @@ The `GroupChat` class is the backbone of the Swarms framework's chat simulation.
| Parameter | Type | Description | Default Value | | Parameter | Type | Description | Default Value |
|------------|---------------------|--------------------------------------------------------------|---------------| |------------|---------------------|--------------------------------------------------------------|---------------|
| agents | List[Flow] | List of agent flows participating in the group chat. | None | | agents | List[Agent] | List of agent flows participating in the group chat. | None |
| messages | List[Dict] | List of message dictionaries exchanged in the group chat. | None | | messages | List[Dict] | List of message dictionaries exchanged in the group chat. | None |
| max_round | int | Maximum number of rounds/messages allowed in the group chat. | 10 | | max_round | int | Maximum number of rounds/messages allowed in the group chat. | 10 |
| admin_name | str | The name of the admin agent in the group chat. | "Admin" | | admin_name | str | The name of the admin agent in the group chat. | "Admin" |
@ -38,10 +38,10 @@ The `GroupChat` class is the backbone of the Swarms framework's chat simulation.
- `agent_names`: Returns a list of the names of the agents in the group chat. - `agent_names`: Returns a list of the names of the agents in the group chat.
- `reset()`: Clears all messages from the group chat. - `reset()`: Clears all messages from the group chat.
- `agent_by_name(name: str) -> Flow`: Finds and returns an agent by name. - `agent_by_name(name: str) -> Agent`: Finds and returns an agent by name.
- `next_agent(agent: Flow) -> Flow`: Returns the next agent in the list. - `next_agent(agent: Agent) -> Agent`: Returns the next agent in the list.
- `select_speaker_msg() -> str`: Returns the message for selecting the next speaker. - `select_speaker_msg() -> str`: Returns the message for selecting the next speaker.
- `select_speaker(last_speaker: Flow, selector: Flow) -> Flow`: Logic to select the next speaker based on the last speaker and the selector agent. - `select_speaker(last_speaker: Agent, selector: Agent) -> Agent`: Logic to select the next speaker based on the last speaker and the selector agent.
- `_participant_roles() -> str`: Returns a string listing all participant roles. - `_participant_roles() -> str`: Returns a string listing all participant roles.
- `format_history(messages: List[Dict]) -> str`: Formats the history of messages for display or processing. - `format_history(messages: List[Dict]) -> str`: Formats the history of messages for display or processing.
@ -50,10 +50,10 @@ The `GroupChat` class is the backbone of the Swarms framework's chat simulation.
#### Example 1: Initializing a GroupChat #### Example 1: Initializing a GroupChat
```python ```python
from swarms.structs.flow import Flow from swarms.structs.agent import Agent
from swarms.groupchat import GroupChat from swarms.groupchat import GroupChat
# Assuming Flow objects (flow1, flow2, flow3) are initialized and configured # Assuming Agent objects (flow1, flow2, flow3) are initialized and configured
agents = [flow1, flow2, flow3] agents = [flow1, flow2, flow3]
group_chat = GroupChat(agents=agents, messages=[], max_round=10) group_chat = GroupChat(agents=agents, messages=[], max_round=10)
``` ```
@ -67,8 +67,8 @@ group_chat.reset()
#### Example 3: Selecting a Speaker #### Example 3: Selecting a Speaker
```python ```python
last_speaker = agents[0] # Assuming this is a Flow object representing the last speaker last_speaker = agents[0] # Assuming this is a Agent object representing the last speaker
selector = agents[1] # Assuming this is a Flow object with the selector role selector = agents[1] # Assuming this is a Agent object with the selector role
next_speaker = group_chat.select_speaker(last_speaker, selector) next_speaker = group_chat.select_speaker(last_speaker, selector)
``` ```
@ -86,7 +86,7 @@ The `GroupChatManager` class acts as a controller for the `GroupChat` instance.
| Parameter | Type | Description | | Parameter | Type | Description |
|------------|-------------|------------------------------------------------------| |------------|-------------|------------------------------------------------------|
| groupchat | GroupChat | The GroupChat instance that the manager will handle. | | groupchat | GroupChat | The GroupChat instance that the manager will handle. |
| selector | Flow | The Flow object that selects the next speaker. | | selector | Agent | The Agent object that selects the next speaker. |
#### Methods #### Methods
@ -98,7 +98,7 @@ The `GroupChatManager` class acts as a controller for the `GroupChat` instance.
```python ```python
from swarms.groupchat import GroupChat, GroupChatManager from swarms.groupchat import GroupChat, GroupChatManager
from swarms.structs.flow import Flow from swarms.structs.agent import Agent
# Initialize your agents and group chat as shown in previous examples # Initialize your agents and group chat as shown in previous examples
chat_manager = GroupChatManager(groupchat=group_chat, selector=manager) chat_manager = GroupChatManager(groupchat=group_chat, selector=manager)
@ -132,7 +132,7 @@ By leveraging the framework's features, users can create complex interaction sce
**Q: Can the Swarms framework handle real-time interactions between agents?** **Q: Can the Swarms framework handle real-time interactions between agents?**
A: The Swarms framework is designed to simulate group chat environments. While it does not handle real-time interactions as they would occur on a network, it can simulate the flow of conversation in a way that mimics real-time communication. A: The Swarms framework is designed to simulate group chat environments. While it does not handle real-time interactions as they would occur on a network, it can simulate the agent of conversation in a way that mimics real-time communication.
**Q: Is the Swarms framework capable of natural language processing?** **Q: Is the Swarms framework capable of natural language processing?**
@ -152,7 +152,7 @@ A: The framework is can be integrated with any chat services. However, it could
**Q: How does the `GroupChatManager` select the next speaker?** **Q: How does the `GroupChatManager` select the next speaker?**
A: The `GroupChatManager` uses a selection mechanism, which is typically based on the conversation's context and the roles of the agents, to determine the next speaker. The specifics of this mechanism can be customized to match the desired flow of the conversation. A: The `GroupChatManager` uses a selection mechanism, which is typically based on the conversation's context and the roles of the agents, to determine the next speaker. The specifics of this mechanism can be customized to match the desired agent of the conversation.
**Q: Can I contribute to the Swarms framework or suggest features?** **Q: Can I contribute to the Swarms framework or suggest features?**

@ -0,0 +1,128 @@
# Phoenix Trace Decorator Documentation
## Introduction
Welcome to the documentation for the `phoenix_trace_decorator` module. This module provides a convenient decorator for tracing Python functions and capturing exceptions using Phoenix, a versatile tracing and monitoring tool. Phoenix allows you to gain insights into the execution of your code, capture errors, and monitor performance.
## Table of Contents
1. [Installation](#installation)
2. [Getting Started](#getting-started)
3. [Decorator Usage](#decorator-usage)
4. [Examples](#examples)
5. [Best Practices](#best-practices)
6. [References](#references)
## 1. Installation <a name="installation"></a>
Before using the `phoenix_trace_decorator`, you need to install the Swarms library. You can install Phoenix using pip:
```bash
pip install swarms
```
## 2. Getting Started <a name="getting-started"></a>
Phoenix is a powerful tracing and monitoring tool, and the `phoenix_trace_decorator` simplifies the process of tracing functions and capturing exceptions within your Python code. To begin, ensure that Phoenix is installed, and then import the `phoenix_trace_decorator` module into your Python script.
```python
from swarms import phoenix_trace_decorator
```
## 3. Decorator Usage <a name="decorator-usage"></a>
The `phoenix_trace_decorator` module provides a decorator, `phoenix_trace_decorator`, which can be applied to functions you want to trace. The decorator takes a single argument, a docstring that describes the purpose of the function being traced.
Here is the basic structure of using the decorator:
```python
@phoenix_trace_decorator("Description of the function")
def my_function(param1, param2):
# Function implementation
pass
```
## 4. Examples <a name="examples"></a>
Let's explore some practical examples of using the `phoenix_trace_decorator` in your code.
### Example 1: Basic Tracing
In this example, we'll trace a simple function and print a message.
```python
@phoenix_trace_decorator("Tracing a basic function")
def hello_world():
print("Hello, World!")
# Call the decorated function
hello_world()
```
### Example 2: Tracing a Function with Parameters
You can use the decorator with functions that have parameters.
```python
@phoenix_trace_decorator("Tracing a function with parameters")
def add_numbers(a, b):
result = a + b
print(f"Result: {result}")
# Call the decorated function with parameters
add_numbers(2, 3)
```
### Example 3: Tracing Nested Calls
The decorator can also trace nested function calls.
```python
@phoenix_trace_decorator("Outer function")
def outer_function():
print("Outer function")
@phoenix_trace_decorator("Inner function")
def inner_function():
print("Inner function")
inner_function()
# Call the decorated functions
outer_function()
```
### Example 4: Exception Handling
Phoenix can capture exceptions and provide detailed information about them.
```python
@phoenix_trace_decorator("Function with exception handling")
def divide(a, b):
try:
result = a / b
except ZeroDivisionError as e:
raise ValueError("Division by zero") from e
# Call the decorated function with an exception
try:
divide(5, 0)
except ValueError as e:
print(f"Error: {e}")
```
## 5. Best Practices <a name="best-practices"></a>
When using the `phoenix_trace_decorator`, consider the following best practices:
- Use meaningful docstrings to describe the purpose of the traced functions.
- Keep your tracing focused on critical parts of your code.
- Make sure Phoenix is properly configured and running before using the decorator.
## 6. References <a name="references"></a>
For more information on Phoenix and advanced usage, please refer to the [Phoenix Documentation](https://phoenix-docs.readthedocs.io/en/latest/).
---
By following this documentation, you can effectively use the `phoenix_trace_decorator` to trace your Python functions, capture exceptions, and gain insights into the execution of your code. This tool is valuable for debugging, performance optimization, and monitoring the health of your applications.

@ -1,37 +1,34 @@
import os
from dotenv import load_dotenv
# Import the OpenAIChat model and the Agent struct
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from swarms.structs import Flow from swarms.structs import Agent
# Load the environment variables
load_dotenv()
# Initialize the language model, this model can be swapped out with Anthropic, ETC, Huggingface Models like Mistral, ETC # Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat( llm = OpenAIChat(
# model_name="gpt-4"
# openai_api_key=api_key,
temperature=0.5, temperature=0.5,
# max_tokens=100, model_name="gpt-4",
openai_api_key=api_key,
max_tokens=1000,
) )
## Initialize the workflow ## Initialize the workflow
flow = Flow( agent = Agent(
llm=llm, llm=llm,
max_loops=2, max_loops=1,
autosave=True,
dashboard=True, dashboard=True,
# tools=[search_api]
# stopping_condition=None, # You can define a stopping condition as needed.
# loop_interval=1,
# retry_attempts=3,
# retry_interval=1,
# interactive=False, # Set to 'True' for interactive mode.
# dynamic_temperature=False, # Set to 'True' for dynamic temperature handling.
) )
# out = flow.load_state("flow_state.json") # Run the workflow on a task
# temp = flow.dynamic_temperature() out = agent.run("Generate a 10,000 word blog on health and wellness.")
# filter = flow.add_response_filter("Trump") print(out)
out = flow.run(
"Generate a 10,000 word blog on mental clarity and the benefits of meditation."
)
# out = flow.validate_response(out)
# out = flow.analyze_feedback(out)
# out = flow.print_history_and_memory()
# # out = flow.save_state("flow_state.json")
# print(out)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -6,9 +6,6 @@ copyright: "&copy; APAC Corp, Inc."
extra_css: extra_css:
- docs/assets/css/extra.css - docs/assets/css/extra.css
extra: extra:
# analytics:
# provider: google
# property: G-QM8EDPSCB6
social: social:
- icon: fontawesome/solid/house - icon: fontawesome/solid/house
link: assets/img/SwarmsLogoIcon.png link: assets/img/SwarmsLogoIcon.png
@ -66,7 +63,6 @@ nav:
- Overview: "swarms/index.md" - Overview: "swarms/index.md"
- swarms.swarms: - swarms.swarms:
- AbstractSwarm: "swarms/swarms/abstractswarm.md" - AbstractSwarm: "swarms/swarms/abstractswarm.md"
- AutoScaler: "swarms/swarms/autoscaler.md"
- GodMode: "swarms/swarms/godmode.md" - GodMode: "swarms/swarms/godmode.md"
- Groupchat: "swarms/swarms/groupchat.md" - Groupchat: "swarms/swarms/groupchat.md"
- swarms.workers: - swarms.workers:
@ -77,15 +73,18 @@ nav:
- OmniModalAgent: "swarms/agents/omni_agent.md" - OmniModalAgent: "swarms/agents/omni_agent.md"
- swarms.models: - swarms.models:
- Language: - Language:
- BaseLLM: "swarms/models/base_llm.md"
- Overview: "swarms/models/index.md" - Overview: "swarms/models/index.md"
- HuggingFaceLLM: "swarms/models/huggingface.md" - HuggingFaceLLM: "swarms/models/huggingface.md"
- Anthropic: "swarms/models/anthropic.md" - Anthropic: "swarms/models/anthropic.md"
- OpenAI: "swarms/models/openai.md" - OpenAI: "swarms/models/openai.md"
- Zephyr: "swarms/models/zephyr.md" - Zephyr: "swarms/models/zephyr.md"
- BioGPT: "swarms/models/biogpt.md" - BioGPT: "swarms/models/biogpt.md"
- vLLM: "swarms/models/vllm.md"
- MPT7B: "swarms/models/mpt.md" - MPT7B: "swarms/models/mpt.md"
- Mistral: "swarms/models/mistral.md" - Mistral: "swarms/models/mistral.md"
- MultiModal: - MultiModal:
- BaseMultiModalModel: "swarms/models/base_multimodal_model.md"
- Fuyu: "swarms/models/fuyu.md" - Fuyu: "swarms/models/fuyu.md"
- Vilt: "swarms/models/vilt.md" - Vilt: "swarms/models/vilt.md"
- Idefics: "swarms/models/idefics.md" - Idefics: "swarms/models/idefics.md"
@ -96,23 +95,25 @@ nav:
- GPT4V: "swarms/models/gpt4v.md" - GPT4V: "swarms/models/gpt4v.md"
- LayoutLMDocumentQA: "swarms/models/layoutlm_document_qa.md" - LayoutLMDocumentQA: "swarms/models/layoutlm_document_qa.md"
- DistilWhisperModel: "swarms/models/distilled_whisperx.md" - DistilWhisperModel: "swarms/models/distilled_whisperx.md"
- ElevenLabsText2SpeechTool: "swarms/models/elevenlabs.md"
- swarms.structs: - swarms.structs:
- Overview: "swarms/structs/overview.md" - Overview: "swarms/structs/overview.md"
- Workflow: "swarms/structs/workflow.md" - AutoScaler: "swarms/swarms/autoscaler.md"
- Flow: "swarms/structs/flow.md" - Agent: "swarms/structs/agent.md"
- SequentialWorkflow: 'swarms/structs/sequential_workflow.md' - SequentialWorkflow: 'swarms/structs/sequential_workflow.md'
- swarms.memory: - swarms.memory:
- Weaviate: "swarms/memory/weaviate.md"
- PineconeVectorStoreStore: "swarms/memory/pinecone.md" - PineconeVectorStoreStore: "swarms/memory/pinecone.md"
- PGVectorStore: "swarms/memory/pg.md" - PGVectorStore: "swarms/memory/pg.md"
- swarms.chunkers: - swarms.utils:
- BaseChunker: "swarms/chunkers/basechunker.md" - phoenix_trace_decorator: "swarms/utils/phoenix_tracer.md"
- PdfChunker: "swarms/chunkers/pdf_chunker.md"
- Guides: - Guides:
- Overview: "examples/index.md" - Overview: "examples/index.md"
- Agents: - Agents:
- Flow: "examples/flow.md" - Agent: "examples/flow.md"
- SequentialWorkflow: "examples/reliable_autonomous_agents.md"
- OmniAgent: "examples/omni_agent.md" - OmniAgent: "examples/omni_agent.md"
- Swarms:
- SequentialWorkflow: "examples/reliable_autonomous_agents.md"
- 2O+ Autonomous Agent Blogs: "examples/ideas.md" - 2O+ Autonomous Agent Blogs: "examples/ideas.md"
- Applications: - Applications:
- CustomerSupport: - CustomerSupport:
@ -134,3 +135,4 @@ nav:
- Architecture: "corporate/architecture.md" - Architecture: "corporate/architecture.md"
- Checklist: "corporate/checklist.md" - Checklist: "corporate/checklist.md"
- Hiring: "corporate/hiring.md" - Hiring: "corporate/hiring.md"
- SwarmCloud: "corporate/swarm_cloud.md"

@ -0,0 +1,34 @@
# Description: This is an example of how to use the Agent class to run a multi-modal workflow
import os
from dotenv import load_dotenv
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.structs import Agent
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = GPT4VisionAPI(
openai_api_key=api_key,
max_tokens=500,
)
# Initialize the language model
task = "What is the color of the object?"
img = "images/swarms.jpeg"
## Initialize the workflow
agent = Agent(
llm=llm,
max_loops="auto",
autosave=True,
dashboard=True,
multi_modal=True,
)
# Run the workflow on a task
out = agent.run(task=task, img=img)
print(out)

@ -4,11 +4,16 @@ load_dict = {"ImageCaptioning": "cuda"}
node = MultiModalAgent(load_dict) node = MultiModalAgent(load_dict)
text = node.run_text("What is your name? Generate a picture of yourself") text = node.run_text(
"What is your name? Generate a picture of yourself"
)
img = node.run_img("/image1", "What is this image about?") img = node.run_img("/image1", "What is this image about?")
chat = node.chat( chat = node.chat(
"What is your name? Generate a picture of yourself. What is this image about?", (
"What is your name? Generate a picture of yourself. What is"
" this image about?"
),
streaming=True, streaming=True,
) )

@ -1,5 +1,5 @@
from swarms.agents.simple_agent import SimpleAgent from swarms.agents.simple_agent import SimpleAgent
from swarms.structs import Flow from swarms.structs import Agent
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
api_key = "" api_key = ""
@ -9,8 +9,8 @@ llm = OpenAIChat(
temperature=0.5, temperature=0.5,
) )
# Initialize the flow # Initialize the agent
flow = Flow( agent = Agent(
llm=llm, llm=llm,
max_loops=5, max_loops=5,
) )
@ -18,7 +18,7 @@ flow = Flow(
agent = SimpleAgent( agent = SimpleAgent(
name="Optimus Prime", name="Optimus Prime",
flow=flow, agent=agent,
# Memory # Memory
) )

@ -0,0 +1,83 @@
import os
from dotenv import load_dotenv
from swarms.models import Anthropic, OpenAIChat
from swarms.prompts.accountant_swarm_prompts import (
DECISION_MAKING_PROMPT,
DOC_ANALYZER_AGENT_PROMPT,
SUMMARY_GENERATOR_AGENT_PROMPT,
)
from swarms.structs import Agent
from swarms.utils.pdf_to_text import pdf_to_text
# Environment variables
load_dotenv()
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
openai_api_key = os.getenv("OPENAI_API_KEY")
# Base llms
llm1 = OpenAIChat(
openai_api_key=openai_api_key,
max_tokens=5000,
)
llm2 = Anthropic(
anthropic_api_key=anthropic_api_key,
max_tokens=5000,
)
# Agents
doc_analyzer_agent = Agent(
llm=llm2,
sop=DOC_ANALYZER_AGENT_PROMPT,
max_loops=1,
autosave=True,
saved_state_path="doc_analyzer_agent.json",
)
summary_generator_agent = Agent(
llm=llm2,
sop=SUMMARY_GENERATOR_AGENT_PROMPT,
max_loops=1,
autosave=True,
saved_state_path="summary_generator_agent.json",
)
decision_making_support_agent = Agent(
llm=llm2,
sop=DECISION_MAKING_PROMPT,
max_loops=1,
saved_state_path="decision_making_support_agent.json",
)
pdf_path = "bankstatement.pdf"
fraud_detection_instructions = "Detect fraud in the document"
summary_agent_instructions = (
"Generate an actionable summary of the document with action steps"
" to take"
)
decision_making_support_agent_instructions = (
"Provide decision making support to the business owner:"
)
# Transform the pdf to text
pdf_text = pdf_to_text(pdf_path)
print(pdf_text)
# Detect fraud in the document
fraud_detection_agent_output = doc_analyzer_agent.run(
f"{fraud_detection_instructions}: {pdf_text}"
)
# Generate an actionable summary of the document
summary_agent_output = summary_generator_agent.run(
f"{summary_agent_instructions}: {fraud_detection_agent_output}"
)
# Provide decision making support to the accountant
decision_making_support_agent_output = decision_making_support_agent.run(
f"{decision_making_support_agent_instructions}:"
f" {summary_agent_output}"
)

@ -0,0 +1,102 @@
import random
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.structs import Agent
from swarms.models.stable_diffusion import StableDiffusion
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
stability_api_key = os.getenv("STABILITY_API_KEY")
# Initialize the language model and image generation model
llm = OpenAIChat(
openai_api_key=openai_api_key, temperature=0.5, max_tokens=3000
)
sd_api = StableDiffusion(api_key=stability_api_key)
# Creative Concept Generator for Product Ads
class ProductAdConceptGenerator:
def __init__(self, product_name):
self.product_name = product_name
self.themes = [
"futuristic",
"rustic",
"luxurious",
"minimalistic",
"vibrant",
"elegant",
"retro",
"urban",
"ethereal",
"surreal",
"artistic",
"tech-savvy",
"vintage",
"natural",
"sophisticated",
"playful",
"dynamic",
"serene",
"lasers,lightning",
]
self.contexts = [
"in an everyday setting",
"in a rave setting",
"in an abstract environment",
"in an adventurous context",
"surrounded by nature",
"in a high-tech setting",
"in a historical context",
"in a busy urban scene",
"in a tranquil and peaceful setting",
"against a backdrop of city lights",
"in a surreal dreamscape",
"in a festive atmosphere",
"in a luxurious setting",
"in a playful and colorful background",
"in an ice cave setting",
"in a serene and calm landscape",
]
self.contexts = [
"high realism product ad (extremely creative)"
]
def generate_concept(self):
theme = random.choice(self.themes)
context = random.choice(self.contexts)
return (
f"{theme} inside a {style} {self.product_name}, {context}"
)
# User input
product_name = input(
"Enter a product name for ad creation (e.g., 'PS5', 'AirPods',"
" 'Kirkland Vodka'): "
)
# Generate creative concept
concept_generator = ProductAdConceptGenerator(product_name)
creative_concept = concept_generator.generate_concept()
# Generate product image based on the creative concept
image_paths = sd_api.run(creative_concept)
# Generate ad copy
ad_copy_agent = Agent(llm=llm, max_loops=1)
ad_copy_prompt = (
f"Write a compelling {social_media_platform} ad copy for a"
f" product photo showing {product_name} {creative_concept}."
)
ad_copy = ad_copy_agent.run(task=ad_copy_prompt)
# Output the results
print("Creative Concept:", concept_result)
print("Design Ideas:", design_result)
print("Ad Copy:", copywriting_result)
print(
"Image Path:",
image_paths[0] if image_paths else "No image generated",
)

@ -0,0 +1,56 @@
import os
from dotenv import load_dotenv
from swarms.models import Anthropic, OpenAIChat
from swarms.prompts.ai_research_team import (
PAPER_IMPLEMENTOR_AGENT_PROMPT,
PAPER_SUMMARY_ANALYZER,
)
from swarms.structs import Agent
from swarms.utils.pdf_to_text import pdf_to_text
# Base llms
# Environment variables
load_dotenv()
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
openai_api_key = os.getenv("OPENAI_API_KEY")
PDF_PATH = "fasterffn.pdf"
# Base llms
llm1 = OpenAIChat(
openai_api_key=openai_api_key,
)
llm2 = Anthropic(
anthropic_api_key=anthropic_api_key,
)
# Agents
paper_summarizer_agent = Agent(
llm=llm2,
sop=PAPER_SUMMARY_ANALYZER,
max_loops=1,
autosave=True,
saved_state_path="paper_summarizer.json",
)
paper_implementor_agent = Agent(
llm=llm1,
sop=PAPER_IMPLEMENTOR_AGENT_PROMPT,
max_loops=1,
autosave=True,
saved_state_path="paper_implementor.json",
code_interpreter=False,
)
paper = pdf_to_text(PDF_PATH)
algorithmic_psuedocode_agent = paper_summarizer_agent.run(
"Focus on creating the algorithmic pseudocode for the novel"
f" method in this paper: {paper}"
)
pytorch_code = paper_implementor_agent.run(
algorithmic_psuedocode_agent
)

@ -0,0 +1,24 @@
from swarms.structs import Agent
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.prompts.multi_modal_autonomous_instruction_prompt import (
MULTI_MODAL_AUTO_AGENT_SYSTEM_PROMPT_1,
)
llm = GPT4VisionAPI()
task = (
"Analyze this image of an assembly line and identify any issues"
" such as misaligned parts, defects, or deviations from the"
" standard assembly process. IF there is anything unsafe in the"
" image, explain why it is unsafe and how it could be improved."
)
img = "assembly_line.jpg"
## Initialize the workflow
agent = Agent(
llm=llm,
max_loops=1,
dashboard=True,
)
agent.run(task=task, img=img)

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 KiB

@ -0,0 +1,147 @@
from termcolor import colored
from swarms.prompts.autobloggen import (
DRAFT_AGENT_SYSTEM_PROMPT,
REVIEW_PROMPT,
SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT,
TOPIC_GENERATOR,
)
# Prompts
topic_selection_task = (
"Generate 10 topics on gaining mental clarity using ancient"
" practices"
)
class AutoBlogGenSwarm:
"""
AutoBlogGenSwarm
Swarm Agent
Topic selection agent -> draft agent -> review agent -> distribution agent
Topic Selection Agent:
- Generate 10 topics on gaining mental clarity using Taosim and Christian meditation
Draft Agent:
- Write a 100% unique, creative and in human-like style article of a minimum of 5,000 words using headings and sub-headings.
Review Agent:
- Refine the article to meet PositiveMeds stringent publication standards.
Distribution Agent:
- Social Media posts for the article.
Example:
```
from swarms.autobloggen import AutoBlogGenSwarm
swarm = AutoBlogGenSwarm()
swarm.run()
```
"""
def __init__(
self,
llm,
objective: str = "Clicks and engagement",
iterations: int = 3,
topic_selection_task: str = topic_selection_task,
max_retries: int = 3,
retry_attempts: int = 3,
topic_selection_agent_prompt: str = f"Your System Instructions: {TOPIC_GENERATOR}, Your current task: {topic_selection_task}",
):
self.llm = llm()
self.topic_selection_task = topic_selection_task
self.topic_selection_agent_prompt = (
topic_selection_agent_prompt
)
self.objective = objective
self.iterations = iterations
self.max_retries = max_retries
self.retry_attempts = retry_attempts
def print_beautifully(self, subheader: str, text: str):
"""Prints the text beautifully"""
print(
colored(
f"""
------------------------------------
{subheader}
-----------------------------
{text}
""",
"blue",
)
)
def social_media_prompt(self, article: str):
"""Gets the social media prompt"""
prompt = SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT.replace(
"{{ARTICLE}}", article
).replace("{{GOAL}}", self.objective)
return prompt
def get_review_prompt(self, article: str):
"""Gets the review prompt"""
prompt = REVIEW_PROMPT.replace("{{ARTICLE}}", article)
return prompt
def step(self):
"""Steps through the task"""
topic_selection_agent = self.llm(
self.topic_selection_agent_prompt
)
topic_selection_agent = self.print_beautifully(
"Topic Selection Agent", topic_selection_agent
)
draft_blog = self.llm(DRAFT_AGENT_SYSTEM_PROMPT)
draft_blog = self.print_beatiufully("Draft Agent", draft_blog)
# Agent that reviews the draft
review_agent = self.llm(self.get_review_prompt(draft_blog))
review_agent = self.print_beautifully(
"Review Agent", review_agent
)
# Agent that publishes on social media
distribution_agent = self.llm(
self.social_media_prompt(article=review_agent)
)
distribution_agent = self.print_beautifully(
"Distribution Agent", distribution_agent
)
def run(self):
"""Runs the swarm"""
for attempt in range(self.retry_attempts):
try:
for i in range(self.iterations):
self.step()
except Exception as error:
print(
colored(
(
"Error while running AutoBlogGenSwarm"
f" {error}"
),
"red",
)
)
if attempt == self.retry_attempts - 1:
raise
def update_task(self, new_task: str):
"""
Updates the task of the swarm
Args:
new_task (str): New task to be performed by the swarm
"""
self.topic_selection_agent = new_task

@ -0,0 +1,90 @@
import re
from swarms.models.openai_models import OpenAIChat
class AutoTemp:
"""
AutoTemp is a tool for automatically selecting the best temperature setting for a given task.
It generates responses at different temperatures, evaluates them, and ranks them based on quality.
"""
def __init__(
self,
api_key,
default_temp=0.0,
alt_temps=None,
auto_select=True,
max_workers=6,
):
self.api_key = api_key
self.default_temp = default_temp
self.alt_temps = (
alt_temps if alt_temps else [0.4, 0.6, 0.8, 1.0, 1.2, 1.4]
)
self.auto_select = auto_select
self.max_workers = max_workers
self.llm = OpenAIChat(
openai_api_key=self.api_key, temperature=self.default_temp
)
def evaluate_output(self, output, temperature):
print(f"Evaluating output at temperature {temperature}...")
eval_prompt = f"""
Evaluate the following output which was generated at a temperature setting of {temperature}. Provide a precise score from 0.0 to 100.0, considering the following criteria:
- Relevance: How well does the output address the prompt or task at hand?
- Clarity: Is the output easy to understand and free of ambiguity?
- Utility: How useful is the output for its intended purpose?
- Pride: If the user had to submit this output to the world for their career, would they be proud?
- Delight: Is the output likely to delight or positively surprise the user?
Be sure to comprehensively evaluate the output, it is very important for my career. Please answer with just the score with one decimal place accuracy, such as 42.0 or 96.9. Be extremely critical.
Output to evaluate:
---
{output}
---
"""
score_text = self.llm(eval_prompt, temperature=0.5)
score_match = re.search(r"\b\d+(\.\d)?\b", score_text)
return (
round(float(score_match.group()), 1)
if score_match
else 0.0
)
def run(self, prompt, temperature_string):
print("Starting generation process...")
temperature_list = [
float(temp.strip())
for temp in temperature_string.split(",")
if temp.strip()
]
outputs = {}
scores = {}
for temp in temperature_list:
print(f"Generating at temperature {temp}...")
output_text = self.llm(prompt, temperature=temp)
if output_text:
outputs[temp] = output_text
scores[temp] = self.evaluate_output(output_text, temp)
print("Generation process complete.")
if not scores:
return "No valid outputs generated.", None
sorted_scores = sorted(
scores.items(), key=lambda item: item[1], reverse=True
)
best_temp, best_score = sorted_scores[0]
best_output = outputs[best_temp]
return (
f"Best AutoTemp Output (Temp {best_temp} | Score:"
f" {best_score}):\n{best_output}"
if self.auto_select
else "\n".join(
f"Temp {temp} | Score: {score}:\n{outputs[temp]}"
for temp, score in sorted_scores
)
)

@ -0,0 +1,22 @@
from swarms.models import OpenAIChat
from autotemp import AutoTemp
# Your OpenAI API key
api_key = ""
autotemp_agent = AutoTemp(
api_key=api_key,
alt_temps=[0.4, 0.6, 0.8, 1.0, 1.2],
auto_select=False,
# model_version="gpt-3.5-turbo" # Specify the model version if needed
)
# Define the task and temperature string
task = "Generate a short story about a lost civilization."
temperature_string = "0.4,0.6,0.8,1.0,1.2,"
# Run the AutoTempAgent
result = autotemp_agent.run(task, temperature_string)
# Print the result
print(result)

@ -0,0 +1,138 @@
import os
from termcolor import colored
from swarms.models import OpenAIChat
from autotemp import AutoTemp
from swarms.structs import SequentialWorkflow
class BlogGen:
def __init__(
self,
api_key,
blog_topic,
temperature_range: str = "0.4,0.6,0.8,1.0,1.2",
): # Add blog_topic as an argument
self.openai_chat = OpenAIChat(
openai_api_key=api_key, temperature=0.8
)
self.auto_temp = AutoTemp(api_key)
self.temperature_range = temperature_range
self.workflow = SequentialWorkflow(max_loops=5)
# Formatting the topic selection prompt with the user's topic
self.TOPIC_SELECTION_SYSTEM_PROMPT = f"""
Given the topic '{blog_topic}', generate an engaging and versatile blog topic. This topic should cover areas related to '{blog_topic}' and might include aspects such as current events, lifestyle, technology, health, and culture related to '{blog_topic}'. Identify trending subjects within this realm. The topic must be unique, thought-provoking, and have the potential to draw in readers interested in '{blog_topic}'.
"""
self.DRAFT_WRITER_SYSTEM_PROMPT = """
Create an engaging and comprehensive blog article of at least 1,000 words on '{{CHOSEN_TOPIC}}'. The content should be original, informative, and reflective of a human-like style, with a clear structure including headings and sub-headings. Incorporate a blend of narrative, factual data, expert insights, and anecdotes to enrich the article. Focus on SEO optimization by using relevant keywords, ensuring readability, and including meta descriptions and title tags. The article should provide value, appeal to both knowledgeable and general readers, and maintain a balance between depth and accessibility. Aim to make the article engaging and suitable for online audiences.
"""
self.REVIEW_AGENT_SYSTEM_PROMPT = """
Critically review the drafted blog article on '{{ARTICLE_TOPIC}}' to refine it to high-quality content suitable for online publication. Ensure the article is coherent, factually accurate, engaging, and optimized for search engines (SEO). Check for the effective use of keywords, readability, internal and external links, and the inclusion of meta descriptions and title tags. Edit the content to enhance clarity, impact, and maintain the authors voice. The goal is to polish the article into a professional, error-free piece that resonates with the target audience, adheres to publication standards, and is optimized for both search engines and social media sharing.
"""
self.DISTRIBUTION_AGENT_SYSTEM_PROMPT = """
Develop an autonomous distribution strategy for the blog article on '{{ARTICLE_TOPIC}}'. Utilize an API to post the article on a popular blog platform (e.g., WordPress, Blogger, Medium) commonly used by our target audience. Ensure the post includes all SEO elements like meta descriptions, title tags, and properly formatted content. Craft unique, engaging social media posts tailored to different platforms to promote the blog article. Schedule these posts to optimize reach and engagement, using data-driven insights. Monitor the performance of the distribution efforts, adjusting strategies based on engagement metrics and audience feedback. Aim to maximize the article's visibility, attract a diverse audience, and foster engagement across digital channels.
"""
def run_workflow(self):
try:
# Topic generation using OpenAIChat
topic_result = self.openai_chat.generate(
[self.TOPIC_SELECTION_SYSTEM_PROMPT]
)
topic_output = topic_result.generations[0][0].text
print(
colored(
(
"\nTopic Selection Task"
f" Output:\n----------------------------\n{topic_output}\n"
),
"white",
)
)
chosen_topic = topic_output.split("\n")[0]
print(
colored("Selected topic: " + chosen_topic, "yellow")
)
# Initial draft generation with AutoTemp
initial_draft_prompt = (
self.DRAFT_WRITER_SYSTEM_PROMPT.replace(
"{{CHOSEN_TOPIC}}", chosen_topic
)
)
auto_temp_output = self.auto_temp.run(
initial_draft_prompt, self.temperature_range
)
initial_draft_output = auto_temp_output # Assuming AutoTemp.run returns the best output directly
print(
colored(
(
"\nInitial Draft"
f" Output:\n----------------------------\n{initial_draft_output}\n"
),
"white",
)
)
# Review process using OpenAIChat
review_prompt = self.REVIEW_AGENT_SYSTEM_PROMPT.replace(
"{{ARTICLE_TOPIC}}", chosen_topic
)
review_result = self.openai_chat.generate([review_prompt])
review_output = review_result.generations[0][0].text
print(
colored(
(
"\nReview"
f" Output:\n----------------------------\n{review_output}\n"
),
"white",
)
)
# Distribution preparation using OpenAIChat
distribution_prompt = (
self.DISTRIBUTION_AGENT_SYSTEM_PROMPT.replace(
"{{ARTICLE_TOPIC}}", chosen_topic
)
)
distribution_result = self.openai_chat.generate(
[distribution_prompt]
)
distribution_output = distribution_result.generations[0][
0
].text
print(
colored(
(
"\nDistribution"
f" Output:\n----------------------------\n{distribution_output}\n"
),
"white",
)
)
# Final compilation of the blog
final_blog_content = f"{initial_draft_output}\n\n{review_output}\n\n{distribution_output}"
print(
colored(
(
"\nFinal Blog"
f" Content:\n----------------------------\n{final_blog_content}\n"
),
"green",
)
)
except Exception as e:
print(colored(f"An error occurred: {str(e)}", "red"))
if __name__ == "__main__":
api_key = os.environ["OPENAI_API_KEY"]
blog_generator = BlogGen(api_key)
blog_generator.run_workflow()

@ -0,0 +1,25 @@
import os
from blog_gen import BlogGen
def main():
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError(
"OPENAI_API_KEY environment variable not set."
)
blog_topic = input("Enter the topic for the blog generation: ")
blog_generator = BlogGen(api_key, blog_topic)
blog_generator.TOPIC_SELECTION_SYSTEM_PROMPT = (
blog_generator.TOPIC_SELECTION_SYSTEM_PROMPT.replace(
"{{BLOG_TOPIC}}", blog_topic
)
)
blog_generator.run_workflow()
if __name__ == "__main__":
main()

@ -0,0 +1,5 @@
"""
Autonomous swarm that optimizes UI autonomously
GPT4Vision ->> GPT4 ->> UI Code
"""

@ -0,0 +1,63 @@
"""
Swarm of developers that write documentation and tests for a given code snippet.
This is a simple example of how to use the swarms library to create a swarm of developers that write documentation and tests for a given code snippet.
The swarm is composed of two agents:
- Documentation agent: writes documentation for a given code snippet.
- Tests agent: writes tests for a given code snippet.
The swarm is initialized with a language model that is used by the agents to generate text. In this example, we use the OpenAI GPT-3 language model.
Agent:
Documentation agent -> Tests agent
"""
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.prompts.programming import DOCUMENTATION_SOP, TEST_SOP
from swarms.structs import Agent
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
TASK = """
CODE
"""
# Initialize the language model
llm = OpenAIChat(openai_api_key=api_key, max_tokens=5000)
# Documentation agent
documentation_agent = Agent(
llm=llm,
sop=DOCUMENTATION_SOP,
max_loops=1,
)
# Tests agent
tests_agent = Agent(
llm=llm,
sop=TEST_SOP,
max_loops=2,
)
# Run the documentation agent
documentation = documentation_agent.run(
f"Write documentation for the following code:{TASK}"
)
# Run the tests agent
tests = tests_agent.run(
f"Write tests for the following code:{TASK} here is the"
f" documentation: {documentation}"
)

@ -0,0 +1,76 @@
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.models.stable_diffusion import StableDiffusion
from swarms.structs import Agent, SequentialWorkflow
import swarms.prompts.education as edu_prompts
# Load environment variables
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
stability_api_key = os.getenv("STABILITY_API_KEY")
# Initialize language model
llm = OpenAIChat(
openai_api_key=api_key, temperature=0.5, max_tokens=3000
)
# Initialize Stable Diffusion
sd_api = StableDiffusion(api_key=stability_api_key)
# User preferences (can be dynamically set in a real application)
user_preferences = {
"subjects": "Cognitive Architectures",
"learning_style": "Visual",
"challenge_level": "Moderate",
}
# Formatted prompts from user preferences
curriculum_prompt = edu_prompts.CURRICULUM_DESIGN_PROMPT.format(
**user_preferences
)
interactive_prompt = edu_prompts.INTERACTIVE_LEARNING_PROMPT.format(
**user_preferences
)
sample_prompt = edu_prompts.SAMPLE_TEST_PROMPT.format(
**user_preferences
)
image_prompt = edu_prompts.IMAGE_GENERATION_PROMPT.format(
**user_preferences
)
# Initialize agents for different educational tasks
curriculum_agent = Agent(llm=llm, max_loops=1, sop=curriculum_prompt)
interactive_learning_agent = Agent(
llm=llm, max_loops=1, sop=interactive_prompt
)
sample_lesson_agent = Agent(llm=llm, max_loops=1, sop=sample_prompt)
# Create Sequential Workflow
workflow = SequentialWorkflow(max_loops=1)
# Add tasks to workflow with personalized prompts
workflow.add(curriculum_agent, "Generate a curriculum")
workflow.add(
interactive_learning_agent, "Generate an interactive lesson"
)
workflow.add(sample_lesson_agent, "Generate a practice test")
# Execute the workflow for text-based tasks
workflow.run()
# Generate an image using Stable Diffusion
image_result = sd_api.run(image_prompt)
# Output results for each task
for task in workflow.tasks:
print(
f"Task Description: {task.description}\nResult:"
f" {task.result}\n"
)
# Output image result
print(
"Image Generation Task: Generate an image for the interactive"
f" lesson\nResult: {image_result}"
)

@ -0,0 +1,149 @@
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.prompts.code_interpreter import CODE_INTERPRETER
from swarms.structs import Agent
from swarms.prompts.programming import TEST_SOP, DOCUMENTATION_SOP
from termcolor import colored
load_dotenv()
FEATURE = (
"Implement an all-new signup system in typescript using supabase"
)
CODEBASE = """
import React, { useState } from 'react';
import UpperPanel from './UpperPanel';
import LowerPanel from './LowerPanel';
const MainPanel = () => {
const [promptInstructionForLowerPanel, setPromptInstructionForLowerPanel] = useState('');
const [formData, setFormData] = useState('');
const [isLoading, setIsLoading] = useState(false);
return (
<div className="flex h-screen">
<UpperPanel setPromptInstructionForLowerPanel={setPromptInstructionForLowerPanel}
isLoading={isLoading}
setIsLoading={setIsLoading}
/>
<LowerPanel promptInstruction={promptInstructionForLowerPanel} isLoading={isLoading} />
</div>
);
};
export default MainPanel;
"""
# Load the environment variables
api_key = os.getenv("OPENAI_API_KEY")
# Initialize the language agent
llm = OpenAIChat(
model_name="gpt-4",
openai_api_key=api_key,
temperature=0.5,
max_tokens=4000,
)
# Product Manager Agent init
product_manager_agent = Agent(
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
)
# Initialize the agent with the language agent
feature_implementer_frontend = Agent(
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
)
# Create another agent for a different task
feature_implementer_backend = Agent(
llm=llm, max_loops=1, sop=CODE_INTERPRETER, autosave=True
)
# Create another agent for a different task
tester_agent = Agent(
llm=llm, max_loops=1, sop=TEST_SOP, autosave=True
)
# Create another agent for a different task
documenting_agent = Agent(
llm=llm, max_loops=1, sop=DOCUMENTATION_SOP, autosave=True
)
# Product Agent prompt
def feature_codebase_product_agentprompt(
feature: str, codebase: str
) -> str:
prompt = (
"Create an algorithmic pseudocode for an all-new feature:"
f" {feature} based on this codebase: {codebase}"
)
return prompt
# Product Manager Agent
product_manager_out = product_manager_agent.run(
feature_codebase_product_agentprompt(FEATURE, CODEBASE)
)
print(
colored(
(
"---------------------------- Product Manager Plan:"
f" {product_manager_out}"
),
"cyan",
)
)
# Feature Implementer Agent
agent1_out = feature_implementer_frontend.run(
f"Create the backend code for {FEATURE} in markdown based off of"
f" this algorithmic pseudocode: {product_manager_out} the logic"
f" based on the following codebase: {CODEBASE}"
)
print(
colored(
(
"--------------------- Feature Implementer Code logic:"
f" {agent1_out}"
),
"cyan",
)
)
# Tester agent
tester_agent_out = tester_agent.run(
f"Create tests for the following code: {agent1_out}"
)
print(
colored(
(
"---------------------------- Tests for the logic:"
f" {tester_agent_out}"
),
"green",
)
)
# Documentation Agent
documenter_agent_out = documenting_agent.run(
f"Document the following code: {agent1_out}"
)
print(
colored(
(
"---------------------------- Documentation for the"
f" logic: {documenter_agent_out}"
),
"yellow",
)
)

@ -0,0 +1,13 @@
#!/bin/bash
# Define the base URL
base_url="http://localhost:8000"
# Define the JSON payload
payload='{"feature": "login system", "codebase": "existing codebase here"}'
# Send POST request
echo "Sending request to /agent/ endpoint..."
response=$(curl -s -X POST "$base_url/agent/" -H "Content-Type: application/json" -d "$payload")
echo "Response: $response"

@ -0,0 +1,13 @@
#!/bin/bash
# Define the base URL
base_url="http://localhost:8000"
# Define the JSON payload
payload='{"feature": "login system", "codebase": "existing codebase here"}'
# Send POST request
echo "Sending request to /agent/ endpoint..."
response=$(curl -s -X POST "$base_url/agent/" -H "Content-Type: application/json" -d "$payload")
echo "Response: $response"

@ -0,0 +1,20 @@
from swarms.structs import Agent
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.prompts.multi_modal_autonomous_instruction_prompt import (
MULTI_MODAL_AUTO_AGENT_SYSTEM_PROMPT_1,
)
llm = GPT4VisionAPI()
task = "What is the color of the object?"
img = "images/swarms.jpeg"
## Initialize the workflow
agent = Agent(
llm=llm,
sop=MULTI_MODAL_AUTO_AGENT_SYSTEM_PROMPT_1,
max_loops="auto",
)
agent.run(task=task, img=img)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

@ -0,0 +1,103 @@
from swarms.structs import Agent
import os
from dotenv import load_dotenv
from swarms.models import GPT4VisionAPI
from swarms.prompts.logistics import (
Health_Security_Agent_Prompt,
Quality_Control_Agent_Prompt,
Productivity_Agent_Prompt,
Safety_Agent_Prompt,
Security_Agent_Prompt,
Sustainability_Agent_Prompt,
Efficiency_Agent_Prompt,
)
# from swarms.utils.phoenix_handler import phoenix_trace_decorator
# from swarms.utils.banana_wrapper import banana
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
# GPT4VisionAPI or llama
# @banana #- deploy to banana
llm = GPT4VisionAPI(openai_api_key=api_key)
# Image for analysis
factory_image = "factory_image1.jpg"
# Initialize agents with respective prompts
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
health_security_agent = Agent(
llm=llm,
sop=Health_Security_Agent_Prompt,
max_loops=1,
multi_modal=True,
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
quality_control_agent = Agent(
llm=llm,
sop=Quality_Control_Agent_Prompt,
max_loops=1,
multi_modal=True,
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
productivity_agent = Agent(
llm=llm,
sop=Productivity_Agent_Prompt,
max_loops=1,
multi_modal=True,
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
safety_agent = Agent(
llm=llm, sop=Safety_Agent_Prompt, max_loops=1, multi_modal=True
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
security_agent = Agent(
llm=llm, sop=Security_Agent_Prompt, max_loops=1, multi_modal=True
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
sustainability_agent = Agent(
llm=llm,
sop=Sustainability_Agent_Prompt,
max_loops=1,
multi_modal=True,
)
# @phoenix_trace_decorator("This function is an agent and is traced by Phoenix.")
efficiency_agent = Agent(
llm=llm,
sop=Efficiency_Agent_Prompt,
max_loops=1,
multi_modal=True,
)
# Run agents with respective tasks on the same image
health_analysis = health_security_agent.run(
"Analyze the safety of this factory", factory_image
)
quality_analysis = quality_control_agent.run(
"Examine product quality in the factory", factory_image
)
productivity_analysis = productivity_agent.run(
"Evaluate factory productivity", factory_image
)
safety_analysis = safety_agent.run(
"Inspect the factory's adherence to safety standards",
factory_image,
)
security_analysis = security_agent.run(
"Assess the factory's security measures and systems",
factory_image,
)
sustainability_analysis = sustainability_agent.run(
"Examine the factory's sustainability practices", factory_image
)
efficiency_analysis = efficiency_agent.run(
"Analyze the efficiency of the factory's manufacturing process",
factory_image,
)

@ -0,0 +1,17 @@
from swarms.structs import Agent
from swarms.models.gpt4_vision_api import GPT4VisionAPI
llm = GPT4VisionAPI()
task = "What is the color of the object?"
img = "images/swarms.jpeg"
## Initialize the workflow
agent = Agent(
llm=llm,
max_loops="auto",
dashboard=True,
)
agent.run(task=task, img=img)

@ -0,0 +1,185 @@
import datetime
import os
import streamlit as st
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.models.stable_diffusion import StableDiffusion
from swarms.structs import Agent
# Load environment variables
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
stability_api_key = os.getenv("STABLE_API_KEY")
# Initialize the models
vision_api = GPT4VisionAPI(api_key=openai_api_key)
sd_api = StableDiffusion(api_key=stability_api_key)
gpt_api = OpenAIChat(openai_api_key=openai_api_key)
class Idea2Image(Agent):
def __init__(self, llm, vision_api):
super().__init__(llm=llm)
self.vision_api = vision_api
def run(self, initial_prompt, num_iterations, run_folder):
current_prompt = initial_prompt
for i in range(num_iterations):
print(f"Iteration {i}: Image generation and analysis")
if i == 0:
current_prompt = self.enrich_prompt(current_prompt)
print(f"Enriched Prompt: {current_prompt}")
img = sd_api.generate_and_move_image(
current_prompt, i, run_folder
)
if not img:
print("Failed to generate image")
break
print(f"Generated image at: {img}")
analysis = (
self.vision_api.run(img, current_prompt)
if img
else None
)
if analysis:
current_prompt += (
". " + analysis[:500]
) # Ensure the analysis is concise
print(f"Image Analysis: {analysis}")
else:
print(f"Failed to analyze image at: {img}")
def enrich_prompt(self, prompt):
enrichment_task = (
"Create a concise and effective image generation prompt"
" within 400 characters or less, based on Stable"
" Diffusion and Dalle best practices to help it create"
" much better images. Starting prompt:"
f" \n\n'{prompt}'\n\nImprove the prompt with any"
" applicable details or keywords by considering the"
" following aspects: \n1. Subject details (like actions,"
" emotions, environment) \n2. Artistic style (such as"
" surrealism, hyperrealism) \n3. Medium (digital"
" painting, oil on canvas) \n4. Color themes and"
" lighting (like warm colors, cinematic lighting) \n5."
" Composition and framing (close-up, wide-angle) \n6."
" Additional elements (like a specific type of"
" background, weather conditions) \n7. Any other"
" artistic or thematic details that can make the image"
" more vivid and compelling. Help the image generator"
" create better images by enriching the prompt."
)
llm_result = self.llm.generate([enrichment_task])
return (
llm_result.generations[0][0].text[:500]
if llm_result.generations
else None
)
def run_gradio(self, initial_prompt, num_iterations, run_folder):
results = []
current_prompt = initial_prompt
for i in range(num_iterations):
enriched_prompt = (
self.enrich_prompt(current_prompt)
if i == 0
else current_prompt
)
img_path = sd_api.generate_and_move_image(
enriched_prompt, i, run_folder
)
analysis = (
self.vision_api.run(img_path, enriched_prompt)
if img_path
else None
)
if analysis:
current_prompt += (
". " + analysis[:500]
) # Ensuring the analysis is concise
results.append((enriched_prompt, img_path, analysis))
return results
# print(
# colored("---------------------------------------- MultiModal Tree of Thought agents for Image Generation", "cyan", attrs=["bold"])
# )
# # User input and setup
# user_prompt = input("Prompt for image generation: ")
# num_iterations = int(
# input("Enter the number of iterations for image improvement: ")
# )
# run_folder = os.path.join(
# "runs", datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
# )
# os.makedirs(run_folder, exist_ok=True)
# print(
# colored(
# f"---------------------------------- Running Multi-Modal Tree of thoughts agent with {num_iterations} iterations", "green"
# )
# )
# # Initialize and run the agent
# idea2image_agent = Idea2Image(gpt_api, vision_api)
# idea2image_agent.run(user_prompt, num_iterations, run_folder)
# print("Idea space has been traversed.")
# Load environment variables and initialize the models
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
stability_api_key = os.getenv("STABLE_API_KEY")
vision_api = GPT4VisionAPI(api_key=openai_api_key)
sd_api = StableDiffusion(api_key=stability_api_key)
gpt_api = OpenAIChat(openai_api_key=openai_api_key)
# Define the modified Idea2Image class here
# Streamlit UI layout
st.title(
"Explore the infinite Multi-Modal Idea Space with Idea2Image"
)
user_prompt = st.text_input("Prompt for image generation:")
num_iterations = st.number_input(
"Enter the number of iterations for image improvement:",
min_value=1,
step=1,
)
if st.button("Generate Image"):
run_folder = os.path.join(
"runs", datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
)
os.makedirs(run_folder, exist_ok=True)
idea2image_agent = Idea2Image(gpt_api, vision_api)
results = idea2image_agent.run_gradio(
user_prompt, num_iterations, run_folder
)
for i, (enriched_prompt, img_path, analysis) in enumerate(
results
):
st.write(f"Iteration {i+1}:")
st.write("Enriched Prompt:", enriched_prompt)
if img_path:
st.image(img_path, caption="Generated Image")
else:
st.error("Failed to generate image")
if analysis:
st.write("Image Analysis:", analysis)
st.success("Idea space has been traversed.")
# [Add any additional necessary code adjustments]

@ -0,0 +1,114 @@
"""
Multi Modal tree of thoughts that leverages the GPT-4 language model and the
Stable Diffusion model to generate a multimodal output and evaluate the
output based a metric from 0.0 to 1.0 and then run a search algorithm using DFS and BFS and return the best output.
task: Generate an image of a swarm of bees -> Image generator -> GPT4V evaluates the img from 0.0 to 1.0 -> DFS/BFS -> return the best output
- GPT4Vision will evaluate the image from 0.0 to 1.0 based on how likely it accomplishes the task
- DFS/BFS will search for the best output based on the evaluation from GPT4Vision
- The output will be a multimodal output that is a combination of the image and the text
- The output will be evaluated by GPT4Vision
- The prompt to the image generator will be optimized from the output of GPT4Vision and the search
"""
import os
from dotenv import load_dotenv
from swarms.models.gpt4_vision_api import GPT4VisionAPI
from swarms.models.stable_diffusion import StableDiffusion
from termcolor import colored
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
stable_api_key = os.environ.get("STABLE_API_KEY")
# Initialize the language model
llm = GPT4VisionAPI(
openai_api_key=api_key,
max_tokens=500,
)
# IMG Generator
img_generator = StableDiffusion(api_key=stable_api_key)
# Initialize the language model
task = "Garden of Eden futuristic city graphic art"
def evaluate_img(llm, task: str, img: str):
EVAL_IMG = f"""
Evaluate the image: {img} on a scale from 0.0 to 1.0 based on how likely it accomplishes the task: {task}. Output nothing than the float representing the evaluated img.
"""
out = llm.run(task=EVAL_IMG, img=img)
out = float(out)
return out
def enrichment_prompt(starting_prompt: str, evaluated_img: str):
enrichment_task = (
"Create a concise and effective image generation prompt"
" within 400 characters or less, based on Stable Diffusion"
" and Dalle best practices. Starting prompt:"
f" \n\n'{starting_prompt}'\n\nImprove the prompt with any"
" applicable details or keywords by considering the"
" following aspects: \n1. Subject details (like actions,"
" emotions, environment) \n2. Artistic style (such as"
" surrealism, hyperrealism) \n3. Medium (digital painting,"
" oil on canvas) \n4. Color themes and lighting (like warm"
" colors, cinematic lighting) \n5. Composition and framing"
" (close-up, wide-angle) \n6. Additional elements (like a"
" specific type of background, weather conditions) \n7. Any"
" other artistic or thematic details that can make the image"
" more vivid and compelling. 8. Based on the evaluation of"
" the first generated prompt used by the first prompt:"
f" {evaluated_img} Enrich the prompt to generate a more"
" compelling image. Output only a new prompt to create a"
" better image"
)
return enrichment_task
# Main loop
max_iterations = 10 # Define the maximum number of iterations
best_score = 0
best_image = None
for _ in range(max_iterations):
# Generate an image and get its path
print(colored(f"Generating img for Task: {task}", "purple"))
img_path = img_generator.run(
task=task
) # This should return the file path of the generated image
img_path = img_path[0]
print(colored(f"Generated Image Path: {img_path}", "green"))
# Evaluate the image by passing the file path
score = evaluate_img(llm, task, img_path)
print(
colored(
f"Evaluated Image Score: {score} for {img_path}", "cyan"
)
)
# Update the best score and image path if necessary
if score > best_score:
best_score = score
best_image_path = img_path
# Enrich the prompt based on the evaluation
prompt = enrichment_prompt(task, score)
print(colored(f"Enrichment Prompt: {prompt}", "yellow"))
# Output the best result
print("Best Image Path:", best_image_path)
print("Best Score:", best_score)

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

@ -0,0 +1,137 @@
import os
import base64
import requests
from dotenv import load_dotenv
from swarms.models import Anthropic, OpenAIChat
from swarms.structs import Agent
# Load environment variables
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
# Define prompts for various tasks
MEAL_PLAN_PROMPT = (
"Based on the following user preferences: dietary restrictions as"
" vegetarian, preferred cuisines as Italian and Indian, a total"
" caloric intake of around 2000 calories per day, and an"
" exclusion of legumes, create a detailed weekly meal plan."
" Include a variety of meals for breakfast, lunch, dinner, and"
" optional snacks."
)
IMAGE_ANALYSIS_PROMPT = (
"Identify the items in this fridge, including their quantities"
" and condition."
)
# Function to encode image to base64
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
# Initialize Language Model (LLM)
llm = OpenAIChat(
openai_api_key=openai_api_key,
max_tokens=3000,
)
# Function to handle vision tasks
def create_vision_agent(image_path):
base64_image = encode_image(image_path)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {openai_api_key}",
}
payload = {
"model": "gpt-4-vision-preview",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": IMAGE_ANALYSIS_PROMPT},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
},
},
],
}
],
"max_tokens": 300,
}
response = requests.post(
"https://api.openai.com/v1/chat/completions",
headers=headers,
json=payload,
)
return response.json()
# Function to generate an integrated shopping list considering meal plan and fridge contents
def generate_integrated_shopping_list(
meal_plan_output, image_analysis, user_preferences
):
# Prepare the prompt for the LLM
fridge_contents = image_analysis["choices"][0]["message"][
"content"
]
prompt = (
f"Based on this meal plan: {meal_plan_output}, and the"
f" following items in the fridge: {fridge_contents},"
" considering dietary preferences as vegetarian with a"
" preference for Italian and Indian cuisines, generate a"
" comprehensive shopping list that includes only the items"
" needed."
)
# Send the prompt to the LLM and return the response
response = llm(prompt)
return response # assuming the response is a string
# Define agent for meal planning
meal_plan_agent = Agent(
llm=llm,
sop=MEAL_PLAN_PROMPT,
max_loops=1,
autosave=True,
saved_state_path="meal_plan_agent.json",
)
# User preferences for meal planning
user_preferences = {
"dietary_restrictions": "vegetarian",
"preferred_cuisines": ["Italian", "Indian"],
"caloric_intake": 2000,
"other notes": "Doesn't eat legumes",
}
# Generate Meal Plan
meal_plan_output = meal_plan_agent.run(
f"Generate a meal plan: {user_preferences}"
)
# Vision Agent - Analyze an Image
image_analysis_output = create_vision_agent("full_fridge.jpg")
# Generate Integrated Shopping List
integrated_shopping_list = generate_integrated_shopping_list(
meal_plan_output, image_analysis_output, user_preferences
)
# Print and save the outputs
print("Meal Plan:", meal_plan_output)
print("Integrated Shopping List:", integrated_shopping_list)
with open("nutrition_output.txt", "w") as file:
file.write("Meal Plan:\n" + meal_plan_output + "\n\n")
file.write(
"Integrated Shopping List:\n"
+ integrated_shopping_list
+ "\n"
)
print("Outputs have been saved to nutrition_output.txt")

@ -0,0 +1,15 @@
from swarms.models import vLLM
# Initialize vLLM with custom model and parameters
custom_vllm = vLLM(
model_name="custom/model",
tensor_parallel_size=8,
trust_remote_code=True,
revision="abc123",
temperature=0.7,
top_p=0.8,
)
# Generate text with custom configuration
generated_text = custom_vllm.run("Create a poem about nature.")
print(generated_text)

@ -0,0 +1,40 @@
import os
import subprocess
from dotenv import load_dotenv
from swarms.models import OpenAIChat
from swarms.structs import Agent
# from swarms.utils.phoenix_handler import phoenix_trace_decorator
# import modal
load_dotenv()
# Model
llm = OpenAIChat(
openai_api_key=os.getenv("OPENAI_API_KEY"),
model_name="gpt-4",
max_tokens=1000,
)
# Modal
# stub = modal.Stub(name="swarms")
# Agent
# @phoenix_trace_decorator(
# "This function is an agent and is traced by Phoenix."
# )
# @stub.function(gpu="any")
agent = Agent(
llm=llm,
max_loops=2,
autosave=True,
dashboard=True,
)
out = agent.run(
"Generate a 5,000 word blog on how swarms of autonomous agents"
" can be used to solve the world's problems."
)
print(out)

@ -0,0 +1,31 @@
from swarms.memory import WeaviateClient
weaviate_client = WeaviateClient(
http_host="YOUR_HTTP_HOST",
http_port="YOUR_HTTP_PORT",
http_secure=True,
grpc_host="YOUR_gRPC_HOST",
grpc_port="YOUR_gRPC_PORT",
grpc_secure=True,
auth_client_secret="YOUR_APIKEY",
additional_headers={"X-OpenAI-Api-Key": "YOUR_OPENAI_APIKEY"},
additional_config=None, # You can pass additional configuration here
)
weaviate_client.create_collection(
name="my_collection",
properties=[
{"name": "property1", "dataType": ["string"]},
{"name": "property2", "dataType": ["int"]},
],
vectorizer_config=None, # Optional vectorizer configuration
)
weaviate_client.add(
collection_name="my_collection",
properties={"property1": "value1", "property2": 42},
)
results = weaviate_client.query(
collection_name="people", query="name:John", limit=5
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

@ -0,0 +1,86 @@
from swarms.structs import Agent
import os
from dotenv import load_dotenv
from swarms.models import GPT4VisionAPI
from swarms.prompts.personal_stylist import (
HAIRCUT_STYLIST_AGENT_PROMPT,
MAKEUP_STYLIST_AGENT_PROMPT,
BEARD_STYLIST_AGENT_PROMPT,
CLOTHING_STYLIST_AGENT_PROMPT,
ACCESSORIES_STYLIST_AGENT_PROMPT,
)
# Load environment variables
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
# Initialize GPT4VisionAPI
llm = GPT4VisionAPI(openai_api_key=api_key)
# User selfie and clothes images
user_selfie = "user_image.jpg"
clothes_image = "clothes_image2.jpg"
# User gender (for conditional agent initialization)
user_gender = "man" # or "woman"
# Initialize agents with respective prompts for personal styling
haircut_stylist_agent = Agent(
llm=llm,
sop=HAIRCUT_STYLIST_AGENT_PROMPT,
max_loops=1,
multi_modal=True,
)
# Conditional initialization of Makeup or Beard Stylist Agent
if user_gender == "woman":
makeup_or_beard_stylist_agent = Agent(
llm=llm,
sop=MAKEUP_STYLIST_AGENT_PROMPT,
max_loops=1,
multi_modal=True,
)
elif user_gender == "man":
makeup_or_beard_stylist_agent = Agent(
llm=llm,
sop=BEARD_STYLIST_AGENT_PROMPT,
max_loops=1,
multi_modal=True,
)
clothing_stylist_agent = Agent(
llm=llm,
sop=CLOTHING_STYLIST_AGENT_PROMPT,
max_loops=1,
multi_modal=True,
)
accessories_stylist_agent = Agent(
llm=llm,
sop=ACCESSORIES_STYLIST_AGENT_PROMPT,
max_loops=1,
multi_modal=True,
)
# Run agents with respective tasks
haircut_suggestions = haircut_stylist_agent.run(
"Suggest suitable haircuts for this user, considering their face shape and hair type.", user_selfie
)
# Run Makeup or Beard agent based on gender
if user_gender == "woman":
makeup_suggestions = makeup_or_beard_stylist_agent.run(
"Recommend makeup styles for this user, complementing their features.", user_selfie
)
elif user_gender == "man":
beard_suggestions = makeup_or_beard_stylist_agent.run(
"Provide beard styling advice for this user, considering their face shape.", user_selfie
)
clothing_suggestions = clothing_stylist_agent.run(
"Match clothing styles and colors for this user, using color matching principles.", clothes_image
)
accessories_suggestions = accessories_stylist_agent.run(
"Suggest accessories to complement this user's outfit, considering the overall style.", clothes_image
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

@ -0,0 +1,136 @@
"""
Swarm Agent
Topic selection agent -> draft agent -> review agent -> distribution agent
Topic Selection Agent:
- Generate 10 topics on gaining mental clarity using Taosim and Christian meditation
Draft Agent:
- Write a 100% unique, creative and in human-like style article of a minimum of 5,000 words using headings and sub-headings.
Review Agent:
- Refine the article to meet PositiveMeds stringent publication standards.
Distribution Agent:
- Social Media posts for the article.
# TODO
- Make prompts better
- Add shorter and better topic generator prompt
- Optimize writer prompt to create longer and more enjoyeable blogs
- Use Local Models like Storywriter
"""
import os
from termcolor import colored
from swarms.models import OpenAIChat
from swarms.prompts.autobloggen import (
AUTOBLOG_REVIEW_PROMPT,
DRAFT_AGENT_SYSTEM_PROMPT,
SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT,
TOPIC_GENERATOR_SYSTEM_PROMPT,
)
api_key = os.environ["OPENAI_API_KEY"]
llm = OpenAIChat(openai_api_key=api_key)
def get_review_prompt(article):
prompt = AUTOBLOG_REVIEW_PROMPT.replace("{{ARTICLE}}", article)
return prompt
def social_media_prompt(
article: str, goal: str = "Clicks and engagement"
):
prompt = SOCIAL_MEDIA_SYSTEM_PROMPT_AGENT.replace(
"{{ARTICLE}}", article
).replace("{{GOAL}}", goal)
return prompt
# Agent that generates topics
topic_selection_task = (
"Generate 10 topics on gaining mental clarity using ancient"
" practices"
)
topics = llm(
f"Your System Instructions: {TOPIC_GENERATOR_SYSTEM_PROMPT}, Your"
f" current task: {topic_selection_task}"
)
dashboard = print(
colored(
f"""
Topic Selection Agent
-----------------------------
Topics:
------------------------
{topics}
""",
"blue",
)
)
draft_blog = llm(DRAFT_AGENT_SYSTEM_PROMPT)
draft_out = print(
colored(
f"""
------------------------------------
Drafter Writer Agent
-----------------------------
Draft:
------------------------
{draft_blog}
""",
"red",
)
)
# Agent that reviews the draft
review_agent = llm(get_review_prompt(draft_blog))
reviewed_draft = print(
colored(
f"""
------------------------------------
Quality Assurance Writer Agent
-----------------------------
Complete Narrative:
------------------------
{draft_blog}
""",
"blue",
)
)
# Agent that publishes on social media
distribution_agent = llm(
social_media_prompt(draft_blog, goal="Clicks and engagement")
)
distribution_agent_out = print(
colored(
f"""
--------------------------------
Distribution Agent
-------------------
Social Media Posts
-------------------
{distribution_agent}
""",
"magenta",
)
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

@ -0,0 +1,158 @@
"""
Swarm of multi modal autonomous agents for manufacturing!
---------------------------------------------------------
Health Security agent: Agent that monitors the health of working conditions: input image of factory output: health safety index 0.0 - 1.0 being the highest
Quality Control agent: Agent that monitors the quality of the product: input image of product output: quality index 0.0 - 1.0 being the highest
Productivity agent: Agent that monitors the productivity of the factory: input image of factory output: productivity index 0.0 - 1.0 being the highest
Safety agent: Agent that monitors the safety of the factory: input image of factory output: safety index 0.0 - 1.0 being the highest
Security agent: Agent that monitors the security of the factory: input image of factory output: security index 0.0 - 1.0 being the highest
Sustainability agent: Agent that monitors the sustainability of the factory: input image of factory output: sustainability index 0.0 - 1.0 being the highest
Efficiency agent: Agent that monitors the efficiency of the factory: input image of factory output: efficiency index 0.0 - 1.0 being the highest
Agent:
health security agent -> quality control agent -> productivity agent -> safety agent -> security agent -> sustainability agent -> efficiency agent
"""
import os
from dotenv import load_dotenv
from termcolor import colored
from swarms.models import GPT4VisionAPI
from swarms.structs import Agent
from swarms.utils.phoenix_handler import phoenix_trace_decorator
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
# GPT4VisionAPI
llm = GPT4VisionAPI(openai_api_key=api_key, max_tokens=2000)
assembly_line = (
"playground/demos/swarm_of_mma_manufacturing/assembly_line.jpg"
)
red_robots = (
"playground/demos/swarm_of_mma_manufacturing/red_robots.jpg"
)
robots = "playground/demos/swarm_of_mma_manufacturing/robots.jpg"
tesla_assembly_line = (
"playground/demos/swarm_of_mma_manufacturing/tesla_assembly.jpg"
)
# Define detailed prompts for each agent
tasks = {
"health_safety": (
"Analyze the factory's working environment for health safety."
" Focus on cleanliness, ventilation, spacing between"
" workstations, and personal protective equipment"
" availability."
),
"productivity": (
"Review the factory's workflow efficiency, machine"
" utilization, and employee engagement. Identify operational"
" delays or bottlenecks."
),
"safety": (
"Analyze the factory's safety measures, including fire exits,"
" safety signage, and emergency response equipment."
),
"security": (
"Evaluate the factory's security systems, entry/exit"
" controls, and potential vulnerabilities."
),
"sustainability": (
"Inspect the factory's sustainability practices, including"
" waste management, energy usage, and eco-friendly processes."
),
"efficiency": (
"Assess the manufacturing process's efficiency, considering"
" the layout, logistics, and automation level."
),
}
# Define prompts for each agent
health_safety_prompt = tasks["health_safety"]
productivity_prompt = tasks["productivity"]
safety_prompt = tasks["safety"]
security_prompt = tasks["security"]
sustainability_prompt = tasks["sustainability"]
efficiency_prompt = tasks["efficiency"]
# Health security agent
health_security_agent = Agent(
llm=llm,
sop_list=health_safety_prompt,
max_loops=1,
multi_modal=True,
)
# Quality control agent
productivity_check_agent = Agent(
llm=llm,
sop=productivity_prompt,
max_loops=1,
multi_modal=True,
autosave=True,
)
# Security agent
security_check_agent = Agent(
llm=llm,
sop=security_prompt,
max_loops=1,
multi_modal=True,
autosave=True,
)
# Efficiency agent
efficiency_check_agent = Agent(
llm=llm,
sop=efficiency_prompt,
max_loops=1,
multi_modal=True,
autosave=True,
)
print(colored("Running the agents...", "green"))
print(colored("Running health check agent initializing...", "cyan"))
# Add the first task to the health_security_agent
health_check = health_security_agent.run(
"Analyze the safety of this factory", robots
)
print(
colored(
"--------------- Productivity agents initializing...", "green"
)
)
# Add the third task to the productivity_check_agent
productivity_check = productivity_check_agent.run(
health_check, assembly_line
)
print(
colored(
"--------------- Security agents initializing...", "green"
)
)
# Add the fourth task to the security_check_agent
security_check = security_check_agent.run(
productivity_check, red_robots
)
print(
colored(
"--------------- Efficiency agents initializing...", "cyan"
)
)
# Add the fifth task to the efficiency_check_agent
efficiency_check = efficiency_check_agent.run(
security_check, tesla_assembly_line
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

@ -0,0 +1,84 @@
import os
from dotenv import load_dotenv
from swarms.models import OpenAIChat, GPT4VisionAPI
from swarms.structs import Agent, SequentialWorkflow
import swarms.prompts.urban_planning as upp
# Load environment variables
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
stability_api_key = os.getenv("STABILITY_API_KEY")
# Initialize language model
llm = OpenAIChat(
openai_api_key=api_key, temperature=0.5, max_tokens=3000
)
# Initialize Vision model
vision_api = GPT4VisionAPI(api_key=api_key)
# Initialize agents for urban planning tasks
architecture_analysis_agent = Agent(
llm=llm, max_loops=1, sop=upp.ARCHITECTURE_ANALYSIS_PROMPT
)
infrastructure_evaluation_agent = Agent(
llm=llm, max_loops=1, sop=upp.INFRASTRUCTURE_EVALUATION_PROMPT
)
traffic_flow_analysis_agent = Agent(
llm=llm, max_loops=1, sop=upp.TRAFFIC_FLOW_ANALYSIS_PROMPT
)
environmental_impact_assessment_agent = Agent(
llm=llm,
max_loops=1,
sop=upp.ENVIRONMENTAL_IMPACT_ASSESSMENT_PROMPT,
)
public_space_utilization_agent = Agent(
llm=llm, max_loops=1, sop=upp.PUBLIC_SPACE_UTILIZATION_PROMPT
)
socioeconomic_impact_analysis_agent = Agent(
llm=llm, max_loops=1, sop=upp.SOCIOECONOMIC_IMPACT_ANALYSIS_PROMPT
)
# Initialize the final planning agent
final_plan_agent = Agent(
llm=llm, max_loops=1, sop=upp.FINAL_URBAN_IMPROVEMENT_PLAN_PROMPT
)
# Create Sequential Workflow
workflow = SequentialWorkflow(max_loops=1)
# Add tasks to workflow with personalized prompts
workflow.add(architecture_analysis_agent, "Architecture Analysis")
workflow.add(
infrastructure_evaluation_agent, "Infrastructure Evaluation"
)
workflow.add(traffic_flow_analysis_agent, "Traffic Flow Analysis")
workflow.add(
environmental_impact_assessment_agent,
"Environmental Impact Assessment",
)
workflow.add(
public_space_utilization_agent, "Public Space Utilization"
)
workflow.add(
socioeconomic_impact_analysis_agent,
"Socioeconomic Impact Analysis",
)
workflow.add(
final_plan_agent,
(
"Generate the final urban improvement plan based on all"
" previous agent's findings"
),
)
# Run the workflow for individual analysis tasks
# Execute the workflow for the final planning
workflow.run()
# Output results for each task and the final plan
for task in workflow.tasks:
print(
f"Task Description: {task.description}\nResult:"
f" {task.result}\n"
)

@ -0,0 +1,73 @@
import os
from dotenv import load_dotenv
from swarms.models import GPT4VisionAPI, OpenAIChat
from swarms.prompts.xray_swarm_prompt import (
TREATMENT_PLAN_PROMPT,
XRAY_ANALYSIS_PROMPT,
)
from swarms.structs.agent import Agent
# Load environment variables
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
# Function to analyze an X-ray image
multimodal_llm = GPT4VisionAPI(
openai_api_key=openai_api_key,
)
# Initialize Language Model (LLM)
llm = OpenAIChat(
openai_api_key=openai_api_key,
max_tokens=3000,
)
# Function to analyze an X-ray image
analyze_xray_agent = Agent(
llm=multimodal_llm,
autosave=True,
sop=XRAY_ANALYSIS_PROMPT,
multi_modal=True,
)
# Treatment Plan Agent
treatment_agent = Agent(
llm=multimodal_llm,
autosave=True,
sop=TREATMENT_PLAN_PROMPT,
max_loops=4,
)
# Function to generate a treatment plan
def generate_treatment_plan(diagnosis):
treatment_plan_prompt = TREATMENT_PLAN_PROMPT.format(diagnosis)
# Using the llm object with the 'prompt' argument
return treatment_agent.run(treatment_plan_prompt)
# X-ray Agent - Analyze an X-ray image
xray_image_path = "playground/demos/xray/xray2.jpg"
# Diagnosis
diagnosis = analyze_xray_agent.run(
task="Analyze the following XRAY", img=xray_image_path
)
# Generate Treatment Plan
treatment_plan_output = generate_treatment_plan(diagnosis)
# Print and save the outputs
print("X-ray Analysis:", diagnosis)
print("Treatment Plan:", treatment_plan_output)
with open("medical_analysis_output.txt", "w") as file:
file.write("X-ray Analysis:\n" + diagnosis + "\n\n")
file.write("Treatment Plan:\n" + treatment_plan_output + "\n")
print("Outputs have been saved to medical_analysis_output.txt")

Binary file not shown.

After

Width:  |  Height:  |  Size: 994 KiB

@ -0,0 +1,11 @@
from swarms.memory import chroma
chromadbcl = chroma.ChromaClient()
chromadbcl.add_vectors(
["This is a document", "BONSAIIIIIII", "the walking dead"]
)
results = chromadbcl.search_vectors("zombie", limit=1)
print(results)

@ -0,0 +1,25 @@
from langchain.document_loaders import CSVLoader
from swarms.memory import qdrant
loader = CSVLoader(
file_path="../document_parsing/aipg/aipg.csv",
encoding="utf-8-sig",
)
docs = loader.load()
# Initialize the Qdrant instance
# See qdrant documentation on how to run locally
qdrant_client = qdrant.Qdrant(
host="https://697ea26c-2881-4e17-8af4-817fcb5862e8.europe-west3-0.gcp.cloud.qdrant.io",
collection_name="qdrant",
api_key="BhG2_yINqNU-aKovSEBadn69Zszhbo5uaqdJ6G_qDkdySjAljvuPqQ",
)
qdrant_client.add_vectors(docs)
# Perform a search
search_query = "Who is jojo"
search_results = qdrant_client.search_vectors(search_query)
print("Search Results:")
for result in search_results:
print(result)

@ -2,8 +2,6 @@ from swarms.models.bing_chat import BingChat
from swarms.workers.worker import Worker from swarms.workers.worker import Worker
from swarms.tools.autogpt import EdgeGPTTool, tool from swarms.tools.autogpt import EdgeGPTTool, tool
from swarms.models import OpenAIChat from swarms.models import OpenAIChat
from langchain.llms import VLLM
import os import os
api_key = os.getenv("OPENAI_API_KEY") api_key = os.getenv("OPENAI_API_KEY")
@ -26,7 +24,9 @@ llm = OpenAIChat(
) )
# Initialize the Worker with the custom tool # Initialize the Worker with the custom tool
worker = Worker(llm=llm, ai_name="EdgeGPT Worker", external_tools=[edgegpt]) worker = Worker(
llm=llm, ai_name="EdgeGPT Worker", external_tools=[edgegpt]
)
# Use the worker to process a task # Use the worker to process a task
task = "Hello, my name is ChatGPT" task = "Hello, my name is ChatGPT"

@ -1,6 +1,8 @@
from swarms.models.bioclip import BioClip from swarms.models.bioclip import BioClip
clip = BioClip("hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224") clip = BioClip(
"hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224"
)
labels = [ labels = [
"adenocarcinoma histopathology", "adenocarcinoma histopathology",
@ -15,5 +17,8 @@ labels = [
] ]
result = clip("swarms.jpeg", labels) result = clip("swarms.jpeg", labels)
metadata = {"filename": "images/.jpg".split("/")[-1], "top_probs": result} metadata = {
"filename": "images/.jpg".split("/")[-1],
"top_probs": result,
}
clip.plot_image_with_metadata("swarms.jpeg", metadata) clip.plot_image_with_metadata("swarms.jpeg", metadata)

@ -7,4 +7,6 @@ model_wrapper = DistilWhisperModel()
transcription = model_wrapper("path/to/audio.mp3") transcription = model_wrapper("path/to/audio.mp3")
# For async usage # For async usage
transcription = asyncio.run(model_wrapper.async_transcribe("path/to/audio.mp3")) transcription = asyncio.run(
model_wrapper.async_transcribe("path/to/audio.mp3")
)

@ -2,11 +2,17 @@ from swarms.models import idefics
model = idefics() model = idefics()
user_input = "User: What is in this image? https://upload.wikimedia.org/wikipedia/commons/8/86/Id%C3%A9fix.JPG" user_input = (
"User: What is in this image?"
" https://upload.wikimedia.org/wikipedia/commons/8/86/Id%C3%A9fix.JPG"
)
response = model.chat(user_input) response = model.chat(user_input)
print(response) print(response)
user_input = "User: And who is that? https://static.wikia.nocookie.net/asterix/images/2/25/R22b.gif/revision/latest?cb=20110815073052" user_input = (
"User: And who is that?"
" https://static.wikia.nocookie.net/asterix/images/2/25/R22b.gif/revision/latest?cb=20110815073052"
)
response = model.chat(user_input) response = model.chat(user_input)
print(response) print(response)

@ -28,7 +28,9 @@ llama_caller.add_func(
) )
# Call the function # Call the function
result = llama_caller.call_function("get_weather", location="Paris", format="Celsius") result = llama_caller.call_function(
"get_weather", location="Paris", format="Celsius"
)
print(result) print(result)
# Stream a user prompt # Stream a user prompt

@ -1,7 +1,9 @@
from swarms.models.mpt import MPT from swarms.models.mpt import MPT
mpt_instance = MPT( mpt_instance = MPT(
"mosaicml/mpt-7b-storywriter", "EleutherAI/gpt-neox-20b", max_tokens=150 "mosaicml/mpt-7b-storywriter",
"EleutherAI/gpt-neox-20b",
max_tokens=150,
) )
mpt_instance.generate("Once upon a time in a land far, far away...") mpt_instance.generate("Once upon a time in a land far, far away...")

@ -2,4 +2,4 @@ from swarms.models.nougat import Nougat
nougat = Nougat() nougat = Nougat()
out = nougat("path/to/image.png") out = nougat("large.png")

@ -3,5 +3,6 @@ from swarms.models.vilt import Vilt
model = Vilt() model = Vilt()
output = model( output = model(
"What is this image", "http://images.cocodataset.org/val2017/000000039769.jpg" "What is this image",
"http://images.cocodataset.org/val2017/000000039769.jpg",
) )

@ -0,0 +1,77 @@
"""
tool decorated func [search_api] -> agent which parses the docs of the tool func
-> injected into prompt -> agent will output json containing tool usage -> agent output will be parsed -> tool executed
-> terminal response can be returned to agent for self-healing
"""
import os
from dotenv import load_dotenv
# Import the OpenAIChat model and the Agent struct
from swarms.models import OpenAIChat
from swarms.structs import Agent
from swarms.tools.tool import tool
# Load the environment variables
load_dotenv()
# Define a tool
@tool
def search_api(query: str, description: str):
"""Search the web for the query
Args:
query (str): _description_
Returns:
_type_: _description_
"""
return f"Search results for {query}"
@tool
def weather_api(
query: str,
):
"""_summary_
Args:
query (str): _description_
"""
print(f"Getting the weather for {query}")
@tool
def rapid_api(query: str):
"""_summary_
Args:
query (str): _description_
"""
print(f"Getting the weather for {query}")
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
openai_api_key=api_key,
)
## Initialize the workflow
agent = Agent(
llm=llm, max_loops=1, dashboard=True, tools=[search_api]
)
# Run the workflow on a task
out = agent.run("Generate a 10,000 word blog on health and wellness.")
print(out)

@ -0,0 +1,46 @@
import os
from dotenv import load_dotenv
# Import the OpenAIChat model and the Agent struct
from swarms.models import OpenAIChat
from swarms.structs import Agent
from swarms.structs.autoscaler import AutoScaler
# Load the environment variables
load_dotenv()
# Get the API key from the environment
api_key = os.environ.get("OPENAI_API_KEY")
# Initialize the language model
llm = OpenAIChat(
temperature=0.5,
openai_api_key=api_key,
)
## Initialize the workflow
agent = Agent(llm=llm, max_loops=1, dashboard=True)
# Load the autoscaler
autoscaler = AutoScaler(
initial_agents=2,
scale_up_factor=1,
idle_threshold=0.2,
busy_threshold=0.7,
agents=[agent],
autoscale=True,
min_agents=1,
max_agents=5,
custom_scale_strategy=None,
)
print(autoscaler)
# Run the workflow on a task
out = autoscaler.run(
agent.id, "Generate a 10,000 word blog on health and wellness."
)
print(out)

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save