Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mcs #7

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mcs
docker-compose.yml
example.py
LICENSE
pyproject.toml
requirements.txt
todo.md
README.md
Patient-001_encrypted.json
.git
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: docker/[email protected]
with:
push: true
tags: h4ckermike/swarms-api:experimental
tags: h4ckermike/swarms-mcs:experimental
# - name: Build the Docker image
# run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)

266 changes: 245 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,260 @@
# Dockerfile
# review
# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Use an official Python runtime as the base image
FROM python:3.12-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1

# Set environment variables to ensure output is not buffered
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV OPENAI_API_KEY="your_key"
ENV WORKSPACE_DIR="agent_workspace"
RUN apt update
RUN apt install -y git
RUN apt install --allow-change-held-packages -y python3-virtualenv
RUN apt install --allow-change-held-packages -y expect
RUN apt install --allow-change-held-packages -y jq netcat-traditional # missing packages

# Install Python dependencies

RUN mkdir -p /var/mcs/agent_workspace/
RUN adduser --disabled-password --gecos "" mcs --home "/home/mcs"
RUN chown -R mcs:mcs /var/mcs/agent_workspace
USER mcs
RUN python3 -m venv /var/mcs/agent_workspace/.venv/

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install --upgrade pip

# 15l
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install aiofiles==24.1.0 \
aiohappyeyeballs==2.4.4 \
aiosignal==1.3.2 \
frozenlist==1.5.0 \
aiohttp==3.11.11 \
attrs==24.3.0 \
annotated-types==0.7.0 \
anyio==4.7.0 \
sniffio==1.3.1 \
typing_extensions==4.12.2 \
asyncio==3.4.3 \
multidict==6.1.0 \
propcache==0.2.1 \
yarl==1.18.3 \
idna==3.10

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install certifi==2024.12.14 \
chardet==5.2.0 \
charset-normalizer==3.4.0 \
click==8.1.8 \
dataclasses-json==0.6.7 \
marshmallow==3.23.2 \
typing-inspect==0.9.0 \
packaging==23.2 \
mypy-extensions==1.0.0 \
dill==0.3.9 \
distro==1.9.0 \
docstring_parser==0.16 \
filelock==3.16.1 \
fastapi==0.115.6 \
starlette==0.41.3 \
pydantic==2.10.4 \
pydantic_core==2.27.2
# 15s


RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install GPUtil==1.4.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install Jinja2==3.1.5 MarkupSafe==3.0.2 PyYAML==6.0.2 Pygments==2.18.0 SQLAlchemy==2.0.36 fsspec==2024.12.0 greenlet==3.1.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install h11==0.14.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install httpcore==1.0.7
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install httpx==0.27.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install huggingface-hub==0.27.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install importlib_metadata==8.5.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install iniconfig==2.0.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install jiter==0.8.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install jsonpatch==1.33
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install jsonpointer==3.0.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install jsonschema-specifications==2024.10.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install jsonschema==4.23.0
# Huge
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install langchain-community==0.0.29 \
langchain-core==0.1.53 \
langsmith==0.1.147 \
numpy==1.26.4 \
orjson==3.10.12 \
requests-toolbelt==1.0.0 \
tenacity==8.5.0

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install loguru==0.7.3
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install lxml==5.3.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install markdown-it-py==3.0.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install mdurl==0.1.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install mpmath==1.3.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install msgpack==1.1.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install multiprocess==0.70.17
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install mypy-protobuf==3.6.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install networkx==3.4.2

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install ollama==0.4.4
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install openai==1.58.1

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pathos==0.3.3
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pathspec==0.12.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install platformdirs==4.3.6
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pluggy==1.5.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pox==0.3.5
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install ppft==1.7.6.9
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install protobuf==5.29.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install psutil==6.1.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pytesseract==0.3.13
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pytest==8.3.4
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install python-dateutil==2.9.0.post0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install python-docx==1.1.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install python-dotenv==1.0.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install python-magic==0.4.27
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pytz==2024.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install ratelimit==2.2.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install referencing==0.35.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install regex==2024.11.6
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install reportlab==4.2.5

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install requests==2.32.3
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install rich==13.9.4
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install rpds-py==0.22.3
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install safetensors==0.4.5
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install sentry-sdk==2.19.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install six==1.17.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install sympy==1.13.1 # 10 sec
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install termcolor==2.5.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install tiktoken==0.8.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install tokenizers==0.21.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install toml==0.10.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install tqdm==4.67.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install types-chardet==5.0.4.6
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install types-protobuf==5.29.1.20241207
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install types-pytz==2024.2.0.20241221
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install types-toml==0.10.8.20240310
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install tzdata==2024.2
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install urllib3==2.3.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install uvicorn==0.34.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install zipp==3.21.0


