Skip to content

Commit

Permalink
Merge pull request #8 from copilot-extensions/tc/fix-build-script
Browse files Browse the repository at this point in the history
update role type for messages
  • Loading branch information
theodoracheng authored Sep 10, 2024
2 parents 8151a22 + 04fc9ce commit 96014d6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
19 changes: 6 additions & 13 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@copilot-extensions/preview-sdk": "^2.6.1",
"@copilot-extensions/preview-sdk": "^4.0.2",
"express": "^4.19.2",
"openai": "^4.55.0"
},
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServer, IncomingMessage } from "node:http";

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

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

console.log("Signature verified");

const compatibilityPayload = transformPayloadForOpenAICompatibility(payload);

// Use the GitHub API token sent in the request
if (!apiKey) {
response.statusCode = 400
Expand All @@ -66,7 +68,7 @@ const server = createServer(async (request, response) => {
const models = await modelsAPI.listModels();
const toolCallMessages = [
{
role: "system",
role: "system" as const,
content: [
"You are an extension of GitHub Copilot, built to interact with GitHub Models.",
"GitHub Models is a language model playground, where you can experiment with different models and see how they respond to your prompts.",
Expand All @@ -84,8 +86,8 @@ const server = createServer(async (request, response) => {
"<-- END OF LIST OF MODELS -->",
].join("\n"),
},
...payload.messages,
].concat(payload.messages);
...compatibilityPayload.messages,
];

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

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

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

0 comments on commit 96014d6

Please sign in to comment.