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

Sofatutor specific changes #1

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4fd6773
add sofatutor specific config
mfittko Sep 10, 2024
379b2fe
add preview compose file
mfittko Sep 10, 2024
0b28333
add preview config
mfittko Sep 10, 2024
ea03519
add more config vars
mfittko Sep 10, 2024
6759faa
disable env file
mfittko Sep 10, 2024
6a6502c
use prot 4000, cleanup
mfittko Sep 10, 2024
6f90d6c
pass in env vars
mfittko Sep 10, 2024
69011d1
fix key
mfittko Sep 10, 2024
733f424
rename and add deployment config
mfittko Sep 11, 2024
10a5b7a
change compose file reference
mfittko Sep 11, 2024
72b6c84
add postgres_data
mfittko Sep 11, 2024
34d3063
add config settings
mfittko Sep 11, 2024
1105f3e
use COMPOSE_FILE
mfittko Sep 11, 2024
cede231
use direct env again
mfittko Sep 11, 2024
dd7d773
add nginx
mfittko Sep 11, 2024
75b74a6
Merge remote-tracking branch 'origin/sofatutor' into sofatutor
mfittko Sep 11, 2024
d61717d
use COMPOSE_FILE again
mfittko Sep 11, 2024
d2c5e5b
remove comments
mfittko Sep 11, 2024
c587814
add logging and caching for assistants
mfittko Sep 11, 2024
910bb9b
add health check
mfittko Sep 11, 2024
cf0edc0
add logging to messages
mfittko Sep 11, 2024
371170b
apply logging calls
mfittko Sep 11, 2024
ea0c69d
revert
mfittko Sep 11, 2024
22ae61b
optimize dockerfile
mfittko Sep 11, 2024
4af59cd
revert
mfittko Sep 11, 2024
d933ea9
fix bad parameter
mfittko Sep 11, 2024
22d9357
add missing argument
mfittko Sep 11, 2024
42b2eb1
enable debug level
mfittko Sep 11, 2024
ce43718
use debug logging
mfittko Sep 11, 2024
4eb88da
add --debug
mfittko Sep 11, 2024
2df96f6
try to get async logger up
mfittko Sep 11, 2024
b5c0fe1
use env var only
mfittko Sep 11, 2024
48ddf96
revert
mfittko Sep 11, 2024
93da0c6
add launch config for debugging
mfittko Sep 11, 2024
6eecb6d
try to enable logging
mfittko Sep 11, 2024
9a5c3a6
fix order
mfittko Sep 11, 2024
0b4e211
add logging
mfittko Sep 11, 2024
630adb4
handle successful_api_call
mfittko Sep 11, 2024
1700ddc
add fallback
mfittko Sep 11, 2024
9ff8a48
add metadata
mfittko Sep 11, 2024
8b1171c
use clean_metadata
mfittko Sep 11, 2024
bd6bfff
last try to adapt to thread run payload
mfittko Sep 11, 2024
d22788e
fix file name
mfittko Sep 11, 2024
31fa500
add more assistant specific data to payload
mfittko Sep 11, 2024
b2f7bb3
clean up file name
mfittko Sep 11, 2024
2ce4cdc
Add CloudWatch logging integration for enhanced monitoring
mfittko Sep 12, 2024
4e68575
re-add redis
mfittko Sep 12, 2024
c1ef940
add db config for accessing docker db
mfittko Sep 12, 2024
3200e19
use cloudwatch logging
mfittko Sep 12, 2024
5d24899
add cloudwatch case
mfittko Sep 12, 2024
7e51d02
Refactor S3 logging to use standard logging payload and improve metad…
mfittko Sep 12, 2024
d07f6f6
Add CloudWatchLogger integration and refactor AWS logger handling
mfittko Sep 12, 2024
2e7c41c
Add AWS region support to CloudWatch integration and configuration
mfittko Sep 12, 2024
9196b67
fix premature call
mfittko Sep 12, 2024
d1dce9f
try router timeout
mfittko Sep 12, 2024
c8287a6
add simple ghcr image push for sofatutor branch
mfittko Sep 16, 2024
0856746
Simplify IMAGE_NAME variable in GitHub Actions workflow
mfittko Sep 16, 2024
9afa3ca
fix image ref
mfittko Sep 17, 2024
0e383a2
remove suffix
mfittko Sep 17, 2024
47656d7
Merge remote-tracking branch 'origin/main' into sofatutor
mfittko Sep 18, 2024
c291e15
Apply suggestions from code review
mfittko Sep 18, 2024
cd32fec
add curl to runtime dependencies
mfittko Sep 18, 2024
844c4e3
Merge remote-tracking branch 'origin/sofatutor' into sofatutor
mfittko Sep 18, 2024
7f8265d
filter instructions
mfittko Sep 18, 2024
21d90d2
move
mfittko Sep 18, 2024
ffee7fd
fix instructions filter in response stream
mfittko Sep 18, 2024
70790b1
easter egg
mfittko Sep 18, 2024
97e326f
Merge remote-tracking branch 'origin/main' into sofatutor
mfittko Sep 24, 2024
68f8189
add missing status argument
mfittko Sep 24, 2024
6031e8b
fix logging issue
mfittko Sep 24, 2024
8992823
fix logging issue
mfittko Sep 24, 2024
f41eebe
switch to sofatutor actions fork
mfittko Nov 4, 2024
d5f5b7d
add httpx dependency for async HTTP requests
mfittko Jan 27, 2025
7fa63bd
cahnge assistants api key OPENAI_ASSISTANTS_API_KEY
mfittko Jan 31, 2025
29035d3
Merge pull request #2 from sofatutor/httpx-fix
mfittko Jan 31, 2025
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
34 changes: 34 additions & 0 deletions .github/workflows/pullpreview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: preview
on:
push:
branches:
- main
pull_request:
types: [labeled, unlabeled, synchronize, reopened]

