Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v4
with:
version: "latest"

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: uv sync

- name: Lint
run: |
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/

- name: Test
run: uv run pytest tests/ -v

- name: Notify Discord on failure
if: failure()
uses: Ilshidur/action-discord@0.4.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
DISCORD_USERNAME: "IShowSpeed"
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
with:
args: "SUUUUIII--- wait... 💀 ang lint/test sa Topic Worker ni ${{github.actor}} NAGUBA!!! Bro unsa ni?? Fix your code dawg 😭🔴"

- name: Notify Discord on success
if: success()
uses: Ilshidur/action-discord@0.4.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
DISCORD_USERNAME: "IShowSpeed"
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
with:
args: "SUUUUUIIIIII ⚡ Topic Worker CI PASSED!!! si ${{github.actor}} kay goated fr fr 🐐✅ WWWWW chat WWWWW"
117 changes: 117 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Deploy to RunPod

on:
release:
types: [published]

env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/topic-worker

jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v4
with:
version: "latest"

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: uv sync

- name: Lint
run: |
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/

- name: Test
run: uv run pytest tests/ -v

build-and-push:
needs: lint-and-test
runs-on: ubuntu-latest
steps:
- name: Notify Discord deployment started
uses: Ilshidur/action-discord@0.4.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
DISCORD_USERNAME: "IShowSpeed"
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
with:
args: "CHAT CHAT CHAT!!! 🏃💨 si ${{github.actor}} kay nag deploy sa Topic Worker to PRODUCTION!!! Hold on let me cook 🔥🔥🔥"

- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract version from release tag
id: version
run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64
tags: |
${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}
${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

update-runpod:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Extract version from release tag
id: version
run: echo "tag=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"

- name: Update RunPod template image
run: |
response=$(curl -s -w "\n%{http_code}" -X PATCH \
"https://rest.runpod.io/v1/templates/${{ secrets.RUNPOD_TEMPLATE_ID }}" \
-H "Authorization: Bearer ${{ secrets.RUNPOD_API_KEY }}" \
-H "Content-Type: application/json" \
-d "{\"imageName\": \"docker.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}\"}")
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -n -1)
echo "Response: $body"
if [ "$http_code" -ge 400 ]; then
echo "::error::Failed to update RunPod template (HTTP $http_code)"
exit 1
fi
echo "Template updated to ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}"

- name: Notify Discord deployment failed
if: failure()
uses: Ilshidur/action-discord@0.4.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
DISCORD_USERNAME: "IShowSpeed"
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
with:
args: "Bro... 💀 ang Topic Worker deployment ni ${{github.actor}} FAILED!!! This is NOT speed chat, this is NOT speed 😭🔴"

- name: Notify Discord deployment succeeded
if: success()
uses: Ilshidur/action-discord@0.4.0
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_DEPLOYMENT_WEBHOOK }}
DISCORD_USERNAME: "IShowSpeed"
DISCORD_AVATAR: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTumYcOCdUsVMQj9L_eYWlZDe-9MR_R42jp5Q&s"
with:
args: "WWWWWW Topic Worker deployed to Production!!! ⚡🚀 si ${{github.actor}} ikaw na jud dawg, SUUUUIIII ✅🐐"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM runpod/pytorch:2.2.0-py3.11-cuda12.1.1-devel-ubuntu22.04
FROM runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04

COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

Expand Down
12 changes: 5 additions & 7 deletions src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import logging
from datetime import datetime, timezone
from datetime import UTC, datetime

import numpy as np
import runpod
Expand All @@ -29,7 +29,7 @@ def _fail(error: str) -> dict:
version=WORKER_VERSION,
status="failed",
error=error,
completedAt=datetime.now(timezone.utc).isoformat(),
completedAt=datetime.now(UTC).isoformat(),
).model_dump()


Expand Down Expand Up @@ -97,9 +97,7 @@ def handler(event: dict) -> dict:
outlier_count = sum(1 for t in model.topics_ if t == -1)

# Compute metrics
metrics = compute_metrics(
model, model.topics_, texts, embeddings, embed_model=embed_model
)
metrics = compute_metrics(model, model.topics_, texts, embeddings, embed_model=embed_model)

response = TopicModelResponse(
version=WORKER_VERSION,
Expand All @@ -108,12 +106,12 @@ def handler(event: dict) -> dict:
assignments=assignments,
metrics=metrics,
outlierCount=outlier_count,
completedAt=datetime.now(timezone.utc).isoformat(),
completedAt=datetime.now(UTC).isoformat(),
)

return response.model_dump()

except Exception as e:
except Exception:
logger.exception("Unexpected error in handler")
# Infrastructure error — let RunPod return error status → BullMQ will retry
raise
Expand Down
1 change: 0 additions & 1 deletion src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from pydantic import BaseModel, ConfigDict


# --- Request ---


Expand Down
Loading
Loading