Skip to main content

Swarm Models

Join our Discord Subscribe on YouTube Connect on LinkedIn Follow on X.com

Swarm Models provides a unified, secure, and highly scalable interface for interacting with multiple LLM and multi-modal APIs across different providers. It is built to streamline your API integrations, ensuring production-grade reliability and robust performance.

Key Features:

  • Multi-Provider Support: Integrate seamlessly with APIs from OpenAI, Anthropic, Azure, and more.

  • Enterprise-Grade Security: Built-in security protocols to protect your API keys and sensitive data, ensuring compliance with industry standards.

  • Lightning-Fast Performance: Optimized for low-latency and high-throughput, Swarm Models delivers blazing-fast API responses, suitable for real-time applications.

  • Ease of Use: Simplified API interaction with intuitive .run(task) and __call__ methods, making integration effortless.

  • Scalability for All Use Cases: Whether it's a small script or a massive enterprise-scale application, Swarm Models scales effortlessly.

  • Production-Grade Reliability: Tested and proven in enterprise environments, ensuring consistent uptime and failover capabilities.


Onboarding

Swarm Models simplifies the way you interact with different APIs by providing a unified interface for all models.

1. Install Swarm Models

$ pip3 install -U swarm-models

2. Set Your Keys

OPENAI_API_KEY="your_openai_api_key"
GROQ_API_KEY="your_groq_api_key"
ANTHROPIC_API_KEY="your_anthropic_api_key"
AZURE_OPENAI_API_KEY="your_azure_openai_api_key"

3. Initialize a Model

Import the desired model from the package and initialize it with your API key or necessary configuration.

from swarm_models import YourDesiredModel

model = YourDesiredModel(api_key='your_api_key', *args, **kwargs)

4. Run Your Task

Use the .run(task) method or simply call the model like model(task) with your task.

task = "Define your task here"
result = model.run(task)

# Or equivalently
#result = model(task)

5. Enjoy the Results

print(result)

Full Code Example

from swarm_models import OpenAIChat
import os

# Get the OpenAI API key from the environment variable
api_key = os.getenv("OPENAI_API_KEY")

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

# Query the model with a question
out = model(
   "What is the best state to register a business in the US for the least amount of taxes?"
)

# Print the model's response
print(out)

TogetherLLM Documentation

The TogetherLLM class is designed to simplify the interaction with Together's LLM models. It provides a straightforward way to run tasks on these models, including support for concurrent and batch processing.

Initialization

To use TogetherLLM, you need to initialize it with your API key, the name of the model you want to use, and optionally, a system prompt. The system prompt is used to provide context to the model for the tasks you will run.

Here's an example of how to initialize TogetherLLM:

import os
from swarm_models import TogetherLLM

model_runner = TogetherLLM(
    api_key=os.environ.get("TOGETHER_API_KEY"),
    model_name="meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
    system_prompt="You're Larry fink",
)

Running Tasks

Once initialized, you can run tasks on the model using the run method. This method takes a task string as an argument and returns the response from the model.

Here's an example of running a single task:

task = "How do we allocate capital efficiently in your opinion Larry?"
response = model_runner.run(task)
print(response)

Running Multiple Tasks Concurrently

TogetherLLM also supports running multiple tasks concurrently using the run_concurrently method. This method takes a list of task strings and returns a list of responses from the model.

Here's an example of running multiple tasks concurrently:

tasks = [
    "What are the top-performing mutual funds in the last quarter?",
    "How do I evaluate the risk of a mutual fund?",
    "What are the fees associated with investing in a mutual fund?",
    "Can you recommend a mutual fund for a beginner investor?",
    "How do I diversify my portfolio with mutual funds?",
]
responses = model_runner.run_concurrently(tasks)
for response in responses:
    print(response)

