From fecff98d55902b950c88a98b5b23a57cb62b94f6 Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:52:01 -0700 Subject: [PATCH] docs(examples): hello-world-without-sdk (#96) closes #95 Co-authored-by: francisfuzz <15894826+francisfuzz@users.noreply.github.com> --- examples/hello-world-without-sdk/index.js | 26 +++++++++++++++++++ examples/hello-world-without-sdk/package.json | 11 ++++++++ 2 files changed, 37 insertions(+) create mode 100644 examples/hello-world-without-sdk/index.js create mode 100644 examples/hello-world-without-sdk/package.json diff --git a/examples/hello-world-without-sdk/index.js b/examples/hello-world-without-sdk/index.js new file mode 100644 index 0000000..cc24728 --- /dev/null +++ b/examples/hello-world-without-sdk/index.js @@ -0,0 +1,26 @@ +import { createServer } from "node:http"; + +const server = createServer((request, response) => { + if (request.method === "GET") { + return response.end("ok"); + } + + const textObject = { + choices: [ + { index: 0, delta: { content: "Hello, world!", role: "assistant" } }, + ], + }; + + const endObject = { + choices: [{ index: 0, finish_reason: "stop", delta: { content: null } }], + }; + + // note the "\n\n"s, they are significant. + response.write(`data: ${JSON.stringify(textObject)}\n\n`); + response.end(`data: ${JSON.stringify(endObject)}\n\ndata: [DONE]\n\n`); +}); + +const PORT = process.env.PORT || 3000; +server.listen(PORT, () => { + console.log(`Server is running on port ${PORT}`); +}); diff --git a/examples/hello-world-without-sdk/package.json b/examples/hello-world-without-sdk/package.json new file mode 100644 index 0000000..6e843dc --- /dev/null +++ b/examples/hello-world-without-sdk/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "type": "module", + "scripts": { + "start": "node index.js", + "watch": "node --watch index.js" + }, + "dependencies": { + "@copilot-extensions/preview-sdk": "../../" + } +}