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

update role type for messages #8

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked breaking changes, does not affect the code in this app

"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