Skip to content

Commit 895588b

Browse files
authored
fix: Docker and sagemaker setup (#1118)
* fix: docker copying extra files * feat: allow configuring mode through env vars * feat: Attempt to build and tag a docker image * fix: run docker on release * fix: typing in prompt transformation * chore: remove tutorial comments
1 parent 768e5ff commit 895588b

File tree

7 files changed

+67
-15
lines changed

7 files changed

+67
-15
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ models
33
.github
44
.vscode
55
.DS_Store
6+
.mypy_cache
7+
.ruff_cache
8+
local_data
69
terraform
710
tests
811
Dockerfile

.github/workflows/docker.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
35+
tags: |
36+
type=ref,event=branch
37+
type=ref,event=pr
38+
type=semver,pattern={{version}}
39+
type=semver,pattern={{major}}.{{minor}}
40+
type=sha
41+
- name: Build and push Docker image
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ steps.meta.outputs.tags }}
47+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ FROM base as dependencies
2323
WORKDIR /home/worker/app
2424
COPY pyproject.toml poetry.lock ./
2525

26-
RUN poetry install --with local
2726
RUN poetry install --with ui
28-
RUN CMAKE_ARGS="-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS"\
29-
poetry run pip install --force-reinstall --no-cache-dir llama-cpp-python
3027

3128
FROM base as app
3229

@@ -39,9 +36,11 @@ EXPOSE 8080
3936
RUN adduser --system worker
4037
WORKDIR /home/worker/app
4138

42-
# Copy everything, including the virtual environment
43-
COPY --chown=worker --from=dependencies /home/worker/app .
44-
COPY --chown=worker . .
39+
RUN mkdir "local_data"; chown worker local_data
40+
COPY --chown=worker --from=dependencies /home/worker/app/.venv/ .venv
41+
COPY --chown=worker private_gpt/ private_gpt
42+
COPY --chown=worker docs/ docs
43+
COPY --chown=worker *.yaml *.md ./
4544

4645
USER worker
4746
ENTRYPOINT .venv/bin/python -m private_gpt

private_gpt/components/embedding/embedding_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EmbeddingComponent:
1313
@inject
1414
def __init__(self) -> None:
1515
match settings.llm.mode:
16-
case "local":
16+
case "local" | "sagemaker":
1717
from llama_index.embeddings import HuggingFaceEmbedding
1818

1919
self.embedding_model = HuggingFaceEmbedding(

private_gpt/components/llm/custom/sagemaker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
)
2222

2323
if TYPE_CHECKING:
24-
from collections.abc import Callable
25-
2624
from llama_index.callbacks import CallbackManager
2725
from llama_index.llms import (
2826
CompletionResponseGen,
@@ -113,10 +111,10 @@ class SagemakerLLM(CustomLLM):
113111
context_window: int = Field(
114112
description="The maximum number of context tokens for the model."
115113
)
116-
messages_to_prompt: Callable[..., str] = Field(
114+
messages_to_prompt: Any = Field(
117115
description="The function to convert messages to a prompt.", exclude=True
118116
)
119-
completion_to_prompt: Callable[..., str] = Field(
117+
completion_to_prompt: Any = Field(
120118
description="The function to convert a completion to a prompt.", exclude=True
121119
)
122120
generate_kwargs: dict[str, Any] = Field(

private_gpt/components/llm/llm_component.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self) -> None:
3737

3838
self.llm = SagemakerLLM(
3939
endpoint_name=settings.sagemaker.endpoint_name,
40+
messages_to_prompt=messages_to_prompt,
41+
completion_to_prompt=completion_to_prompt,
4042
)
4143
case "openai":
4244
from llama_index.llms import OpenAI

settings-docker.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ server:
33
port: ${PORT:8080}
44

55
llm:
6-
mode: local
6+
mode: ${PGPT_MODE:mock}
77

88
local:
9-
llm_hf_repo_id: TheBloke/Mistral-7B-Instruct-v0.1-GGUF
10-
llm_hf_model_file: mistral-7b-instruct-v0.1.Q4_K_M.gguf
11-
embedding_hf_model_name: BAAI/bge-small-en-v1.5
9+
llm_hf_repo_id: ${PGPT_HF_REPO_ID:TheBloke/Mistral-7B-Instruct-v0.1-GGUF}
10+
llm_hf_model_file: ${PGPT_HF_MODEL_FILE:mistral-7b-instruct-v0.1.Q4_K_M.gguf}
11+
embedding_hf_model_name: ${PGPT_EMBEDDING_HF_MODEL_NAME:BAAI/bge-small-en-v1.5}
12+
13+
sagemaker:
14+
endpoint_name: ${PGPT_SAGEMAKER_ENDPOINT_NAME:}
1215

1316
ui:
1417
enabled: true

0 commit comments

Comments
 (0)