Skip to content

Commit

Permalink
Refactor: Port this project into typescript (#58)
Browse files Browse the repository at this point in the history
* chore: remove all python related files

* refactor: merge the TS port from bifrostlab/llm-assistant-v2

* refactor: update dev container and workflows

* feat: remove unused env TZ

* chore: update lintstaged biome command to not emit errors if glob is unmatched

* feat: rename Command type to SlashCommand

* build: update build config

- Remove DTS generation since we're not exporting a library
- clean output folder before building
  • Loading branch information
samhwang authored Apr 14, 2024
1 parent e139834 commit 92e58fd
Show file tree
Hide file tree
Showing 71 changed files with 6,070 additions and 1,055 deletions.
16 changes: 6 additions & 10 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
FROM mcr.microsoft.com/devcontainers/python:3.12
LABEL org.opencontainers.image.authors="https://github.com/nqngo"
LABEL description="Python 3.12 devcontainer with poetry"
FROM mcr.microsoft.com/devcontainers/typescript-node:20-bookworm
LABEL org.opencontainers.image.authors="https://github.com/nqngo,https://github.com/samhwang"
LABEL description="TypeScript NodeJS devcontainers with PNPM"

# Configure the dev environment
RUN apt-get update && \
apt-get install -y bash-completion && \
rm -rf /var/lib/apt/list/*
# Configure poetry
RUN pipx install poetry && \
poetry completions bash > /etc/bash_completion.d/poetry
ARG packages="pnpm typescript"
RUN npm -g install ${packages} && \
npm cache clean --force
15 changes: 7 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"name": "Python 3.12",
"name": "TypeScript + NodeJS + PNPM",
"image": "ghcr.io/bifrostlab/llm-assistant/devcontainer:latest",
"customizations": {
"vscode": {
"settings": {
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true,
"python.editor.formatOnSave": true,
"python.editor.defaultFormatter": "charliermarsh.ruff"
"editor.formatOnSave": true
},
"extensions": [
"biomejs.biome",
"GitHub.vscode-github-actions",
"GitHub.copilot",
"charliermarsh.ruff",
"elagil.pre-commit-helper",
"EditorConfig.EditorConfig",
"ms-python.mypy-type-checker"
"mikestead.dotenv",
"ms-azuretools.vscode-docker",
"vitest.explorer",
"yoavbls.pretty-ts-errors"
]
}
},
Expand Down
4 changes: 1 addition & 3 deletions .devcontainer/post-install.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/bash
poetry install
poetry shell
poetry run pre-commit install
pnpm install
38 changes: 38 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
node_modules

.DS_Store
*.local

# Test Coverage
coverage

# Build output
dist

# Env
.env*

# Log & README
*.log
*.md
*.MD

# OS Specific
Thumbs.db
.DS_Store

# Docker
docker-compose.*
Dockerfile

# Misc
LICENSE
.github
.idea
.vscode
.devcontainer

# Not needed for prod
litellm
scripts
playgrounds
13 changes: 7 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# LiteLLM/OpenAI
AI_SERVER_URL="http://localhost:8000"
# AI SERVER
AI_SERVER_URL="http://localhost:4000"

# Discord Bot
DISCORD_BOT_TOKEN="EXAMPLETokennnnnn.Gro00t.aaaaaBBBBBccccc11111DDDDDDD2222eeeeeeee"
# THIS SHOULD BE ASSIGNED TO THE BOT'S `scopes` WHEN DEPLOYED
DISCORD_GUILD_ID="99999999999999999999999"
# BOT CONFIGS
CLIENT_ID=CLIENT_ID_GOES_HERE
# GUILD_ID=FOR_DEVELOPMENT_ONLY
PUBLIC_KEY=PUBLIC_KEY_GOES_HERE
TOKEN=YOUR_BOT_TOKEN_HERE
20 changes: 20 additions & 0 deletions .github/actions/setup-node-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: setup-node-dependencies
description: Setup Node Dependencies

runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: ^8.15.0

- name: Set up Node 20
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Set up project
shell: bash
run: pnpm install
19 changes: 0 additions & 19 deletions .github/actions/setup-python/action.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build-devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}/devcontainer:latest
ghcr.io/${{ github.repository }}/devcontainer:3.12
ghcr.io/${{ github.repository }}/devcontainer:node-20
ghcr.io/${{ github.repository }}/devcontainer:${{ github.sha }}
41 changes: 8 additions & 33 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,14 @@ on:
paths:
- Dockerfile
- src/**
- poetry.lock
- pyproject.toml
- bin/**
- pnpm-lock.yaml
- package.json
- .github/workflows/build.yml

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64, arm64

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

- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ github.repository }}/llm-assistant:latest
ghcr.io/${{ github.repository }}/llm-assistant:${{ github.sha }}
test-and-lint:
uses: ./.github/workflows/workflow-test-and-lint.yml
deploy:
needs: test-and-lint
uses: ./.github/workflows/workflow-build.yml
37 changes: 2 additions & 35 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
name: Test and Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

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

- name: Set up Python
uses: ./.github/actions/setup-python

- name: Lint with Ruff
run: poetry run ruff check .

format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: ./.github/actions/setup-python

- name: Format check with Ruff
run: poetry run ruff format --check .

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: ./.github/actions/setup-python

- name: Typecheck with mypy
run: poetry run mypy .
test-and-lint:
uses: ./.github/workflows/workflow-test-and-lint.yml
35 changes: 35 additions & 0 deletions .github/workflows/workflow-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and deploy Docker Image

on:
workflow_call:

jobs:
build-discord-bot:
name: Build Discord Bot Docker Image
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Login to GitHub Docker
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push docker image
uses: docker/build-push-action@v5
with:
pull: true
push: true
target: production
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
ghcr.io/${{ github.repository }}/llm-assistant:latest
ghcr.io/${{ github.repository }}/llm-assistant:${{ github.sha }}
42 changes: 42 additions & 0 deletions .github/workflows/workflow-test-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests and Lints packages

on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up project
uses: ./.github/actions/setup-node-deps

- name: Run linting
run: pnpm lint

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up project
uses: ./.github/actions/setup-node-deps

- name: Run tests
run: pnpm test

typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up project
uses: ./.github/actions/setup-node-deps

- name: Run typecheck
run: pnpm typecheck
Loading

0 comments on commit 92e58fd

Please sign in to comment.