Skip to content

Commit

Permalink
gogo
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleecode committed Dec 13, 2024
1 parent 6786cf7 commit 573e500
Show file tree
Hide file tree
Showing 51 changed files with 7,842 additions and 1 deletion.
77 changes: 77 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Version control
.git
.gitignore

# Node.js
node_modules
npm-debug.log
yarn-error.log
.pnpm-store

# Build outputs
.sst
out
.turbo
.open-next
dist
build

# Environment and config files
.env*
*.env
*.config.js
*.config.ts
sst.config.ts

# Logs
*.log

# OS generated files
.DS_Store
Thumbs.db

# IDEs and editors
.vscode
.idea
*.swp
*.swo

# Testing
coverage
.nyc_output

# Temporary files
tmp
temp

# Python
__pycache__
*.pyc
*.pyo
*.pyd
.Python
venv
pip-log.txt
pip-delete-this-directory.txt

# Project specific
infra
docker
README.md

# Ignore sst-env.d.ts under packages directory
packages/**/sst-env.d.ts
scripts
packages/**/temp

packages/**/tsdoc-metadata.json

**/node_modules
out
.turbo
**/.turbo
dist
**/.dist
**/.dev-dist
**/dist
**/dev-dist
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LOG_LEVEL=DEBUG
DATABASE_URL=
OPENAI_API_KEY=
DEEPGRAM_API_KEY=
LIVEKIT_URL=
LIVEKIT_API_KEY=
LIVEKIT_API_SECRET=
95 changes: 95 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Dependency directories
node_modules/
jspm_packages/

# Build outputs
dist/
build/
out/
.tshy/
.tshy-build/

# SST-specific
.sst/
.build/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# IDEs and editors
.idea/
.vscode/
*.swp
*.swo
.DS_Store

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt

# Python
__pycache__/
*.py[cod]
*$py.class

# Virtual environment
.venv
venv/
env/
ENV/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version
.turbo

**/*.tsbuildinfo

.open-next
temp
packages/**/tsdoc-metadata.json
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# voice-agent-example
# SST Voice Agent Example

## Setup

```sh
python -m venv .venv
source .venv/bin/activate
pip3 install -r apps/voice-agent/requirements.txt
```
31 changes: 31 additions & 0 deletions apps/voice-agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Python
venv
__pycache__
*.pyc
*.pyo
*.pyd
.Python
pip-log.txt
pip-delete-this-directory.txt

# Node
node_modules
npm-debug.log
yarn-error.log
.pnpm-debug.log

# Environment
.env
.env.local
.env.*.local

# IDEs and editors
.idea
*.swp
*.swo
.DS_Store

# Build outputs
dist
build
*.egg-info
53 changes: 53 additions & 0 deletions apps/voice-agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM python:3.11-slim-bullseye AS base

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends curl unzip build-essential && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y --no-install-recommends nodejs && \
apt-get clean

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN corepack pnpm install turbo --global
RUN curl -fsSL https://bun.sh/install | bash && \
mv /root/.bun/bin/bun /usr/local/bin/bun

VOLUME /pnpm/store

FROM base AS python-builder
WORKDIR /app/apps/voice-agent
COPY apps/voice-agent/requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt

FROM base AS pnpm-builder
WORKDIR /app
COPY . .
RUN turbo prune "@voice-agent-example/voice-agent" --docker

FROM base AS pnpm-installer
WORKDIR /app
COPY --from=pnpm-builder /app/out/json/ .
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts

COPY --from=pnpm-builder /app/out/full/ .
RUN corepack pnpm turbo build
RUN pnpm deploy --filter="@voice-agent-example/voice-agent" --prod /prod/app

# Runner stage
FROM base AS runner
WORKDIR /app

COPY --from=pnpm-installer /app .
COPY --from=python-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
ENV PYTHONPATH="/usr/local/lib/python3.11/site-packages:$PYTHONPATH"

# Create a non-root user named 'bun'
RUN useradd -m -s /bin/bash bun
USER bun
WORKDIR /app/apps/voice-agent
ENV NODE_ENV=production
CMD ["bun", "run", "main.ts"]
4 changes: 4 additions & 0 deletions apps/voice-agent/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preload = ["@deepkit/bun"]

[install]
peer = true
45 changes: 45 additions & 0 deletions apps/voice-agent/ipc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { VectorStoreHttpHono } from '@voice-agent-example/vector-storage-hono'
import { Config, Effect, Layer, pipe, Schedule } from 'effect'
import { Hono } from 'hono'

const App = Effect.gen(function*() {
const vectorStore = yield* VectorStoreHttpHono

const app = yield* Effect.sync(() =>
new Hono()
.route('embeddings', vectorStore)
)

return app
})

export const layerIPCServer = Layer.effectDiscard(
Effect.gen(function*() {
const app = yield* App
const SOCKET_PATH = yield* pipe(
Config.nonEmptyString('SOCKET_PATH'),
Config.withDefault('/tmp/voice-agent.sock'),
)

yield* Effect.acquireRelease(
Effect.sync(() =>
Bun.serve({
unix: SOCKET_PATH,
fetch: app.fetch,
})
),
(server) =>
pipe(
Effect.sync(() => server.stop()),
Effect.catchAll(() => Effect.void),
),
)

yield* Effect.never
}).pipe(
Effect.andThen(() => Effect.never),
Effect.retry({ schedule: Schedule.forever }),
Effect.scoped,
Effect.fork,
),
)
Loading

0 comments on commit 573e500

Please sign in to comment.