diff --git a/README.md b/README.md index 230e224..59b56c6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,28 @@ -# wasm-packs +# Example of Cloud Native Buildpacks for Wasm +This repository contains a set of build packs and example Wasm applications to demonstrate how to build and run Wasm applications using Cloud Native Buildpacks. + +## The Parts +### Base Images +The `base-images` directory contains the Dockerfiles for the base images used by the buildpacks. The `build.sh` script builds the base images used for build +and run in the buildpacks. They are based on the Heroku stack images. + +### Builders +The `builders` directory contains the builder for the Wasm buildpacks. + +### Buildpacks +The `buildpacks` directory contains the buildpacks used in the builder. + +#### Meta-buildpacks +The `meta-buildpacks` directory contains the meta-buildpacks used in the builder. + +### Apps +The `apps` directory contains the example Wasm applications. The `js` directory contains a simple Wasm application written in Rust and compiled to Wasm. The `compose` directory contains a multi-component Wasm microservice application using both JS and Golang to demonstrate the use of multiple languages in a single application. + +## Building and Running the Example ```bash ./base-images/build.sh wasm pack builder create wasm/demo-builder:wasm --config ../builders/wasm/builder.toml -pack build test-wasm-js --builder wasm/demo-builder:wasm --path apps/js/ -docker run --rm -it -p 8080:8080 test-wasm-js +pack build wasm-compose --builder wasm/demo-builder:wasm --path apps/compose/ +docker run --rm -it -p 8080:8080 -e OPENAI_API_KEY wasm-compose ``` diff --git a/apps/compose/app-js/src/server.js b/apps/compose/app-js/src/server.js index a39b925..1106cd4 100644 --- a/apps/compose/app-js/src/server.js +++ b/apps/compose/app-js/src/server.js @@ -30,8 +30,9 @@ router }) .get("/chat", (request) => { let prompt = request.query["prompt"]; + let model = request.query["model"]; let chatRequest = { - model: "gpt-4o-mini", + model: model ?? "gpt-4o-mini", messages: [ { role: "user", diff --git a/apps/compose/service-go/service.go b/apps/compose/service-go/service.go index ca218ec..8f5c9ac 100644 --- a/apps/compose/service-go/service.go +++ b/apps/compose/service-go/service.go @@ -54,7 +54,8 @@ func init() { Message: chatErr.Message, }) } - return cm.OK[cm.Result[chat.ChatResponseShape, chat.ChatResponse, chat.Error]](res) + cmOk := cm.OK[cm.Result[chat.ChatResponseShape, chat.ChatResponse, chat.Error]](res) + return cmOk } } diff --git a/buildpacks/wac-composer/bin/build b/buildpacks/wac-composer/bin/build index abe0bfe..e86fd5f 100644 --- a/buildpacks/wac-composer/bin/build +++ b/buildpacks/wac-composer/bin/build @@ -40,6 +40,6 @@ cat > "${CNB_LAYERS_DIR}/launch.toml" << EOL [[processes]] type = "web" command = ["wasmtime"] -args = ["serve", "-S", "cli", "--env", "OPENAI_API_KEY", "--allow-precompiled", "${wasm_component_layer}/composed.cwasm"] +args = ["serve", "-S", "cli", "--env", "--allow-precompiled", "${wasm_component_layer}/composed.cwasm"] default = true EOL