Skip to content

Commit

Permalink
Add example docker file for building agents (#401)
Browse files Browse the repository at this point in the history
* Add example docker file for building agents

* fix ruff errors

* use entrypoint

* one more type

* fix typecheck workflow

* more types
  • Loading branch information
davidzhao authored Jul 1, 2024
1 parent da1694e commit 39a5959
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 38 deletions.
85 changes: 49 additions & 36 deletions .github/workflows/check-types.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Types
name: Check Types

on:
push:
Expand All @@ -16,39 +16,52 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-python@v5
with:
python-version: '3.9'
cache: 'pip'

- name: Install mypy
run: python -m pip install --upgrade mypy

- name: Install all packages
run: |
pip install ./livekit-agents \
./livekit-plugins/livekit-plugins-openai \
./livekit-plugins/livekit-plugins-deepgram \
./livekit-plugins/livekit-plugins-google \
./livekit-plugins/livekit-plugins-nltk \
./livekit-plugins/livekit-plugins-silero \
./livekit-plugins/livekit-plugins-elevenlabs \
./livekit-plugins/livekit-plugins-cartesia \
./livekit-plugins/livekit-plugins-azure
- name: Check Types
run : |
mypy --install-types --non-interactive \
-p livekit.agents \
-p livekit.plugins.openai \
-p livekit.plugins.deepgram \
-p livekit.plugins.google \
-p livekit.plugins.nltk \
-p livekit.plugins.silero \
-p livekit.plugins.elevenlabs \
-p livekit.plugins.cartesia \
-p livekit.plugins.azure
- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: "pip"

- name: Install mypy
run: python -m pip install --upgrade mypy

- name: Install all packages
run: |
pip install ./livekit-agents \
./livekit-plugins/livekit-plugins-openai \
./livekit-plugins/livekit-plugins-deepgram \
./livekit-plugins/livekit-plugins-google \
./livekit-plugins/livekit-plugins-nltk \
./livekit-plugins/livekit-plugins-silero \
./livekit-plugins/livekit-plugins-elevenlabs \
./livekit-plugins/livekit-plugins-cartesia \
./livekit-plugins/livekit-plugins-azure
- name: Install stub packages
run: |
pip install \
pandas-stubs \
types-Pygments \
types-cachetools \
types-cffi \
types-psutil \
types-pyOpenSSL \
types-requests \
types-openpyxl \
types-requests
- name: Check Types
run: |
mypy --install-types --non-interactive \
-p livekit.agents \
-p livekit.plugins.openai \
-p livekit.plugins.deepgram \
-p livekit.plugins.google \
-p livekit.plugins.nltk \
-p livekit.plugins.silero \
-p livekit.plugins.elevenlabs \
-p livekit.plugins.cartesia \
-p livekit.plugins.azure
49 changes: 49 additions & 0 deletions examples/Dockerfile-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an example Dockerfile that builds a minimal container for running LK Agents
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.11.6
FROM python:${PYTHON_VERSION}-slim

# Prevents Python from writing pyc files.
ENV PYTHONDONTWRITEBYTECODE=1

# Keeps Python from buffering stdout and stderr to avoid situations where
# the application crashes without emitting any logs due to buffering.
ENV PYTHONUNBUFFERED=1

# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/home/appuser" \
--shell "/sbin/nologin" \
--uid "${UID}" \
appuser


# Install gcc and other build dependencies.
RUN apt-get update && \
apt-get install -y \
gcc \
python3-dev \
&& rm -rf /var/lib/apt/lists/*

USER appuser

RUN mkdir -p /home/appuser/.cache
RUN chown -R appuser /home/appuser/.cache

WORKDIR /home/appuser

COPY requirements.txt .
RUN python -m pip install --user --no-cache-dir -r requirements.txt

COPY . .

# ensure that any dependent models are downloaded at build-time
RUN python myagent.py download-files

# Run the application.
ENTRYPOINT ["python", "myagent.py"]
CMD ["start"]
2 changes: 1 addition & 1 deletion livekit-agents/livekit/agents/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def default(self, o: Any):
return o.isoformat()
elif istraceback(o):
return "".join(traceback.format_tb(o)).strip()
elif type(o) == Exception or isinstance(o, Exception) or type(o) == type:
elif type(o) is Exception or isinstance(o, Exception) or type(o) is type:
return str(o)

# extra values are formatted as str() if the encoder raises TypeError
Expand Down
2 changes: 1 addition & 1 deletion livekit-agents/livekit/agents/llm/function_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def is_type_supported(t: type) -> bool:
for e in t:
if initial_type is None:
initial_type = type(e.value)
if type(e.value) != initial_type:
if type(e.value) is not initial_type:
return False

return initial_type in (str, int)
Expand Down

0 comments on commit 39a5959

Please sign in to comment.