Skip to content

Commit

Permalink
add @ts-expect-errors for type-interop problems between OpenAI and …
Browse files Browse the repository at this point in the history
…Copilot Extension SDKs
  • Loading branch information
gr2m committed Sep 6, 2024
1 parent bee45e7 commit c7052ad
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,14 +89,20 @@ 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)
toolCaller.choices

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
Expand All @@ -107,6 +112,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) {
Expand All @@ -133,7 +140,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
Expand Down

0 comments on commit c7052ad

Please sign in to comment.