env:
DNS: 'previews.sofatutor.us'

jobs:
deploy:
runs-on: ubuntu-22.04
if: github.event_name == 'push' || github.event.label.name == 'preview' || contains(github.event.pull_request.labels.*.name, 'preview')
timeout-minutes: 20

steps:
- uses: actions/checkout@v4
- uses: sofatutor/pullpreview@sofatutor
with:
admins: mfittko,Ayushi1296
always_on: main
app_path: .
instance_type: small
dns: ${{ env.DNS }}
default_port: 8080
registries: docker://index.docker.io/v1
env:
AWS_REGION: eu-central-1
PULLPREVIEW_ENV_VARS: "DOMAIN=${{ env.DNS }},AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }},AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }},OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }},LITELLM_MASTER_KEY=${{ secrets.LITELLM_MASTER_KEY }},LITELLM_SALT_KEY=${{ secrets.LITELLM_SALT_KEY }}"
PULLPREVIEW_LAUNCH_COMMAND: COMPOSE_FILE=docker-compose.pullpreview.yml docker-compose up -d --build --force-recreate
AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}"
AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
59 changes: 59 additions & 0 deletions .github/workflows/sofatutor_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
---
name: Create and publish a Container image

on:
push:
branches:
- sofatutor
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: sofatutor/docker-login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: sofatutor/docker-metadata-action@57396166ad8aefe6098280995947635806a0e6ea
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push Docker image
uses: sofatutor/docker-build-push-action@c56af957549030174b10d6867f20e78cfd7debc5
with:
context: .
push: true
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "LiteLLM Proxy",
"type": "debugpy",
"request": "launch",
"module": "litellm.proxy.proxy_cli",
"args": [
"--config",
"${workspaceFolder}/sofatutor_config.yaml",
"--debug"
],
"env": {
"LITELLM_LOG": "DEBUG",
"LITELLM_MASTER_KEY": "test",
"DATABASE_URL": "postgresql://llmproxy:dbpassword9090@localhost:5433/litellm",
"STORE_MODEL_IN_DB": "True"
},
"cwd": "${workspaceFolder}",
"console": "integratedTerminal"
}
]
}
78 changes: 32 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,76 +1,62 @@
# Base image for building
ARG LITELLM_BUILD_IMAGE=python:3.11.8-slim

# Runtime image
ARG LITELLM_RUNTIME_IMAGE=python:3.11.8-slim
# Builder stage
FROM $LITELLM_BUILD_IMAGE AS builder

# Set the working directory to /app
WORKDIR /app
FROM $LITELLM_BUILD_IMAGE as builder

# Install build dependencies
RUN apt-get clean && apt-get update && \
apt-get install -y gcc python3-dev && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app

RUN pip install --upgrade pip && \
pip install build
RUN --mount=type=cache,target=/var/cache/apt,id=litellm_apt \
apt-get update && \
apt-get install -y gcc python3-dev

# Copy the current directory contents into the container at /app
COPY . .
RUN --mount=type=cache,target=/root/.cache/pip,id=litellm_pip \
pip install --upgrade pip build

