Skip to content

Commit 371512b

Browse files
authored
Merge pull request #9 from devigned/precompile
precompile the wasm component
2 parents a42b6f4 + 7c1f322 commit 371512b

9 files changed

Lines changed: 12 additions & 65 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
**/target
33

44
**/*.wasm
5+
**/*.cwasm
56

67
**/.projects.json

apps/compose/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GO_COMPONENT_NAME := service.wasm
55
SERVER_COMPONENT_PATH := $(ROOT_DIR)/app-js/$(SERVER_COMPONENT_NAME)
66
GO_COMPONENT_PATH := $(ROOT_DIR)/service-go/$(GO_COMPONENT_NAME)
77
COMPOSED_COMPONENT_PATH := $(ROOT_DIR)/composed.wasm
8+
COMPOSED_COMPILED_COMPONENT_PATH := $(ROOT_DIR)/composed.cwasm
89
.DEFAULT_GOAL:=help
910

1011
## --------------------------------------
@@ -31,11 +32,12 @@ build-compose: ## Compose the microservice app with the constituent components.
3132
$(info "Fusing components together with wac...")
3233
# @wac plug --plug $(GO_COMPONENT_PATH) -o composed.wasm $(SERVER_COMPONENT_PATH)
3334
wac compose --dep example:service=$(GO_COMPONENT_PATH) --dep example:server=$(SERVER_COMPONENT_PATH) -o composed.wasm compose.wac
35+
wasmtime compile $(COMPOSED_COMPONENT_PATH)
3436

3537
.PHONY: run
3638
run: ## Run the microservice app after build.
3739
$(info "Running Component Application Using Wasmtime...")
38-
wasmtime serve -S cli --env OPENAI_API_KEY="$${OPENAI_API_KEY}" $(COMPOSED_COMPONENT_PATH)
40+
wasmtime serve -S cli --env OPENAI_API_KEY --allow-precompiled $(COMPOSED_COMPILED_COMPONENT_PATH)
3941

4042
.PHONY: build-and-run
4143
build-and-run: build run ## Build and run the microservice app.
@@ -45,7 +47,7 @@ build-and-run: build run ## Build and run the microservice app.
4547
.PHONY: clean
4648
clean: ## Clean up the build artifacts.
4749
@echo "Cleaning up build artifacts..."
48-
@rm -rf $(SERVER_COMPONENT_PATH) $(GO_COMPONENT_PATH) $(COMPOSED_COMPONENT_PATH)
50+
@rm -rf $(SERVER_COMPONENT_PATH) $(GO_COMPONENT_PATH) $(COMPOSED_COMPONENT_PATH) $(COMPOSED_COMPILED_COMPONENT_PATH)
4951

5052
help: ## Display this help.
5153
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9a-zA-Z_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

apps/compose/app-js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"rollup-plugin-polyfill-node": "^0.13.0"
1010
},
1111
"scripts": {
12-
"build:jco": "jco types -h ./wit",
1312
"build:rollup": "rollup -c",
1413
"build": "wkg wit fetch && npm run build:rollup && node componentize.js"
1514
},

apps/compose/app-js/src/server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ router
3131
.get("/chat", (request) => {
3232
let prompt = request.query["prompt"];
3333
let chatRequest = {
34-
model: "gpt-3.5-turbo",
34+
model: "gpt-4o-mini",
3535
messages: [
3636
{
3737
role: "user",
@@ -42,7 +42,6 @@ router
4242

4343
// send the request to the chat function, which is the Golang backend component.
4444
let result = chat(chatRequest);
45-
console.log("result", result);
4645
return {
4746
result: result,
4847
};

apps/compose/service-go/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func init() {
2828

2929
run.Exports.Run = func() cm.BoolResult {
3030
res, err := chatCompletion(chat.ChatRequest{
31-
Model: "gpt-4o",
31+
Model: "gpt-4o-mini",
3232
Messages: cm.ToList([]domainTypes.Message{
3333
{
3434
Role: "user",

buildpacks/python/bin/build

Lines changed: 0 additions & 17 deletions
This file was deleted.

buildpacks/python/bin/detect

Lines changed: 0 additions & 29 deletions
This file was deleted.

buildpacks/python/buildpack.toml

Lines changed: 0 additions & 11 deletions
This file was deleted.

buildpacks/wac-composer/bin/build

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ echo "wac-composer: running compose command: '${compose_cmd}' to create composed
2222
# command should look something like: `wac compose --dep example:math=./component_path1/math.wasm --dep example:server=./component_path2/server.wasm -o composed.wasm compose.wac`
2323
$compose_cmd
2424

25+
wasmtime compile composed.wasm
26+
2527
wasm_component_layer="${CNB_LAYERS_DIR}/wac-composer"
2628
mkdir -p "${wasm_component_layer}"
2729
cat > "${wasm_component_layer}.toml" << EOL
@@ -31,12 +33,13 @@ cache = false
3133
build = false
3234
EOL
3335

34-
cp composed.wasm "${wasm_component_layer}"
36+
cp composed.cwasm "${wasm_component_layer}"
3537

3638
# Set default start command
3739
cat > "${CNB_LAYERS_DIR}/launch.toml" << EOL
3840
[[processes]]
3941
type = "web"
40-
command = ["wasmtime", "serve", "-S", "cli", "${wasm_component_layer}/composed.wasm"]
42+
command = ["wasmtime"]
43+
args = ["serve", "-S", "cli", "--env", "OPENAI_API_KEY", "--allow-precompiled", "${wasm_component_layer}/composed.cwasm"]
4144
default = true
4245
EOL

0 commit comments

Comments
 (0)