Skip to content

Commit dc155bc

Browse files
committed
feat(docker): add Dockerfile, action
1 parent a758451 commit dc155bc

File tree

4 files changed

+140
-2
lines changed

4 files changed

+140
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Push
2+
3+
on:
4+
push:
5+
# tags: ["v*.*.*"] # Match semantic versioning tags like v1.0.0
6+
branches: ["main"]
7+
workflow_dispatch: # Allow manual triggering of the workflow
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
attestations: write
20+
id-token: write
21+
steps:
22+
# Checkout repository
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
# Log in to GHCR
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ${{ env.REGISTRY }}
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
# Generate Docker metadata
35+
- name: Metadata for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
41+
# Cache Docker layers to speed up builds
42+
- name: Cache Docker layers
43+
uses: actions/cache@v3
44+
with:
45+
path: /tmp/.buildx-cache
46+
key: ${{ runner.os }}-docker-${{ github.ref }}
47+
restore-keys: |
48+
${{ runner.os }}-docker-
49+
50+
# Build and push Docker image
51+
- name: Build and push Docker image
52+
uses: docker/build-push-action@v6
53+
id: push
54+
with:
55+
context: .
56+
push: true
57+
load: true
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Stage 1: Build Backend
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS backend-builder
3+
ADD . /flare-ai-social
4+
WORKDIR /flare-ai-social
5+
RUN uv sync --frozen
6+
7+
# Stage 2: Final Image
8+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
9+
10+
WORKDIR /app
11+
COPY --from=backend-builder /flare-ai-social/.venv ./.venv
12+
COPY --from=backend-builder /flare-ai-social/src ./src
13+
COPY --from=backend-builder /flare-ai-social/pyproject.toml .
14+
COPY --from=backend-builder /flare-ai-social/README.md .
15+
16+
# Allow workload operator to override environment variables
17+
LABEL "tee.launch_policy.allow_env_override"="GEMINI_API_KEY,GEMINI_MODEL"
18+
LABEL "tee.launch_policy.log_redirect"="always"
19+
20+
CMD ["uv", "run", "start-social"]

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@ Flare AI Kit template for Social AI Agents.
44

55
## 🏗️ Build & Run Instructions
66

7+
### Fine tuning a model over a dataset
8+
79
1. **Prepare the Environment File:**
810
Rename `.env.example` to `.env` and update the variables accordingly.
11+
Some parameters are specific to model fine-tuning:
12+
13+
| Parameter | Description | Default |
14+
| --------------------- | -------------------------------------------------------------------------- | ------------------------------------ |
15+
| `tuning_source_model` | Name of the model to tune. | `models/gemini-1.5-flash-001-tuning` |
16+
| `epoch_count` | Number of tuning epochs to run. An epoch is a pass over the whole dataset. | `100` |
17+
| `batch_size` | Number of examples to use in each training batch. | `4` |
18+
| `learning_rate` | Step size multiplier for the gradient updates. | `0.001` |
919

10-
2. **Tune a new model**
20+
2. **Prepare a dataset:**
21+
An example dataset is provided in `src/data/training_data.json`, which consists of tweet from
22+
[Hugo Philion's X](https://x.com/HugoPhilion) account. You can use any publicly available dataset
23+
for model fine-tuning.
24+
25+
3. **Tune a new model**
26+
Set the name of the new tuned model in `src/flare_ai_social/tune_model.py`, then:
1127

1228
```bash
1329
uv run start-tuning
1430
```
1531

16-
3. **Test the new model**
32+
4. **Observe loss parameters:**
33+
After tuning in complete, a training loss PNG will be saved in the root folder corresponding to the new model.
34+
Ideally the loss should minimize to near 0 after several training epochs.
35+
36+
5. **Test the new model**
37+
Select the new tuned model and test it:
1738

1839
```bash
1940
uv run start-social

uv.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)