Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use @copilot-extensions/preview-sdk to call LLM #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Octokit } from "@octokit/core";
import express from "express";
import { Readable } from "node:stream";
import { prompt } from '@copilot-extensions/preview-sdk';

const app = express()

Expand Down Expand Up @@ -28,26 +29,16 @@ app.post("/", express.json(), async (req, res) => {

// Use Copilot's LLM to generate a response to the user's messages, with
// our extra system messages attached.
const copilotLLMResponse = await fetch(
"https://api.githubcopilot.com/chat/completions",
{
method: "POST",
headers: {
authorization: `Bearer ${tokenForUser}`,
"content-type": "application/json",
},
body: JSON.stringify({
messages,
stream: true,
}),
}
);
const copilotLLMResponse = await prompt.stream({
token: tokenForUser,
messages
});

// Stream the response straight back to the user.
Readable.from(copilotLLMResponse.body).pipe(res);
Readable.from(copilotLLMResponse.stream).pipe(res);
})

const port = Number(process.env.PORT || '3000')
app.listen(port, () => {
console.log(`Server running on port ${port}`)
});
});
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"type": "module",
"dependencies": {
"@copilot-extensions/preview-sdk": "^5.0.1",
"@octokit/core": "^6.1.2",
"express": "^4.19.2"
}
}
}