Skip to content

Commit 8bf90d1

Browse files
committed
update DMR endpoint to match docs, update demo flow, update diagram
1 parent 7190508 commit 8bf90d1

File tree

4 files changed

+35
-47
lines changed

4 files changed

+35
-47
lines changed

.env.compose

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
DMR=true
22
REACT_APP_NODE_ENV=development
33
REACT_APP_LOCAL=localhost
4-
REACT_APP_MODEL_SERVICE=host.docker.internal
5-
REACT_APP_MODEL_PORT=12434
6-
REACT_APP_MODEL_PATH=/engines/llama.cpp/v1/chat/completions
4+
REACT_APP_MODEL_SERVICE=model-runner.docker.internal
75
REACT_APP_SERVER_PORT=5002

Demo.md

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,50 @@ This demonstration will walk through this project to showcase Docker's build, te
1010
- Select the stars on the top left to "Ask Gordon"
1111
- Select Explain my Dockerfile -> Give access to CatBot directory
1212
- See the various descriptions of lines in the Dockerfile
13-
14-
Knowing this, let's start developing.
13+
- Let's run this and see it in action.
1514

1615
## Running in my dev environment
17-
### Containers, TestContainers, TCC 🐳
16+
### Topics: Docker Model Runner, Containers, Docker Compose 🐳
1817
- Navigate back to project on VS Code
19-
- Start model container as instructed in README: `docker run -p 11434:11434 --name model samanthamorris684/ollama@sha256:78a199fa9652a16429037726943a82bd4916975fecf2b105d06e140ae70a1420`
20-
- Run app locally using: `dotenv -e .env.dev -- npm run start:dev`
2118
- Split view between VSCode and Chrome
19+
- Run `docker compose up --build`
20+
- Build the images and run them
2221
- Navigate to localhost:3000 on Chrome
23-
- *Note: We are only running the LLM container*
2422
- Test it out!
25-
- *What if I wanted to test this locally?*
23+
- *How did this work?*
24+
- Move into Docker Compose `compose.yaml`
25+
- See we automatically spun up a frontend and a backend service
26+
- *How did the cat talk to us?*
27+
- *Easy: We are using Docker Model Runner to run a model locally.*
28+
- Review logs where we connect to `http://model-runner.docker.internal/engines/llama.cpp/v1/chat/completions`
29+
- Navigate to `server.js`
30+
- *Note that we are interacting with the model through an OpenAI endpoint (chat/completions) from within the backend container*
31+
- Take down services with `docker compose down`
32+
- *How can we learn more about models?*
33+
- In a separate terminal, run `docker model ls`
34+
- See you can run a model using `docker model run ai/llama3.2`
35+
- Exit with `/bye`
36+
- :red_circle: NAVIGATE BACK TO SLIDES
37+
38+
39+
## Let's scan what we built our image and test our code!
40+
### Topics: Scout, TCC 🐳
41+
- Navigate to Docker Desktop and search for image build from compose
42+
- Run analysis for vulnerabilities with Docker Scout
43+
- Navigate back to VS Code
2644
- Split VS Code and Docker Desktop
2745
- Navigate to tests/server.test.js and show TestContainers logic
2846
- Run `npm test` and watch test run, containers appear in DD
2947
- Switch to TestContainers cloud and re-run `npm test`, notice the containers do not appear in DD
3048
- View results in [TCC dashboard](https://app.testcontainers.cloud/accounts/9926/dashboard)
31-
32-
33-
## Let's build and scan our image!
34-
### Topics: Build, Build Cloud, and Scout 🐳
35-
- Let's try to build this locally: `docker build -t samanthamorris684/catbot:nobc . --platform="linux/amd64"`
36-
- *Note: This will only leverage local caching!*
37-
- We can also use build cloud remote bulder: `docker buildx build --builder cloud-demonstrationorg-default -t samanthamorris684/catbot:bc . --platform="linux/amd64"`
38-
- Subsequent builds of this image will use the shared build cache on different machines, making builds faster! [Take a look.](https://app.docker.com/build/accounts/demonstrationorg/builds)
39-
- *Note: We will also make use of build cloud in the CI pipeline.*
40-
- Navigate to Docker Desktop and search for image build
41-
- Run analysis for vulnerabilities with Docker Scout
42-
43-
## How can we start up and tear down all these services together, and use containers for all?
44-
45-
### Topics: Docker Compose 🐳
46-
47-
- Navigate to the compose.yaml file
48-
- Two different containers/services, port mapping to access entry of app on port 3000
49-
- *Note: These containers will be able to talk to each other via their exposed ports*
50-
- Run `docker compose up --build`
51-
- Navigate to localhost:3000
52-
- When done, run `docker compose down`
49+
- :red_circle: NAVIGATE BACK TO SLIDES
5350

5451
## Bonus: How can we automate this?
5552

5653
- You can use a pipeline to automate this process, in this case we use GitHub Actions
5754
- Let's make a quick PR.
5855
- Edit line 213 of App.js to a different cat name
59-
- Quick preview of a frontend change by running `dotenv -e .env.dev -- npm run start:dev`
56+
- Quick preview of change by running `docker compose up --build`
6057
- `git checkout -b new-cat`
6158
- `git add src/App.js` && `git commit -m "Change cat name"`
6259
- `git push`
@@ -65,6 +62,8 @@ Knowing this, let's start developing.
6562

6663
- Navigate to GitHub and open a PR then see the pipeline for building, testing, and scanning
6764

65+
- See we built our images with a cloud builder, navigate to [cloud builds](https://app.docker.com/build/accounts/demonstrationorg/builds) to see.
66+
6867
- *Note: On merge, we kick off the deployment to prod, but we won't show that here!*
6968

70-
- Navigate back to diagram slide to close out.
69+
- :red_circle: NAVIGATE BACK TO SLIDES

images/catbotfull.png

-67.4 KB
Loading

server.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ async function handleStreamRequest(req, res) {
4444

4545
try {
4646
const host = ("REACT_APP_MODEL_SERVICE" in process.env) ? process.env.REACT_APP_MODEL_SERVICE : "model-published";
47-
const port = ("REACT_APP_MODEL_PORT" in process.env) ? process.env.REACT_APP_MODEL_PORT : 11434;
48-
const path = ("REACT_APP_MODEL_PATH" in process.env) ? process.env.REACT_APP_MODEL_PATH : "/api/generate";
49-
5047
const isDMR = "DMR" in process.env ? true : false;
5148

5249
// Add debug logging
@@ -56,11 +53,11 @@ async function handleStreamRequest(req, res) {
5653

5754
if (isDMR) {
5855
// Docker Model Runner (OpenAI format)
59-
console.log(`DMR endpoint: http://${host}:${port}${path}`);
56+
console.log(`DMR endpoint: http://${host}/engines/llama.cpp/v1/chat/completions`);
6057
console.log(`Model: ${model}`)
6158
response = await axios({
6259
method: 'post',
63-
url: `http://${host}:${port}${path}`,
60+
url: `http://${host}/engines/llama.cpp/v1/chat/completions`,
6461
data: {
6562
model: 'ai/' + model,
6663
messages: [{ role: "user", content: prompt }],
@@ -93,14 +90,12 @@ async function handleStreamRequest(req, res) {
9390
response.data.on('data', (chunk) => {
9491
try {
9592
const chunkStr = chunk.toString();
96-
console.log("Received chunk:", chunkStr.substring(0, 50) + (chunkStr.length > 50 ? '...' : ''));
97-
93+
9894
// Handle DMR (OpenAI) format - may contain multiple SSE events
9995
if (isDMR) {
10096
// Split by double newlines to handle multiple SSE events in one chunk
10197
const events = chunkStr.split('\n\n').filter(event => event.trim());
102-
console.log(`Found ${events.length} events in chunk`);
103-
98+
10499
for (const event of events) {
105100
if (event.startsWith('data: ')) {
106101
const dataContent = event.replace('data: ', '');
@@ -115,9 +110,6 @@ async function handleStreamRequest(req, res) {
115110
try {
116111
const data = JSON.parse(dataContent);
117112

118-
// Debug the received data structure
119-
console.log("Parsed DMR data:", JSON.stringify(data).substring(0, 100));
120-
121113
// Extract content based on what's available
122114
let content = '';
123115
if (data.choices && data.choices.length > 0) {
@@ -138,7 +130,6 @@ async function handleStreamRequest(req, res) {
138130
};
139131

140132
if (content) {
141-
console.log(`Sending content: ${content.substring(0, 20)}${content.length > 20 ? '...' : ''}`);
142133
// Send to client
143134
res.write(`data: ${JSON.stringify(responseData)}\n\n`);
144135
}

0 commit comments

Comments
 (0)