From 6610ad6a14077318a8501b631fd42cf05a1275f3 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 14:41:32 -0700 Subject: [PATCH 1/6] Add example docker file for building agents --- examples/Dockerfile-example | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/Dockerfile-example diff --git a/examples/Dockerfile-example b/examples/Dockerfile-example new file mode 100644 index 000000000..7b976cfec --- /dev/null +++ b/examples/Dockerfile-example @@ -0,0 +1,48 @@ +# 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. +CMD python myagent.py start From 9a0e22561b4323a9e608c43b98a9d10c19b2731c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 14:44:46 -0700 Subject: [PATCH 2/6] fix ruff errors --- livekit-agents/livekit/agents/cli/log.py | 2 +- livekit-agents/livekit/agents/llm/function_context.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/livekit-agents/livekit/agents/cli/log.py b/livekit-agents/livekit/agents/cli/log.py index 356ab8809..066188f21 100644 --- a/livekit-agents/livekit/agents/cli/log.py +++ b/livekit-agents/livekit/agents/cli/log.py @@ -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) == type: return str(o) # extra values are formatted as str() if the encoder raises TypeError diff --git a/livekit-agents/livekit/agents/llm/function_context.py b/livekit-agents/livekit/agents/llm/function_context.py index aaeafdbb1..a189275b4 100644 --- a/livekit-agents/livekit/agents/llm/function_context.py +++ b/livekit-agents/livekit/agents/llm/function_context.py @@ -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) From d63c554caff707b7bc7cdeeaa0b5922c3b27eadc Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 14:47:30 -0700 Subject: [PATCH 3/6] use entrypoint --- examples/Dockerfile-example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Dockerfile-example b/examples/Dockerfile-example index 7b976cfec..994fa428e 100644 --- a/examples/Dockerfile-example +++ b/examples/Dockerfile-example @@ -45,4 +45,5 @@ COPY . . RUN python myagent.py download-files # Run the application. -CMD python myagent.py start +ENTRYPOINT ["python", "myagent.py"] +CMD ["start"] From 2154789467f6fb89ad6982c1c9b3e4b46b2c7716 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 14:50:23 -0700 Subject: [PATCH 4/6] one more type --- livekit-agents/livekit/agents/cli/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/livekit-agents/livekit/agents/cli/log.py b/livekit-agents/livekit/agents/cli/log.py index 066188f21..bd7c2682c 100644 --- a/livekit-agents/livekit/agents/cli/log.py +++ b/livekit-agents/livekit/agents/cli/log.py @@ -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) is 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 From c5305f81ffb1058882e39b77b62e444c6c0b47ea Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 14:52:47 -0700 Subject: [PATCH 5/6] fix typecheck workflow --- .github/workflows/check-types.yml | 83 +++++++++++++++++-------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index d446a8756..5e400c30a 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -1,4 +1,4 @@ -name: Check Types +name: Check Types on: push: @@ -16,39 +16,50 @@ 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 + + - 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 From 954ba4d0ad57653d68dcd1f950ff682323463297 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 30 Jun 2024 15:04:46 -0700 Subject: [PATCH 6/6] more types --- .github/workflows/check-types.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index 5e400c30a..409c5cc4b 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -49,6 +49,8 @@ jobs: types-cffi \ types-psutil \ types-pyOpenSSL \ + types-requests \ + types-openpyxl \ types-requests - name: Check Types