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": "../../" + } +}