Skip to content

Commit

Permalink
docs(examples): hello-world-without-sdk (#96)
Browse files Browse the repository at this point in the history
closes #95

Co-authored-by: francisfuzz <[email protected]>
  • Loading branch information
gr2m and francisfuzz authored Sep 17, 2024
1 parent cf87d43 commit fecff98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/hello-world-without-sdk/index.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
11 changes: 11 additions & 0 deletions examples/hello-world-without-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"type": "module",
"scripts": {
"start": "node index.js",
"watch": "node --watch index.js"
},
"dependencies": {
"@copilot-extensions/preview-sdk": "../../"
}
}

0 comments on commit fecff98

Please sign in to comment.