Enterprise-Grade Features

  1. Security: API keys and user data are handled with utmost care, utilizing encryption and best security practices to protect your sensitive information.

  2. Production Reliability: Swarm Models has undergone rigorous testing to ensure that it can handle high traffic and remains resilient in enterprise-grade environments.

  3. Fail-Safe Mechanisms: Built-in failover handling to ensure uninterrupted service even under heavy load or network issues.

  4. Unified API: No more dealing with multiple SDKs or libraries. Swarm Models standardizes your interactions across providers like OpenAI, Anthropic, Azure, and more, so you can focus on what matters.


Available Models

Model Name Import Path
BaseLLM from swarm_models.base_llm import BaseLLM
BaseMultiModalModel from swarm_models.base_multimodal_model import BaseMultiModalModel
GPT4VisionAPI from swarm_models.gpt4_vision_api import GPT4VisionAPI
HuggingfaceLLM from swarm_models.huggingface import HuggingfaceLLM
LayoutLMDocumentQA from swarm_models.layoutlm_document_qa import LayoutLMDocumentQA
llama3Hosted from swarm_models.llama3_hosted import llama3Hosted
LavaMultiModal from swarm_models.llava import LavaMultiModal
Nougat from swarm_models.nougat import Nougat
OpenAIEmbeddings from swarm_models.openai_embeddings import OpenAIEmbeddings
OpenAITTS from swarm_models.openai_tts import OpenAITTS
GooglePalm from swarm_models.palm import GooglePalm as Palm
Anthropic from swarm_models.popular_llms import Anthropic as Anthropic
AzureOpenAI from swarm_models.popular_llms import AzureOpenAILLM as AzureOpenAI
Cohere from swarm_models.popular_llms import CohereChat as Cohere
OctoAIChat from swarm_models.popular_llms import OctoAIChat
OpenAIChat from swarm_models.popular_llms import OpenAIChatLLM as OpenAIChat
OpenAILLM from swarm_models.popular_llms import OpenAILLM as OpenAI
Replicate from swarm_models.popular_llms import ReplicateChat as Replicate
QwenVLMultiModal from swarm_models.qwen import QwenVLMultiModal
FireWorksAI from swarm_models.popular_llms import FireWorksAI
Vilt from swarm_models.vilt import Vilt
TogetherLLM from swarm_models.together_llm import TogetherLLM
LiteLLM from swarm_models.lite_llm_model import LiteLLM
OpenAIFunctionCaller from swarm_models.openai_function_caller import OpenAIFunctionCaller
OllamaModel from swarm_models.ollama_model import OllamaModel
GroundedSAMTwo from swarm_models.sam_two import GroundedSAMTwo

Support & Contributions

  • Documentation: Comprehensive guides, API references, and best practices are available in our official Documentation.
  • GitHub: Explore the code, report issues, and contribute to the project via our GitHub repository.

License

Swarm Models is released under the MIT License.


Todo

  • Add cohere models command r
  • Add gemini and google ai studio
  • Integrate ollama extensively

Release files for swarm-models 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarm-models 0.3.2
File Size Uploaded
swarm_models-0.3.2.tar.gz 57.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for swarm-models 0.3.2
File Interpreter ABI Platform
swarm_models-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 130.7 kB

Release files / swarm_models-0.3.2.tar.gz

Download URL swarm_models-0.3.2.tar.gz
Size 57.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a75ad3946600be32521e6fafcc0ba6249d3ea3274774260242e0d7c99aab92ad
BLAKE2b-256 checksum
How to use checksums
611f1bd8f98b6ad7d1250601e8ba2ecf97e42e95c183b7a508e0afff3594a589
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Darwin/23.3.0

Release files / swarm_models-0.3.2-py3-none-any.whl

Download URL swarm_models-0.3.2-py3-none-any.whl
Size 73.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76271fb42febb05eeda0cc9b71ac6cd6ac20bdb0506a8f0c68b5ae21f069449f
BLAKE2b-256 checksum
How to use checksums
14d29d59ec1383264a5e6a57528c07ebb4ee3ced7d34b66db0b64029b2eb4bfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.8 Darwin/23.3.0

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.9

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page