1
1
import { createServer , IncomingMessage } from "node:http" ;
2
2
3
- import { verifyAndParseRequest } from "@copilot-extensions/preview-sdk" ;
3
+ import { verifyAndParseRequest , transformPayloadForOpenAICompatibility } from "@copilot-extensions/preview-sdk" ;
4
4
import OpenAI from "openai" ;
5
5
6
6
import { describeModel } from "./functions/describe-model.js" ;
@@ -44,6 +44,8 @@ const server = createServer(async (request, response) => {
44
44
45
45
console . log ( "Signature verified" ) ;
46
46
47
+ const compatibilityPayload = transformPayloadForOpenAICompatibility ( payload ) ;
48
+
47
49
// Use the GitHub API token sent in the request
48
50
if ( ! apiKey ) {
49
51
response . statusCode = 400
@@ -66,7 +68,7 @@ const server = createServer(async (request, response) => {
66
68
const models = await modelsAPI . listModels ( ) ;
67
69
const toolCallMessages = [
68
70
{
69
- role : "system" ,
71
+ role : "system" as const ,
70
72
content : [
71
73
"You are an extension of GitHub Copilot, built to interact with GitHub Models." ,
72
74
"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) => {
84
86
"<-- END OF LIST OF MODELS -->" ,
85
87
] . join ( "\n" ) ,
86
88
} ,
87
- ...payload . messages ,
88
- ] . concat ( payload . messages ) ;
89
+ ...compatibilityPayload . messages ,
90
+ ] ;
89
91
90
92
console . time ( "tool-call" ) ;
91
93
const toolCaller = await capiClient . chat . completions . create ( {
@@ -108,7 +110,6 @@ const server = createServer(async (request, response) => {
108
110
const stream = await capiClient . chat . completions . create ( {
109
111
stream : true ,
110
112
model : "gpt-4o" ,
111
- // @ts -expect-error - TODO @gr2m - type incompatibility between @openai/api and @copilot-extensions/preview-sdk
112
113
messages : payload . messages ,
113
114
} ) ;
114
115
@@ -137,7 +138,6 @@ const server = createServer(async (request, response) => {
137
138
138
139
console . log ( "\t with args" , args ) ;
139
140
const func = new funcClass ( modelsAPI ) ;
140
- // @ts -expect-error - TODO @gr2m - type incompatibility between @openai/api and @copilot-extensions/preview-sdk
141
141
functionCallRes = await func . execute ( payload . messages , args ) ;
142
142
} catch ( err ) {
143
143
console . error ( err ) ;
0 commit comments