Skip to content

Commit c1e8167

Browse files
committed
feat(frontend): create fastapi backend and JS frontend for interacting with tuned model
1 parent da8b80e commit c1e8167

33 files changed

+19712
-71
lines changed

Dockerfile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
1-
# Stage 1: Build Backend
1+
# Stage 1: Build Frontend
2+
FROM node:18-alpine AS frontend-builder
3+
WORKDIR /frontend
4+
COPY chat-ui/ .
5+
RUN npm install
6+
RUN npm run build
7+
8+
# Stage 2: Build Backend
29
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS backend-builder
310
ADD . /flare-ai-social
411
WORKDIR /flare-ai-social
512
RUN uv sync --frozen
613

7-
# Stage 2: Final Image
14+
# Stage 3: Final Image
815
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
916

17+
# Install nginx
18+
RUN apt-get update && apt-get install -y nginx supervisor curl && \
19+
rm -rf /var/lib/apt/lists/*
20+
1021
WORKDIR /app
1122
COPY --from=backend-builder /flare-ai-social/.venv ./.venv
1223
COPY --from=backend-builder /flare-ai-social/src ./src
1324
COPY --from=backend-builder /flare-ai-social/pyproject.toml .
1425
COPY --from=backend-builder /flare-ai-social/README.md .
1526

27+
# Copy frontend files
28+
COPY --from=frontend-builder /frontend/build /usr/share/nginx/html
29+
30+
# Copy nginx configuration
31+
COPY nginx.conf /etc/nginx/sites-enabled/default
32+
33+
# Setup supervisor configuration
34+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
35+
1636
# Allow workload operator to override environment variables
17-
LABEL "tee.launch_policy.allow_env_override"="GEMINI_API_KEY,GEMINI_MODEL"
37+
LABEL "tee.launch_policy.allow_env_override"="GEMINI_API_KEY,TUNED_MODEL_NAME,SIMULATE_ATTESTATION"
1838
LABEL "tee.launch_policy.log_redirect"="always"
1939

20-
CMD ["uv", "run", "start-social"]
40+
EXPOSE 80
41+
42+
# Start supervisor (which will start both nginx and the backend)
43+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

README.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ Flare AI Kit template for Social AI Agents.
44

55
## 🏗️ Build & Run Instructions
66

7-
### Fine tuning a model over a dataset
8-
9-
1. **Prepare the Environment File:**
7+
**Prepare the Environment File:**
108
Rename `.env.example` to `.env` and update the variables accordingly.
119
Some parameters are specific to model fine-tuning:
1210

@@ -18,25 +16,48 @@ Flare AI Kit template for Social AI Agents.
1816
| `batch_size` | Number of examples to use in each training batch. | `4` |
1917
| `learning_rate` | Step size multiplier for the gradient updates. | `0.001` |
2018

21-
2. **Prepare a dataset:**
19+
### Fine tuning a model over a dataset
20+
21+
1. **Prepare a dataset:**
2222
An example dataset is provided in `src/data/training_data.json`, which consists of tweet from
2323
[Hugo Philion's X](https://x.com/HugoPhilion) account. You can use any publicly available dataset
2424
for model fine-tuning.
2525

26-
3. **Tune a new model**
26+
2. **Tune a new model**
2727
Set the name of the new tuned model in `src/flare_ai_social/tune_model.py`, then:
2828

2929
```bash
3030
uv run start-tuning
3131
```
3232

33-
4. **Observe loss parameters:**
33+
3. **Observe loss parameters:**
3434
After tuning in complete, a training loss PNG will be saved in the root folder corresponding to the new model.
3535
Ideally the loss should minimize to near 0 after several training epochs.
3636

37-
5. **Test the new model**
38-
Select the new tuned model and test it against a set of prompts:
37+
4. **Test the new model**
38+
Select the new tuned model and compare it against a set of prompting techniques (zero-shot, few-shot and chain-of-thought):
39+
40+
```bash
41+
uv run start-compare
42+
```
43+
44+
### Build using Docker (Recommended)
45+
46+
**Note:** You can only perform this step once you have finishing training a new model.
47+
48+
The Docker setup mimics a TEE environment and includes an Nginx server for routing, while Supervisor manages both the backend and frontend services in a single container.
49+
50+
1. **Build the Docker Image:**
51+
52+
```bash
53+
docker build -t flare-ai-social .
54+
```
55+
56+
2. **Run the Docker Container:**
3957

4058
```bash
41-
uv run start-social
59+
docker run -p 80:80 -it --env-file .env flare-ai-social
4260
```
61+
62+
3. **Access the Frontend:**
63+
Open your browser and navigate to [http://localhost:80](http://localhost:80) to interact with the Chat UI.

chat-ui/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

chat-ui/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13+
14+
The page will reload when you make changes.\
15+
You may also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
35+
36+
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39+
40+
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

0 commit comments

Comments
 (0)