## dev toools
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install ruff==0.4.4
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install black==24.10.0

### ## SLOW
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install doc-master==0.0.2
### # needs qt
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install clusterops==0.1.6

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pandas==2.2.3 # 13s
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install litellm==1.55.9 # 11s
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install transformers==4.47.1 # 12s
### #RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install triton==3.1.0 # 18s
### # Big ones
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pillow==11.0.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install pypdf==5.1.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install ray==2.40.0
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cublas-cu12==12.4.5.8
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cuda-cupti-cu12==12.4.127
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cuda-nvrtc-cu12==12.4.127
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cuda-runtime-cu12==12.4.127
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cudnn-cu12==9.1.0.70
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cufft-cu12==11.2.1.3
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-curand-cu12==10.3.5.147
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cusolver-cu12==11.6.1.9
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-cusparse-cu12==12.3.1.170
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-nccl-cu12==2.21.5
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-nvjitlink-cu12==12.4.127
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install nvidia-nvtx-cu12==12.4.127

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install torch==2.5.1
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install together==1.3.10

###
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install git+https://github.com/jmikedupont2/swarm-models@main#egg=swarm-models

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install git+https://github.com/jmikedupont2/swarms@feature/merge_latest_675#egg=swarms

# just try and install from here
RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install git+https://github.com/jmikedupont2/swarms-MedicalCoderSwarm-deployment/@feature/mcs#egg=mcs

RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install cryptography


#
# swarm-models==0.2.7 # BIG 55 sec
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install -r /opt/swarms/requirements.txt
#RUN git config --global --add safe.directory "/opt/swarms"
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install uvicorn fastapi

#COPY swarms /opt/swarms/swarms
#COPY pyproject.toml /opt/swarms/
#COPY README.md /opt/swarms/
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install -e /opt/swarms/
#COPY requirements.txt .
# things that change
#COPY api/main.py /opt/swarms/api/main.py
WORKDIR /var/mcs/agent_workspace



## Use an official Python runtime as the base image
#FROM h4ckermike/swarms-api:experimental

# # Set environment variables to ensure output is not buffered
# ENV PYTHONUNBUFFERED=1
# ENV PYTHONDONTWRITEBYTECODE=1
# #ENV OPENAI_API_KEY="your_key"
# ENV WORKSPACE_DIR="agent_workspace"

# Set the working directory inside the container
WORKDIR /app
#WORKDIR /opt/mcs/api

# Install dependencies
#RUN apt-get update && \
# apt-get install -y --no-install-recommends build-essential

# Update and install required system packages
#RUN apt-get install -y --no-install-recommends sqlite3 libsqlite3-dev

# Copy only requirements first (for better caching)
COPY ./api/requirements.txt /app/requirements.txt
#COPY ./api/requirements.txt /app/requirements.txt

# Install dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
pip install --no-cache-dir -r requirements.txt && \
apt-get remove -y build-essential && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
#RUN pip install --no-cache-dir -r requirements.txt

# we can remove the build essential after the fact so we can build the reqs apart
#RUN apt-get remove -y build-essential

#RUN mkdir -p /opt/mcs
# Copy the rest of the application code
COPY ./api /app
COPY ./api/main.py /opt/mcs/api/main.py
#RUN mkdir -p /opt/mcs/mcs

#COPY ./pyproject.toml /opt/mcs/pyproject.toml

#USER root
#ADD /mcs /opt/mcs/mcs

#ADD . /opt/mcs
#ADD /mcs/__init__.py /opt/mcs/mcs/__init__.py
#COPY ./mcs/main.py /opt/mcs/mcs/main.py
#COPY ./mcs/security.py /opt/mcs/mcs/security.py

