突然头脑发热订阅了 Github Copilot,突然发现可以自己创建一个 Copilot Agent 来创建一个 Copilot Extension。在看到 Github 官方给出的例子 blackbeard-extension 的时候发现它例子里面就有调用 Github Chat Completions API 的代码。
messages.unshift({
role: "system",
content: `Start every response with the user's name, which is @${user.data.login}`,
});
// Use Copilot's LLM to generate a response to the user's messages, with
// our extra system messages attached.
const copilotLLMResponse = await fetch(
"https://api.githubcopilot.com/chat/completions",
{
method: "POST",
headers: {
authorization: `Bearer ${tokenForUser}`,
"content-type": "application/json",
},
body: JSON.stringify({
messages,
stream: true,
}),
}
);
// Stream the response straight back to the user.
Readable.from(copilotLLMResponse.body).pipe(res);
这段代码来自官方例子。
我之前在哪里好像看到过说将 Copilot Chat 转 API 来使用就会被封号。但在代码里明显是调用了官方的 Chat API 的。虽说这个是 Agent 行为,但本质上不就是直接调用 Chat API 吗?
所以来论坛问一下。