# Build Admin UI
RUN chmod +x build_admin_ui.sh && ./build_admin_ui.sh
COPY requirements.txt .

# Build the package
RUN rm -rf dist/* && python -m build
RUN --mount=type=cache,target=/root/.cache/pip,id=litellm_pip \
pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt

# There should be only one wheel file now, assume the build only creates one
RUN ls -1 dist/*.whl | head -1
RUN --mount=type=cache,target=/root/.cache/pip,id=litellm_pip \
pip install redisvl==0.0.7 --no-deps

# Install the package
RUN pip install dist/*.whl
RUN pip uninstall jwt PyJWT -y && \
pip install PyJWT --no-cache-dir

# install dependencies as wheels
RUN pip wheel --no-cache-dir --wheel-dir=/wheels/ -r requirements.txt
COPY . .

# install semantic-cache [Experimental]- we need this here and not in requirements.txt because redisvl pins to pydantic 1.0
RUN pip install redisvl==0.0.7 --no-deps
RUN chmod +x build_admin_ui.sh && ./build_admin_ui.sh

# ensure pyjwt is used, not jwt
RUN pip uninstall jwt -y
RUN pip uninstall PyJWT -y
RUN pip install PyJWT --no-cache-dir
RUN rm -rf dist/* && python -m build

# Build Admin UI
RUN chmod +x build_admin_ui.sh && ./build_admin_ui.sh
RUN --mount=type=cache,target=/root/.cache/pip,id=litellm_pip \
pip install dist/*.whl

# Runtime stage
FROM $LITELLM_RUNTIME_IMAGE AS runtime
FROM $LITELLM_RUNTIME_IMAGE as runtime

# Update dependencies and clean up - handles debian security issue
RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/*
# Install runtime dependencies, e.g. curl for healthcheck
RUN apt-get clean && apt-get update && \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . .
RUN ls -la /app

# Copy the built wheel from the builder stage to the runtime stage; assumes only one wheel file is present
COPY --from=builder /app/dist/*.whl .
COPY --from=builder /wheels/ /wheels/
COPY --from=builder /app/dist/*.whl .

# Install the built wheel using pip; again using a wildcard if it's the only file
RUN pip install *.whl /wheels/* --no-index --find-links=/wheels/ && rm -f *.whl && rm -rf /wheels
RUN --mount=type=cache,target=/root/.cache/pip,id=litellm_pip \
pip install *.whl /wheels/* --no-index --find-links=/wheels/ && \
rm -f *.whl && \
rm -rf /wheels

COPY . .

# Generate prisma client
RUN prisma generate

RUN chmod +x entrypoint.sh

EXPOSE 4000/tcp

ENTRYPOINT ["litellm"]

# Append "--detailed_debug" to the end of CMD to view detailed debug logs
CMD ["--port", "4000"]
73 changes: 73 additions & 0 deletions docker-compose.pullpreview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
services:
litellm:
build:
context: .
args:
target: runtime
image: ghcr.io/sofatutor/sofatutor/litellm:sofatutor
deploy:
replicas: 2
update_config:
parallelism: 1
order: stop-first
failure_action: rollback
delay: 30s
restart_policy:
condition: on-failure
environment:
DATABASE_URL: "postgresql://llmproxy:dbpassword9090@db:5432/litellm"
STORE_MODEL_IN_DB: "True"
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
OPENAI_API_KEY: ${OPENAI_API_KEY}
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
LITELLM_SALT_KEY: ${LITELLM_SALT_KEY}
LITELLM_LOG: "DEBUG"
REDIS_HOST: "redis"
REDIS_PORT: "6379"
command: ["--port", "4000", "--config", "sofatutor_config.yaml"]
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4000/health"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
depends_on:
- redis
- db

nginx:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- litellm

db:
image: postgres
restart: always
environment:
POSTGRES_DB: litellm
POSTGRES_USER: llmproxy
POSTGRES_PASSWORD: dbpassword9090
healthcheck:
test: ["CMD-SHELL", "pg_isready -d litellm -U llmproxy"]
interval: 1s
timeout: 5s
retries: 10
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- "5433:5432"

redis:
image: redis:7-alpine
volumes:
- redis_data:/data
command: redis-server --appendonly yes

volumes:
redis_data:
postgres_data:
16 changes: 16 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
events {
worker_connections 1000;
}

http {
upstream litellm_backend {
server litellm:4000;
}

server {
listen 80;
location / {
proxy_pass http://litellm_backend;
}
}
}
Loading