#USER mcs
# now install mcs
#RUN ls -latr /opt/mcs/
#RUN /var/mcs/agent_workspace/.venv/bin/python -m pip install -e /opt/mcs/
#COPY ./api/bootup.sh /opt/mcs/api/bootup.sh

# Make the bootup script executable
RUN chmod +x bootup.sh
#USER root
#RUN chmod +x /opt/mcs/api/bootup.sh

# Expose the application port
EXPOSE 8000
#EXPOSE 8000

# Start the application
CMD ["./bootup.sh"]
#CMD ["/opt/mcs/api/bootup.sh"]
#CMD ["/usr/bin/unbuffer", "/var/mcs/agent_workspace/.venv/bin/uvicorn", "--proxy-headers", "--forwarded-allow-ips='*'", "--workers=4", "--port=8000", "--reload-delay=30", "main:create_app"]
CMD ["/usr/bin/unbuffer", "/var/mcs/agent_workspace/.venv/bin/uvicorn", "--proxy-headers", "--forwarded-allow-ips='*'", "--workers=4", "--port=8000", "--reload-delay=30", "main:app"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Infrastructure packageing for MSC

1. terraform code to create mcs.api.swarms.ai and launch autoscaler group
https://github.com/jmikedupont2/swarms-terraform/pull/15

2. setup of nginx and systemd to launch docker process (wip)
this allows flexibility of adding in https and other features in front as well as monitoring the system and restarting it on boot.
3. setup of docker file to run mcs (wip)
taking existing docker packaging.
4. bootscript to launch into docker from shell (api/rundocker.sh)

# Medical Diagnosis Swarm Architecture


Expand Down
9 changes: 7 additions & 2 deletions api/bootup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pip3 install -r requirements.txt
#!/bin/bash
set -x
set -e
#pip3 install -r requirements.txt

uvicorn main:app --host 0.0.0.0 --port 8000 --reload
#uvicorn main:app --host 0.0.0.0 --port 8000 --reload

#CMD ["/usr/bin/unbuffer", "/var/swarms/agent_workspace/.venv/bin/uvicorn", "--proxy-headers", "--forwarded-allow-ips='*'", "--workers=4", "--port=8000", "--reload-delay=30", "main:create_app"]
16 changes: 12 additions & 4 deletions api/rundocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set -e # stop on any error
#export ROOT="" # empty
export WORKSOURCE="/opt/mcs/api"

# login to ecr from docker
aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 916723593639.dkr.ecr.us-east-2.amazonaws.com

adduser --disabled-password --gecos "" mcs --home "/home/mcs" || echo ignore
git config --global --add safe.directory "/opt/mcs"
git config --global --add safe.directory "/opt/mcs-memory"
Expand Down Expand Up @@ -47,7 +50,10 @@ mkdir -p "/home/mcs/.cache/huggingface/hub"
set +x
OPENAI_KEY=$(aws ssm get-parameter --name "mcs_openai_key" | jq .Parameter.Value -r )
export OPENAI_KEY
# CREATE
echo "OPENAI_KEY=${OPENAI_KEY}" > "/var/run/mcs/secrets/env"
# APPEND
echo "OPENAI_API_KEY=${OPENAI_KEY}" >> "/var/run/mcs/secrets/env"
set -x

## append new homedir
Expand Down Expand Up @@ -79,15 +85,17 @@ chown -R mcs:mcs /opt/mcs/api/
# might be leftover on the ami,
systemctl stop swarms-uvicorn || echo ok
systemctl disable swarms-uvicorn || echo ok
rm /etc/systemd/system/swarms-uvicorn.service
rm /etc/systemd/system/swarms-uvicorn.service || echo not there

systemctl daemon-reload
systemctl start mcs-docker || journalctl -xeu mcs-docker
systemctl enable mcs-docker || journalctl -xeu mcs-docker
systemctl start mcs-docker || echo failed
#journalctl -xeu mcs-docker
systemctl enable mcs-docker || echo failed
#journalctl -xeu mcs-docker
systemctl enable nginx
systemctl start nginx

journalctl -xeu mcs-docker | tail -200 || echo oops
#journalctl -xeu mcs-docker | tail -200 || echo oops
systemctl status mcs-docker || echo oops2

# now after mcs is up, we restart nginx
Expand Down
Loading
Loading