parent
b148d8f48a
commit
dceef99bc6
@ -1,51 +0,0 @@
|
||||
import logging
|
||||
import os
|
||||
from fastapi import FastAPI, HTTPException, Depends
|
||||
from fastapi_cache.decorator import cache
|
||||
from fastapi_cache.coder import JsonCoder
|
||||
|
||||
from fastapi_cache import FastAPICache
|
||||
from fastapi_cache.backends.redis import RedisBackend
|
||||
from aioredis import Redis
|
||||
|
||||
from pydantic import BaseModel
|
||||
from swarms.swarms.swarms import swarm
|
||||
from fastapi_limiter import FastAPILimiter
|
||||
|
||||
from fastapi_limiter.depends import RateLimiter
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class SwarmInput(BaseModel):
|
||||
api_key: str
|
||||
objective: str
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
redis_host = os.getenv("REDIS_HOST", "localhost")
|
||||
redis_port = int(os.getenv("REDIS_PORT", 6379))
|
||||
redis = await Redis.create(redis_host, redis_port)
|
||||
FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache", coder=JsonCoder())
|
||||
await FastAPILimiter.init(f"redis://{redis_host}:{redis_port}")
|
||||
|
||||
|
||||
@app.post("/chat", dependencies=[Depends(RateLimiter(times=2, minutes=1))])
|
||||
@cache(expire=60) # Cache results for 1 minute
|
||||
async def run(swarm_input: SwarmInput):
|
||||
try:
|
||||
results = swarm(swarm_input.api_key, swarm_input.objective)
|
||||
if not results:
|
||||
raise HTTPException(status_code=500, detail="Failed to run swarms")
|
||||
return {"results": results}
|
||||
except ValueError as ve:
|
||||
logging.error("A ValueError occurred", exc_info=True)
|
||||
raise HTTPException(status_code=400, detail=str(ve))
|
||||
except Exception:
|
||||
logging.error("An error occurred", exc_info=True)
|
||||
raise HTTPException(status_code=500, detail="An unexpected error occurred")
|
@ -1,60 +0,0 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from swarms.agents.utils.agent_creator import AgentManager
|
||||
from swarms.utils.main import BaseHandler, FileHandler, FileType
|
||||
from swarms.tools.main import ExitConversation, RequestsGet, CodeEditor, Terminal
|
||||
|
||||
from swarms.utils.main import CsvToDataframe
|
||||
|
||||
from swarms.tools.main import BaseToolSet
|
||||
|
||||
from swarms.utils.main import StaticUploader
|
||||
|
||||
BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
os.chdir(BASE_DIR / os.environ["PLAYGROUND_DIR"])
|
||||
|
||||
#
|
||||
toolsets: List[BaseToolSet] = [
|
||||
Terminal(),
|
||||
CodeEditor(),
|
||||
RequestsGet(),
|
||||
ExitConversation(),
|
||||
]
|
||||
handlers: Dict[FileType, BaseHandler] = {FileType.DATAFRAME: CsvToDataframe()}
|
||||
|
||||
if os.environ["USE_GPU"]:
|
||||
import torch
|
||||
|
||||
# from core.handlers.image import ImageCaptioning
|
||||
from swarms.tools.main import ImageCaptioning
|
||||
from swarms.tools.main import (
|
||||
ImageEditing,
|
||||
InstructPix2Pix,
|
||||
Text2Image,
|
||||
VisualQuestionAnswering,
|
||||
)
|
||||
|
||||
if torch.cuda.is_available():
|
||||
toolsets.extend(
|
||||
[
|
||||
Text2Image("cuda"),
|
||||
ImageEditing("cuda"),
|
||||
InstructPix2Pix("cuda"),
|
||||
VisualQuestionAnswering("cuda"),
|
||||
]
|
||||
)
|
||||
handlers[FileType.IMAGE] = ImageCaptioning("cuda")
|
||||
|
||||
agent_manager = AgentManager.create(toolsets=toolsets)
|
||||
|
||||
file_handler = FileHandler(handlers=handlers, path=BASE_DIR)
|
||||
|
||||
templates = Jinja2Templates(directory=BASE_DIR / "api" / "templates")
|
||||
|
||||
uploader = StaticUploader.from_settings(path=BASE_DIR / "static", endpoint="static")
|
||||
|
||||
reload_dirs = [BASE_DIR / "core", BASE_DIR / "api"]
|
@ -1,137 +0,0 @@
|
||||
import os
|
||||
|
||||
import re
|
||||
from multiprocessing import Process
|
||||
from tempfile import NamedTemporaryFile
|
||||
from typing import List, TypedDict
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, Request, UploadFile
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from pydantic import BaseModel
|
||||
|
||||
from api.olds.container import (
|
||||
agent_manager,
|
||||
file_handler,
|
||||
reload_dirs,
|
||||
templates,
|
||||
uploader,
|
||||
)
|
||||
from api.olds.worker import get_task_result, start_worker, task_execute
|
||||
|
||||
# from env import settings
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
app.mount("/static", StaticFiles(directory=uploader.path), name="static")
|
||||
|
||||
|
||||
class ExecuteRequest(BaseModel):
|
||||
session: str
|
||||
prompt: str
|
||||
files: List[str]
|
||||
|
||||
|
||||
class ExecuteResponse(TypedDict):
|
||||
answer: str
|
||||
files: List[str]
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request):
|
||||
return templates.TemplateResponse("index.html", {"request": request})
|
||||
|
||||
|
||||
@app.get("/dashboard", response_class=HTMLResponse)
|
||||
async def dashboard(request: Request):
|
||||
return templates.TemplateResponse("dashboard.html", {"request": request})
|
||||
|
||||
|
||||
@app.post("/upload")
|
||||
async def create_upload_file(files: List[UploadFile]):
|
||||
urls = []
|
||||
for file in files:
|
||||
extension = "." + file.filename.split(".")[-1]
|
||||
with NamedTemporaryFile(suffix=extension) as tmp_file:
|
||||
tmp_file.write(file.file.read())
|
||||
tmp_file.flush()
|
||||
urls.append(uploader.upload(tmp_file.name))
|
||||
return {"urls": urls}
|
||||
|
||||
|
||||
@app.post("/api/execute")
|
||||
async def execute(request: ExecuteRequest) -> ExecuteResponse:
|
||||
query = request.prompt
|
||||
files = request.files
|
||||
session = request.session
|
||||
|
||||
executor = agent_manager.create_executor(session)
|
||||
|
||||
promptedQuery = "\n".join([file_handler.handle(file) for file in files])
|
||||
promptedQuery += query
|
||||
|
||||
try:
|
||||
res = executor({"input": promptedQuery})
|
||||
except Exception as e:
|
||||
return {"answer": str(e), "files": []}
|
||||
|
||||
files = re.findall(r"\[file://\S*\]", res["output"])
|
||||
files = [file[1:-1].split("file://")[1] for file in files]
|
||||
|
||||
return {
|
||||
"answer": res["output"],
|
||||
"files": [uploader.upload(file) for file in files],
|
||||
}
|
||||
|
||||
|
||||
@app.post("/api/execute/async")
|
||||
async def execute_async(request: ExecuteRequest):
|
||||
query = request.prompt
|
||||
files = request.files
|
||||
session = request.session
|
||||
|
||||
promptedQuery = "\n".join([file_handler.handle(file) for file in files])
|
||||
promptedQuery += query
|
||||
|
||||
execution = task_execute.delay(session, promptedQuery)
|
||||
return {"id": execution.id}
|
||||
|
||||
|
||||
@app.get("/api/execute/async/{execution_id}")
|
||||
async def execute_async(execution_id: str):
|
||||
execution = get_task_result(execution_id)
|
||||
|
||||
result = {}
|
||||
if execution.status == "SUCCESS" and execution.result:
|
||||
output = execution.result.get("output", "")
|
||||
files = re.findall(r"\[file://\S*\]", output)
|
||||
files = [file[1:-1].split("file://")[1] for file in files]
|
||||
result = {
|
||||
"answer": output,
|
||||
"files": [uploader.upload(file) for file in files],
|
||||
}
|
||||
|
||||
return {
|
||||
"status": execution.status,
|
||||
"info": execution.info,
|
||||
"result": result,
|
||||
}
|
||||
|
||||
|
||||
def serve():
|
||||
p = Process(target=start_worker, args=[])
|
||||
p.start()
|
||||
uvicorn.run("api.main:app", host="0.0.0.0", port=os.environ["EVAL_PORT"])
|
||||
|
||||
|
||||
def dev():
|
||||
p = Process(target=start_worker, args=[])
|
||||
p.start()
|
||||
uvicorn.run(
|
||||
"api.main:app",
|
||||
host="0.0.0.0",
|
||||
port=os.environ["EVAL_PORT"],
|
||||
reload=True,
|
||||
reload_dirs=reload_dirs,
|
||||
)
|
@ -1,44 +0,0 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
from celery.result import AsyncResult
|
||||
|
||||
from api.olds.container import agent_manager
|
||||
|
||||
|
||||
celery_app = Celery(__name__)
|
||||
celery_app.conf.broker_url = os.environ["CELERY_BROKER_URL"]
|
||||
celery_app.conf.result_backend = os.environ["CELERY_BROKER_URL"]
|
||||
celery_app.conf.update(
|
||||
task_track_started=True,
|
||||
task_serializer="json",
|
||||
accept_content=["json"], # Ignore other content
|
||||
result_serializer="json",
|
||||
enable_utc=True,
|
||||
)
|
||||
|
||||
|
||||
@celery_app.task(name="task_execute", bind=True)
|
||||
def task_execute(self, session: str, prompt: str):
|
||||
executor = agent_manager.create_executor(session, self)
|
||||
response = executor({"input": prompt})
|
||||
result = {"output": response["output"]}
|
||||
|
||||
previous = AsyncResult(self.request.id)
|
||||
if previous and previous.info:
|
||||
result.update(previous.info)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_task_result(task_id):
|
||||
return AsyncResult(task_id)
|
||||
|
||||
|
||||
def start_worker():
|
||||
celery_app.worker_main(
|
||||
[
|
||||
"worker",
|
||||
"--loglevel=INFO",
|
||||
]
|
||||
)
|
@ -1,52 +0,0 @@
|
||||
# This is a basic Dockerfile and might need to be adjusted according to your specific application's needs. Please replace the placeholders for environment variables with your actual keys. Also, remember not to expose sensitive data like API keys in your Dockerfile or any version control systems.
|
||||
|
||||
# When building and running this Docker container, be sure to allocate enough resources (especially GPU memory) for your chosen visual foundation model if running on a machine with an NVIDIA GPU. You may need to use nvidia-docker or Docker's --gpus option when running the container. The GPU memory usage you provided would be valuable for this purpose.
|
||||
|
||||
# It's important to note that Docker inherently does not fully support GPUs. As a result, running GPU-accelerated code within Docker requires a special runtime like NVIDIA Docker. For more complex orchestration, a platform like Kubernetes can be more effective.
|
||||
|
||||
# Lastly, since your application seems to be using Redis (CELERY_BROKER_URL), you might need to set up a separate Redis service as well. This can be accomplished by creating a multi-container Docker application using Docker Compose or Kubernetes.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.10
|
||||
|
||||
# Set environment variables
|
||||
ENV EVAL_PORT=8000 \
|
||||
MODEL_NAME=gpt-4 \
|
||||
CELERY_BROKER_URL=redis://localhost:6379 \
|
||||
SERVER=http://localhost:${EVAL_PORT} \
|
||||
USE_GPU=False \
|
||||
PLAYGROUND_DIR=playground \
|
||||
LOG_LEVEL=INFO \
|
||||
BOT_NAME=Swarm \
|
||||
# You will need to set these environment variables to your actual keys in production
|
||||
OPENAI_API_KEY=your_openai_api_key \
|
||||
WINEDB_HOST=your_winedb_host \
|
||||
WINEDB_PASSWORD=your_winedb_password \
|
||||
BING_SEARCH_URL=your_bing_search_url \
|
||||
BING_SUBSCRIPTION_KEY=your_bing_subscription_key \
|
||||
SERPAPI_API_KEY=your_serpapi_api_key \
|
||||
REDIS_HOST=your_redis_host \
|
||||
REDIS_PORT=your_redis_port
|
||||
|
||||
# Set work directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Add requirements file
|
||||
COPY requirements.txt ./
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE ${EVAL_PORT}
|
||||
|
||||
# Run the application
|
||||
CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
@ -1,48 +0,0 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM nvidia/cuda:11.7.0-runtime-ubuntu20.04
|
||||
|
||||
# Set environment variables
|
||||
ENV EVAL_PORT=8000 \
|
||||
MODEL_NAME=gpt-4 \
|
||||
CELERY_BROKER_URL=redis://localhost:6379 \
|
||||
SERVER=http://localhost:${EVAL_PORT} \
|
||||
USE_GPU=True \
|
||||
PLAYGROUND_DIR=playground \
|
||||
LOG_LEVEL=INFO \
|
||||
BOT_NAME=Orca \
|
||||
# You will need to set these environment variables to your actual keys in production
|
||||
OPENAI_API_KEY=your_openai_api_key \
|
||||
WINEDB_HOST=your_winedb_host \
|
||||
WINEDB_PASSWORD=your_winedb_password \
|
||||
BING_SEARCH_URL=your_bing_search_url \
|
||||
BING_SUBSCRIPTION_KEY=your_bing_subscription_key \
|
||||
SERPAPI_API_KEY=your_serpapi_api_key \
|
||||
REDIS_HOST=your_redis_host \
|
||||
REDIS_PORT=your_redis_port
|
||||
|
||||
# Set work directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install system dependencies
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && \
|
||||
apt-get install -y software-properties-common && \
|
||||
add-apt-repository ppa:deadsnakes/ppa && \
|
||||
apt-get install -y python3.10 python3-pip curl && \
|
||||
apt-get install -y nodejs npm
|
||||
|
||||
# Add requirements file
|
||||
COPY requirements.txt ./
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN python3.10 -m pip install --upgrade pip && \
|
||||
python3.10 -m pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
# Expose port
|
||||
EXPOSE ${EVAL_PORT}
|
||||
|
||||
# Run the application
|
||||
CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
@ -1,32 +0,0 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
swarms:
|
||||
build: .
|
||||
ports:
|
||||
- "${SWARMS_PORT}:${SWARMS_PORT}"
|
||||
environment:
|
||||
SWARMS_PORT: 8000
|
||||
MODEL_NAME: gpt-4
|
||||
CELERY_BROKER_URL: redis://redis:6379
|
||||
SERVER: http://localhost:${SWARMS_PORT}
|
||||
USE_GPU: False
|
||||
PLAYGROUND_DIR: playground
|
||||
LOG_LEVEL: INFO
|
||||
BOT_NAME: Orca
|
||||
# You will need to set these environment variables to your actual keys in production
|
||||
OPENAI_API_KEY: your_openai_api_key
|
||||
WINEDB_HOST: your_winedb_host
|
||||
WINEDB_PASSWORD: your_winedb_password
|
||||
BING_SEARCH_URL: your_bing_search_url
|
||||
BING_SUBSCRIPTION_KEY: your_bing_subscription_key
|
||||
SERPAPI_API_KEY: your_serpapi_api_key
|
||||
depends_on:
|
||||
- redis
|
||||
volumes:
|
||||
- .:/usr/src/app
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
ports:
|
||||
- 6379:6379
|
@ -1,42 +0,0 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: swarms-deployment
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: swarms
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: swarms
|
||||
spec:
|
||||
containers:
|
||||
- name: swarms
|
||||
image: your_dockerhub_username/swarms:latest
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
env:
|
||||
- name: EVAL_PORT
|
||||
value: "8000"
|
||||
- name: MODEL_NAME
|
||||
value: "gpt-4"
|
||||
- name: CELERY_BROKER_URL
|
||||
value: "redis://redis:6379"
|
||||
- name: SERVER
|
||||
value: "http://localhost:8000"
|
||||
- name: USE_GPU
|
||||
value: "False"
|
||||
- name: PLAYGROUND_DIR
|
||||
value: "playground"
|
||||
- name: LOG_LEVEL
|
||||
value: "INFO"
|
||||
- name: BOT_NAME
|
||||
value: "Orca"
|
||||
- name: OPENAI_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: openai-secret
|
||||
key: OPENAI_API_KEY
|
||||
# Other environment variables
|
@ -1,12 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: swarms-service
|
||||
spec:
|
||||
selector:
|
||||
app: swarms
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 8000
|
||||
type: LoadBalancer
|
@ -1,208 +0,0 @@
|
||||
To create a Terraform configuration for deploying the Swarm application on an AWS EC2 instance with a T4 GPU, you would typically need the following resources:
|
||||
|
||||
1. **AWS Provider:** This is needed to configure the AWS resources.
|
||||
2. **AWS Key Pair:** This is required for SSH access to the EC2 instances.
|
||||
3. **Security Group:** This defines the firewall rules for your instances.
|
||||
4. **EC2 Instance:** This is where you deploy your application. Be sure to choose an instance type that supports T4 GPUs (like `g4dn.xlarge` for example).
|
||||
5. **IAM Role and Policy:** These are optional but recommended for managing permissions.
|
||||
|
||||
The Terraform configuration file(s) should be written in HashiCorp Configuration Language (HCL). The conventional file extension is `.tf`.
|
||||
|
||||
Here's an example of what the Terraform configuration might look like:
|
||||
|
||||
```hcl
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "deployer" {
|
||||
key_name = "deployer-key"
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}
|
||||
|
||||
resource "aws_security_group" "swarm-sg" {
|
||||
name = "swarm-sg"
|
||||
description = "Security group for Swarm app"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
ingress {
|
||||
from_port = 8000
|
||||
to_port = 8000
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_instance" "swarm" {
|
||||
ami = "ami-0c94855ba95c574c8" # Update this with the correct AMI ID
|
||||
instance_type = "g4dn.xlarge"
|
||||
key_name = aws_key_pair.deployer.key_name
|
||||
|
||||
vpc_security_group_ids = [aws_security_group.swarm-sg.id]
|
||||
|
||||
tags = {
|
||||
Name = "SwarmInstance"
|
||||
}
|
||||
|
||||
user_data = <<-EOF
|
||||
#!/bin/bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io
|
||||
sudo docker pull your_docker_image_name
|
||||
sudo docker run -d -p 8000:8000 your_docker_image_name
|
||||
EOF
|
||||
}
|
||||
```
|
||||
|
||||
Please replace the `"ami-0c94855ba95c574c8"` with the correct AMI ID for your desired operating system and `"your_docker_image_name"` with the name of your Docker image.
|
||||
|
||||
This is a simple configuration and may not cover all your requirements. You might need to modify this to fit your needs, such as adding persistent storage (EBS volumes), load balancers, auto scaling groups, etc.
|
||||
|
||||
Remember to install Terraform and initialize it in your working directory using `terraform init` before running `terraform apply` to create the resources. Also, ensure your AWS credentials are correctly set up in your environment.
|
||||
|
||||
|
||||
|
||||
Incorporating persistent storage, load balancers, and auto scaling will make our Terraform configuration significantly more complex. Below is a skeleton of what the configuration might look like:
|
||||
|
||||
```hcl
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
data "aws_ami" "ubuntu" {
|
||||
most_recent = true
|
||||
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
|
||||
}
|
||||
|
||||
filter {
|
||||
name = "virtualization-type"
|
||||
values = ["hvm"]
|
||||
}
|
||||
|
||||
owners = ["099720109477"]
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "deployer" {
|
||||
key_name = "deployer-key"
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}
|
||||
|
||||
resource "aws_security_group" "swarm-sg" {
|
||||
name = "swarm-sg"
|
||||
description = "Security group for Swarm app"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
ingress {
|
||||
from_port = 8000
|
||||
to_port = 8000
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_launch_configuration" "swarm" {
|
||||
name = "swarm-configuration"
|
||||
image_id = data.aws_ami.ubuntu.id
|
||||
instance_type = "g4dn.xlarge"
|
||||
key_name = aws_key_pair.deployer.key_name
|
||||
|
||||
security_groups = [aws_security_group.swarm-sg.id]
|
||||
|
||||
user_data = <<-EOF
|
||||
#!/bin/bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io
|
||||
sudo docker pull your_docker_image_name
|
||||
sudo docker run -d -p 8000:8000 your_docker_image_name
|
||||
EOF
|
||||
|
||||
root_block_device {
|
||||
volume_type = "gp2"
|
||||
volume_size = 30 # size in GBs
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_group" "swarm" {
|
||||
name_prefix = "swarm-asg"
|
||||
max_size = 5
|
||||
min_size = 1
|
||||
desired_capacity = 1
|
||||
launch_configuration = aws_launch_configuration.swarm.id
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_elb" "swarm" {
|
||||
name = "swarm-elb"
|
||||
subnets = ["subnet-id1", "subnet-id2"]
|
||||
|
||||
listener {
|
||||
instance_port = 8000
|
||||
instance_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
}
|
||||
|
||||
health_check {
|
||||
healthy_threshold = 2
|
||||
unhealthy_threshold = 2
|
||||
timeout = 3
|
||||
target = "HTTP:8000/"
|
||||
interval = 30
|
||||
}
|
||||
|
||||
instances = [aws_instance.swarm.id]
|
||||
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
connection_draining_timeout = 400
|
||||
}
|
||||
```
|
||||
|
||||
In this example, the `aws_launch_configuration` sets up the details
|
||||
|
||||
for launching new instances, including attaching an EBS volume for persistent storage. The `aws_autoscaling_group` uses this configuration to scale instances up and down as required.
|
||||
|
||||
The `aws_elb` resource creates a load balancer that distributes incoming traffic across all the instances in the autoscaling group. The `health_check` block inside `aws_elb` is used to check the health of the instances. If an instance fails the health check, it is replaced by the autoscaling group.
|
||||
|
||||
Please replace `"subnet-id1"` and `"subnet-id2"` with your actual subnet IDs and `"your_docker_image_name"` with the name of your Docker image.
|
||||
|
||||
Again, note that this is a simplified example and may need to be adjusted to suit your particular use case. For instance, this configuration assumes that you are using a single security group for all instances, which might not be the best setup for a real-world scenario.
|
||||
|
||||
Before running this Terraform configuration, make sure to initialize Terraform in your working directory using `terraform init`, and ensure that your AWS credentials are correctly set up in your environment.
|
@ -1,115 +0,0 @@
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
data "aws_ami" "ubuntu" {
|
||||
most_recent = true
|
||||
|
||||
filter {
|
||||
name = "name"
|
||||
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
|
||||
}
|
||||
|
||||
filter {
|
||||
name = "virtualization-type"
|
||||
values = ["hvm"]
|
||||
}
|
||||
|
||||
owners = ["099720109477"]
|
||||
}
|
||||
|
||||
resource "aws_key_pair" "deployer" {
|
||||
key_name = "deployer-key"
|
||||
public_key = file("~/.ssh/id_rsa.pub")
|
||||
}
|
||||
|
||||
resource "aws_security_group" "swarm-sg" {
|
||||
name = "swarm-sg"
|
||||
description = "Security group for Swarm app"
|
||||
|
||||
ingress {
|
||||
from_port = 22
|
||||
to_port = 22
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
ingress {
|
||||
from_port = 8000
|
||||
to_port = 8000
|
||||
protocol = "tcp"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
|
||||
egress {
|
||||
from_port = 0
|
||||
to_port = 0
|
||||
protocol = "-1"
|
||||
cidr_blocks = ["0.0.0.0/0"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_launch_configuration" "swarm" {
|
||||
name = "swarm-configuration"
|
||||
image_id = data.aws_ami.ubuntu.id
|
||||
instance_type = "g4dn.xlarge"
|
||||
key_name = aws_key_pair.deployer.key_name
|
||||
|
||||
security_groups = [aws_security_group.swarm-sg.id]
|
||||
|
||||
user_data = <<-EOF
|
||||
#!/bin/bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker.io
|
||||
sudo docker pull your_docker_image_name
|
||||
sudo docker run -d -p 8000:8000 your_docker_image_name
|
||||
EOF
|
||||
|
||||
root_block_device {
|
||||
volume_type = "gp2"
|
||||
volume_size = 30 # size in GBs
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_group" "swarm" {
|
||||
name_prefix = "swarm-asg"
|
||||
max_size = 5
|
||||
min_size = 1
|
||||
desired_capacity = 1
|
||||
launch_configuration = aws_launch_configuration.swarm.id
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_elb" "swarm" {
|
||||
name = "swarm-elb"
|
||||
subnets = ["subnet-id1", "subnet-id2"]
|
||||
|
||||
listener {
|
||||
instance_port = 8000
|
||||
instance_protocol = "http"
|
||||
lb_port = 80
|
||||
lb_protocol = "http"
|
||||
}
|
||||
|
||||
health_check {
|
||||
healthy_threshold = 2
|
||||
unhealthy_threshold = 2
|
||||
timeout = 3
|
||||
target = "HTTP:8000/"
|
||||
interval = 30
|
||||
}
|
||||
|
||||
instances = [aws_instance.swarm.id]
|
||||
|
||||
cross_zone_load_balancing = true
|
||||
idle_timeout = 400
|
||||
connection_draining = true
|
||||
connection_draining_timeout = 400
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="swarms",
|
||||
packages=find_packages(exclude=[]),
|
||||
version="1.4.1",
|
||||
license="MIT",
|
||||
description="Swarms - Pytorch",
|
||||
author="Kye Gomez",
|
||||
author_email="kye@apac.ai",
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/kyegomez/swarms",
|
||||
keywords=[
|
||||
"artificial intelligence",
|
||||
"deep learning",
|
||||
"optimizers",
|
||||
"Prompt Engineering",
|
||||
],
|
||||
install_requires=[
|
||||
"transformers",
|
||||
"openai",
|
||||
"langchain==0.0.240",
|
||||
"asyncio",
|
||||
"nest_asyncio",
|
||||
"pegasusx",
|
||||
"google-generativeai",
|
||||
"oceandb",
|
||||
"langchain-experimental",
|
||||
"playwright",
|
||||
"duckduckgo_search",
|
||||
"faiss-cpu",
|
||||
"wget",
|
||||
"httpx",
|
||||
"ggl",
|
||||
"beautifulsoup4",
|
||||
"pydantic",
|
||||
"tenacity",
|
||||
"celery",
|
||||
"redis",
|
||||
"google-search-results==2.4.2",
|
||||
"Pillow",
|
||||
],
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
],
|
||||
)
|
Loading…
Reference in new issue