Skip to content

Commit 96014d6

Browse files
authoredSep 10, 2024
Merge pull request #8 from copilot-extensions/tc/fix-build-script
update role type for messages
2 parents 8151a22 + 04fc9ce commit 96014d6

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed
 

‎package-lock.json

+6-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"license": "ISC",
1313
"description": "",
1414
"dependencies": {
15-
"@copilot-extensions/preview-sdk": "^2.6.1",
15+
"@copilot-extensions/preview-sdk": "^4.0.2",
1616
"express": "^4.19.2",
1717
"openai": "^4.55.0"
1818
},

‎src/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createServer, IncomingMessage } from "node:http";
22

3-
import { verifyAndParseRequest } from "@copilot-extensions/preview-sdk";
3+
import { verifyAndParseRequest, transformPayloadForOpenAICompatibility } from "@copilot-extensions/preview-sdk";
44
import OpenAI from "openai";
55

66
import { describeModel } from "./functions/describe-model.js";
@@ -44,6 +44,8 @@ const server = createServer(async (request, response) => {
4444

4545
console.log("Signature verified");
4646

47+
const compatibilityPayload = transformPayloadForOpenAICompatibility(payload);
48+
4749
// Use the GitHub API token sent in the request
4850
if (!apiKey) {
4951
response.statusCode = 400
@@ -66,7 +68,7 @@ const server = createServer(async (request, response) => {
6668
const models = await modelsAPI.listModels();
6769
const toolCallMessages = [
6870
{
69-
role: "system",
71+
role: "system" as const,
7072
content: [
7173
"You are an extension of GitHub Copilot, built to interact with GitHub Models.",
7274
"GitHub Models is a language model playground, where you can experiment with different models and see how they respond to your prompts.",
@@ -84,8 +86,8 @@ const server = createServer(async (request, response) => {
8486
"<-- END OF LIST OF MODELS -->",
8587
].join("\n"),
8688
},
87-
...payload.messages,
88-
].concat(payload.messages);
89+
...compatibilityPayload.messages,
90+
];
8991

9092
console.time("tool-call");
9193
const toolCaller = await capiClient.chat.completions.create({
@@ -108,7 +110,6 @@ const server = createServer(async (request, response) => {
108110
const stream = await capiClient.chat.completions.create({
109111
stream: true,
110112
model: "gpt-4o",
111-
// @ts-expect-error - TODO @gr2m - type incompatibility between @openai/api and @copilot-extensions/preview-sdk
112113
messages: payload.messages,
113114
});
114115

@@ -137,7 +138,6 @@ const server = createServer(async (request, response) => {
137138

138139
console.log("\t with args", args);
139140
const func = new funcClass(modelsAPI);
140-
// @ts-expect-error - TODO @gr2m - type incompatibility between @openai/api and @copilot-extensions/preview-sdk
141141
functionCallRes = await func.execute(payload.messages, args);
142142
} catch (err) {
143143
console.error(err);

0 commit comments

Comments
 (0)
Failed to load comments.