diff --git a/api/src/index.ts b/api/src/index.ts index 57ae7d5..7df0576 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -52,7 +52,7 @@ router.post("/api/generate", async (_req, extra) => { // Open the default KV store. let kv = spinSdk.kv.openDefault(); let configuration = new Configuration({ - apiKey: decoder.decode(kv.get("openai_key")), + apiKey: spinSdk.config.get("openai_key") }); let openai = new OpenAIApi(configuration); diff --git a/spin.toml b/spin.toml index f9a426c..9315a6c 100644 --- a/spin.toml +++ b/spin.toml @@ -1,13 +1,12 @@ spin_version = "1" authors = ["Radu Matei "] description = "Simple Spin application calling OpenAI APIs" -name = "openai-demo2" +name = "chatgpt" trigger = { type = "http", base = "/" } version = "0.1.0" [variables] -openai_key = { required = true } - +openai_key = { required = true, secret = true } # Chat UI [[component]] @@ -16,6 +15,7 @@ id = "web" files = [{ source = "web", destination = "/" }] [component.trigger] route = "/..." +watch = ["index.html", "main.js", "styles.css"] # API [[component]] @@ -30,10 +30,11 @@ route = "/api/..." [component.build] command = "npm run build" workdir = "api" +watch = ["src/index.ts", "package.json"] # Spin KV explorer component [[component]] -source = { url = "https://github.com/radu-matei/spin-kv-explorer/releases/download/v0.5.0/spin-kv-explorer.wasm", digest = "sha256:d5f9e1f6b61b90f7404e3800285f7860fe2cfc7d0116023efc370adbb403fe87" } +source = { url = "https://github.com/radu-matei/spin-kv-explorer/releases/download/v0.9.0/spin-kv-explorer.wasm", digest = "sha256:07f5f0b8514c14ae5830af0f21674fd28befee33cd7ca58bc0a68103829f2f9c" } id = "kv-explorer" # add or remove stores you want to explore here key_value_stores = ["default"] diff --git a/web/main.js b/web/main.js index 22f0f23..a6c2375 100644 --- a/web/main.js +++ b/web/main.js @@ -65,7 +65,7 @@ function typeMessage(speaker, message) { // Function to handle sending a message to the OpenAI API async function sendMessageToAPI(id, message) { let response = await fetch("/api/generate", { method: "POST", body: JSON.stringify({ id: id, message: message }) }); - typeMessage("AI", await response.text()); + typeMessage("OpenAI", await response.text()); } // Event listener for send button click @@ -123,7 +123,7 @@ function notify(message) { const toggleDocsButton = document.getElementById('toggle-docs'); const docsSection = document.querySelector('.documentation'); -toggleDocsButton.addEventListener('click', function () { +toggleDocsButton.addEventListener('click', function() { if (docsSection.style.display === "none") { docsSection.style.display = "block"; } else {