Skip to content

Commit a42b6f4

Browse files
authored
Merge pull request #8 from devigned/openai
Add an example of OpenAI chat completion
2 parents 33b4bf0 + b0350d4 commit a42b6f4

109 files changed

Lines changed: 875 additions & 113 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/compose/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SHELL:=/usr/bin/env bash
22
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
3-
SERVER_COMPONENT_NAME := server.component.wasm
4-
GO_COMPONENT_NAME := add.wasm
3+
SERVER_COMPONENT_NAME := frontend.wasm
4+
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
@@ -19,23 +19,23 @@ build: build-js build-go build-compose ## Run all build steps.
1919
.PHONY: build-js
2020
build-js: ## Build the JavaScript component.
2121
$(info "Building JavaScript Component...")
22-
@cd "$(ROOT_DIR)/app-js" && npm install && npm run build
22+
@cd "$(ROOT_DIR)/app-js" && npm install && COMPONENT_NAME=frontend.wasm npm run build
2323

2424
.PHONY: build-go
2525
build-go: ## Build the Go component.
2626
$(info "Building Golang Component...")
27-
@cd $(ROOT_DIR)/service-go && go generate && tinygo build -target=wasip2 -o add.wasm --wit-package ./wit --wit-world adder service.go
27+
@cd $(ROOT_DIR)/service-go && go generate && tinygo build -target=wasip2 -o service.wasm --wit-package ./wit --wit-world backend service.go
2828

2929
.PHONY: build-compose
3030
build-compose: ## Compose the microservice app with the constituent components.
3131
$(info "Fusing components together with wac...")
3232
# @wac plug --plug $(GO_COMPONENT_PATH) -o composed.wasm $(SERVER_COMPONENT_PATH)
33-
wac compose --dep example:math=$(GO_COMPONENT_PATH) --dep example:server=$(SERVER_COMPONENT_PATH) -o composed.wasm compose.wac
33+
wac compose --dep example:service=$(GO_COMPONENT_PATH) --dep example:server=$(SERVER_COMPONENT_PATH) -o composed.wasm compose.wac
3434

3535
.PHONY: run
3636
run: ## Run the microservice app after build.
3737
$(info "Running Component Application Using Wasmtime...")
38-
wasmtime serve -S cli $(COMPOSED_COMPONENT_PATH)
38+
wasmtime serve -S cli --env OPENAI_API_KEY="$${OPENAI_API_KEY}" $(COMPOSED_COMPONENT_PATH)
3939

4040
.PHONY: build-and-run
4141
build-and-run: build run ## Build and run the microservice app.

apps/compose/app-js/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist

apps/compose/app-js/componentize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { componentize } from "@bytecodealliance/componentize-js";
66
// AoT compilation makes use of weval (https://github.com/bytecodealliance/weval)
77
const enableAot = process.env.ENABLE_AOT == "1";
88

9-
const jsSource = await readFile("server.js", "utf8");
9+
const jsSource = await readFile("./dist/index.js", "utf8");
1010

1111
const { component } = await componentize(jsSource, {
1212
witPath: resolve("wit"),
13+
debug: true,
1314
enableAot,
1415
});
1516

0 commit comments

Comments
 (0)