From 7b2881241fa755c4b90affaee118c467d20f637b Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:11:17 -0700 Subject: [PATCH] add `@ts-expect-errors` for type-interop problems between OpenAI and Copilot Extension SDKs --- src/index.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1537c3e..4ef249a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,6 @@ import { ModelsAPI } from "./models-api.js"; const server = createServer(async (request, response) => { if (request.method === "GET") { - // health check response.statusCode = 200; response.end(`OK`); return; @@ -90,14 +89,18 @@ const server = createServer(async (request, response) => { console.time("tool-call"); const toolCaller = await capiClient.chat.completions.create({ + // @ts-expect-error - type error due to Copilot/OpenAI SDKs interop, I'll look into it ~@gr2m messages: toolCallMessages, stream: false, model: "gpt-4", tools: functions.map((f) => f.tool), - }) + }); console.timeEnd("tool-call"); - const [functionToCall] = getFunctionCalls(toolCaller) + const [functionToCall] = getFunctionCalls( + // @ts-expect-error - type error due to Copilot/OpenAI SDKs interop, I'll look into it ~@gr2m + toolCaller.choices[0].message + ) if ( !functionToCall @@ -107,6 +110,8 @@ const server = createServer(async (request, response) => { const stream = await capiClient.chat.completions.create({ stream: true, model: "gpt-4", + // @ts-expect-error - type error due to Copilot/OpenAI SDKs interop, I'll look into it ~@gr2m + messages: payload.messages }); for await (const chunk of stream) { @@ -133,7 +138,11 @@ const server = createServer(async (request, response) => { console.log("\t with args", args); const func = new funcClass(modelsAPI); - functionCallRes = await func.execute(payload.messages, args); + functionCallRes = await func.execute( + // @ts-expect-error - type error due to Copilot/OpenAI SDKs interop, I'll look into it ~@gr2m + payload.messages, + args + ); } catch (err) { console.error(err); response.statusCode = 500