Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d30fd1eb5 | ||
|
|
8265975098 | ||
|
|
5aaf3f4f97 | ||
|
|
90a51287b4 | ||
|
|
a252f90b62 | ||
|
|
a789afbd61 | ||
|
|
ac9e439191 | ||
|
|
215ec19ba1 | ||
|
|
e74d97f4ae | ||
|
|
b5c2924886 | ||
|
|
892151ef92 | ||
|
|
503273f17d | ||
|
|
bbf1b56a76 | ||
|
|
9b6e78e9f5 | ||
|
|
4e50c28def | ||
|
|
8f1d71d913 | ||
|
|
e9a060af0f | ||
|
|
46b8d7e888 | ||
|
|
0460305327 | ||
|
|
c4bb02a7a2 | ||
|
|
f295cb8535 |
No files matched your search
+77
-4
@@ -8,7 +8,75 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|||||||
and this project adheres to
|
and this project adheres to
|
||||||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [0.4.1] - 2026-11-08
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Moved the Marketplace `baseContentUrl`/`baseImagesUrl` settings into a
|
||||||
|
`vsce` block in package.json. vsce only reads them from there (or from
|
||||||
|
CLI flags) for non-GitHub/GitLab repositories, so packaging previously
|
||||||
|
failed with "Couldn't detect the repository". Verified the packaged
|
||||||
|
README now links the icon, LICENSE, and NOTICE with working Gitea URLs.
|
||||||
|
|
||||||
|
## [0.4.0] - 2026-11-08
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Set `baseContentUrl` in package.json to the Gitea raw URL, so LICENSE and
|
||||||
|
NOTICE links in the README resolve correctly on the Marketplace.
|
||||||
|
- Added an npm `publish` script running `vsce publish`, with `@vscode/vsce`
|
||||||
|
as a dev dependency, for releasing to the VS Code Marketplace.
|
||||||
|
- Added `language-models` and `chat` Marketplace tags, so the extension
|
||||||
|
appears in the "Install Language Models" discovery flow. The tags take
|
||||||
|
effect when the next version is published.
|
||||||
|
- Added an extension icon rendered from the Inference Coop logo, shown on
|
||||||
|
the Marketplace listing and in the Extensions view.
|
||||||
|
- Added Marketplace keywords for search discoverability.
|
||||||
|
- Changed the Marketplace category from "Other" to "AI".
|
||||||
|
- Changed the Marketplace display name from the package ID to the readable
|
||||||
|
title, "Inference Coop for Copilot Chat".
|
||||||
|
- Reworked the README: an "About the Inference Cooperative" section for
|
||||||
|
prospective members, step-by-step Setup instructions starting with
|
||||||
|
creating an API key at the dashboard (noting keys are shown only once),
|
||||||
|
and consistent use of "Inference Cooperative" as the organization name.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Removed the unused `inferenceCoop.baseUrl` setting. The extension only
|
||||||
|
ever talked to the hardcoded `https://gateway.inference.coop/v1` gateway;
|
||||||
|
keeping a configurable URL would let a modified setting redirect the
|
||||||
|
stored API key to a hostile endpoint.
|
||||||
|
- Removed the membership/API-key line from Requirements, since Setup now
|
||||||
|
walks through acquiring both.
|
||||||
|
|
||||||
|
## [0.3.0] - 2026-11-08
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Removed the "(unofficial)" disclaimer from the package description and
|
||||||
|
NOTICE, and the README; the project is now official, maintained in the
|
||||||
|
co-op's Git at `code/inference-coop-copilot`.
|
||||||
|
- Updated the repository URL to `https://git.inference.coop/code/inference-coop-copilot.git`
|
||||||
|
in package.json and CHANGELOG links.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Abort in-flight chat requests on cancellation: an `AbortController` wired
|
||||||
|
to `token.onCancellationRequested` closes the SSE connection as soon as
|
||||||
|
the user stops the request, instead of the server continuing to generate
|
||||||
|
until the response ends.
|
||||||
|
|
||||||
|
## [0.2.2] - 2026-11-06
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Correct the publisher in package.json.
|
||||||
|
|
||||||
|
## [0.2.1] - 2026-11-06
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Correct instructions for setting the API key in README.
|
||||||
|
|
||||||
## [0.2.0] - 2026-11-06
|
## [0.2.0] - 2026-11-06
|
||||||
|
|
||||||
@@ -58,6 +126,11 @@ First release usable for chat.
|
|||||||
|
|
||||||
Initial development release. Not functional for chat.
|
Initial development release. Not functional for chat.
|
||||||
|
|
||||||
[Unreleased]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.2.0...HEAD
|
[Unreleased]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.4.1...HEAD
|
||||||
[0.2.0]: https://git.inference.coop/evanp/inference-coop-copilot/compare/v0.1.0...v0.2.0
|
[0.4.1]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.4.0...v0.4.1
|
||||||
[0.1.0]: https://git.inference.coop/evanp/inference-coop-copilot/releases/tag/v0.1.0
|
[0.4.0]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.3.0...v0.4.0
|
||||||
|
[0.3.0]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.2...v0.3.0
|
||||||
|
[0.2.2]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.1...v0.2.2
|
||||||
|
[0.2.1]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.2.0...v0.2.1
|
||||||
|
[0.2.0]: https://git.inference.coop/code/inference-coop-copilot/compare/v0.1.0...v0.2.0
|
||||||
|
[0.1.0]: https://git.inference.coop/code/inference-coop-copilot/releases/tag/v0.1.0
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
Inference Coop Copilot (unofficial)
|
Inference Coop Copilot
|
||||||
Copyright 2026 Evan Prodromou
|
Copyright 2026 Evan Prodromou
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0.
|
Licensed under the Apache License, Version 2.0.
|
||||||
@@ -1,14 +1,59 @@
|
|||||||
# Inference Coop (unofficial)
|
# Inference Coop for Copilot Chat
|
||||||
|
|
||||||
Community-built model provider for [inference.coop](https://inference.coop),
|

|
||||||
usable in GitHub Copilot Chat. Not affiliated with or endorsed by the
|
|
||||||
Inference Cooperative.
|
Official model provider for [inference.coop](https://inference.coop), usable
|
||||||
|
in GitHub Copilot Chat. An official project of the Inference Cooperative,
|
||||||
|
maintained in the Inference Cooperative's Git at
|
||||||
|
[code/inference-coop-copilot](https://git.inference.coop/code/inference-coop-copilot).
|
||||||
|
|
||||||
|
## About the Inference Cooperative
|
||||||
|
|
||||||
|
The Inference Cooperative is a member-owned cooperative that pools its
|
||||||
|
members' purchasing power to support privacy-preserving, renewable-energy,
|
||||||
|
and open-weights AI services. Members choose among powerful, open-weights
|
||||||
|
models — hosted in encrypted enclaves, on 100% renewable power, or built as
|
||||||
|
public goods — instead of accepting whatever Big Tech offers.
|
||||||
|
|
||||||
|
Membership is a sliding scale starting at $5 a month. Every member gets the
|
||||||
|
same $15 monthly credit for chat and API use, plus a vote in how the
|
||||||
|
Inference Cooperative is run. Credits never expire, and you can cancel any time.
|
||||||
|
|
||||||
|
To join, visit [inference.coop](https://inference.coop) and sign up. Your
|
||||||
|
membership includes access to the chat and the developer API — this
|
||||||
|
extension brings those same models into GitHub Copilot Chat.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- VS Code 1.145 or newer
|
||||||
|
- GitHub Copilot Chat, installed and signed in
|
||||||
|
|
||||||
|
Copilot Business/Enterprise: your administrator must leave "Bring Your Own
|
||||||
|
Language Model Key" enabled, or these models will not appear.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Set `inferenceCoop.apiKey` in your settings to your co-op API key.
|
1. Create an API key at
|
||||||
2. Open Copilot Chat and pick an `inference-coop/…` model.
|
[dashboard.inference.coop/#keys-card](https://dashboard.inference.coop/#keys-card).
|
||||||
|
**The key is only shown once, right after it is created** — copy it
|
||||||
|
somewhere safe before you close the page.
|
||||||
|
2. Run **Inference Coop: Set API Key** from the Command Palette and paste
|
||||||
|
the key. It is stored in VS Code's secret storage, not in settings.
|
||||||
|
3. Open Copilot Chat, click the model name, and pick an `inference-coop/…`
|
||||||
|
model. Tool calling works, so agent mode is usable.
|
||||||
|
|
||||||
## Status
|
To sign out, run **Inference Coop: Sign Out**. (You can create a new key
|
||||||
|
any time and run Set API Key again — keys are not deleted when you sign
|
||||||
|
out, so revoke unused keys from the dashboard.)
|
||||||
|
|
||||||
Early development. Text chat only so far; tool calling is not implemented.
|
## Limitations
|
||||||
|
|
||||||
|
- No image input; models are advertised as text-and-tools only.
|
||||||
|
- Token counts are estimated rather than computed with a real tokenizer, so
|
||||||
|
context budgeting is approximate.
|
||||||
|
- No inline code completions. Copilot does not support third-party providers
|
||||||
|
for completions; this extension only adds chat models.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,25 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 130 130">
|
||||||
|
<rect width="130" height="130" rx="24" fill="#faf8f5"/>
|
||||||
|
<circle cx="65" cy="14" r="5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="58" cy="30" r="6" fill="#7ab87a"/>
|
||||||
|
<circle cx="74" cy="30" r="4" fill="#6ba86b"/>
|
||||||
|
<circle cx="51.5" cy="46" r="6.5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="65" cy="46" r="5" fill="#7ab87a"/>
|
||||||
|
<circle cx="81" cy="46" r="4" fill="#6ba86b"/>
|
||||||
|
<circle cx="44" cy="62" r="7" fill="#6ba86b"/>
|
||||||
|
<circle cx="61" cy="62" r="5.5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="76" cy="62" r="4.5" fill="#7ab87a"/>
|
||||||
|
<circle cx="89.5" cy="62" r="3.5" fill="#6ba86b"/>
|
||||||
|
<circle cx="36.5" cy="78" r="7.5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="54" cy="78" r="6" fill="#7ab87a"/>
|
||||||
|
<circle cx="70" cy="78" r="5" fill="#6ba86b"/>
|
||||||
|
<circle cx="84" cy="78" r="4" fill="#5b8c5a"/>
|
||||||
|
<circle cx="97.5" cy="78" r="3.5" fill="#7ab87a"/>
|
||||||
|
<circle cx="44" cy="94" r="6.5" fill="#6ba86b"/>
|
||||||
|
<circle cx="61" cy="94" r="5.5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="76" cy="94" r="4.5" fill="#7ab87a"/>
|
||||||
|
<circle cx="89.5" cy="94" r="3.5" fill="#6ba86b"/>
|
||||||
|
<circle cx="51.5" cy="110" r="5.5" fill="#5b8c5a"/>
|
||||||
|
<circle cx="65" cy="110" r="4.5" fill="#7ab87a"/>
|
||||||
|
<circle cx="81" cy="110" r="3.5" fill="#6ba86b"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.2 KiB |
Generated
+1461
-2
File diff suppressed because it is too large.
Load diff
+35
-26
@@ -1,19 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "inference-coop-copilot",
|
"name": "inference-coop-copilot",
|
||||||
"displayName": "inference-coop-copilot",
|
"displayName": "Inference Coop for Copilot Chat",
|
||||||
"description": "Inference.coop models for Copilot Chat (unofficial)",
|
"description": "Inference.coop models for Copilot Chat",
|
||||||
"version": "0.2.0",
|
"version": "0.4.1",
|
||||||
|
"icon": "images/icon.png",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.145.0"
|
"vscode": "^1.145.0"
|
||||||
},
|
},
|
||||||
"publisher": "inference-coop",
|
"publisher": "evanp",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.inference.coop/evanp/inference-coop-copilot.git"
|
"url": "https://git.inference.coop/code/inference-coop-copilot.git"
|
||||||
|
},
|
||||||
|
"vsce": {
|
||||||
|
"baseContentUrl": "https://git.inference.coop/code/inference-coop-copilot/raw/branch/main",
|
||||||
|
"baseImagesUrl": "https://git.inference.coop/code/inference-coop-copilot/raw/branch/main"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"categories": [
|
"categories": [
|
||||||
"Other"
|
"AI"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"language-models",
|
||||||
|
"chat"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"inference-coop",
|
||||||
|
"inference.coop",
|
||||||
|
"copilot",
|
||||||
|
"chat",
|
||||||
|
"language model",
|
||||||
|
"AI"
|
||||||
],
|
],
|
||||||
"activationEvents": [],
|
"activationEvents": [],
|
||||||
"main": "./dist/extension.js",
|
"main": "./dist/extension.js",
|
||||||
@@ -25,10 +42,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
|
||||||
"command": "inference-coop-copilot.helloWorld",
|
|
||||||
"title": "Hello World"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"command": "inferenceCoop.setKey",
|
"command": "inferenceCoop.setKey",
|
||||||
"title": "Inference Coop: Set API Key"
|
"title": "Inference Coop: Set API Key"
|
||||||
@@ -37,17 +50,7 @@
|
|||||||
"command": "inferenceCoop.clearKey",
|
"command": "inferenceCoop.clearKey",
|
||||||
"title": "Inference Coop: Sign Out"
|
"title": "Inference Coop: Sign Out"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"configuration": {
|
|
||||||
"title": "Inference Coop",
|
|
||||||
"properties": {
|
|
||||||
"inferenceCoop.baseUrl": {
|
|
||||||
"type": "string",
|
|
||||||
"default": "https://gateway.inference.coop/v1",
|
|
||||||
"description": "Gateway base URL. Leave default unless testing."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "npm run package",
|
"vscode:prepublish": "npm run package",
|
||||||
@@ -61,22 +64,28 @@
|
|||||||
"pretest": "npm run compile-tests && npm run compile && npm run lint",
|
"pretest": "npm run compile-tests && npm run compile && npm run lint",
|
||||||
"check-types": "tsc --noEmit",
|
"check-types": "tsc --noEmit",
|
||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
|
"publish": "vsce publish",
|
||||||
"test": "vscode-test"
|
"test": "vscode-test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/vscode": "^1.145.0",
|
|
||||||
"@types/mocha": "^10.0.10",
|
"@types/mocha": "^10.0.10",
|
||||||
"@types/node": "24.x",
|
"@types/node": "24.x",
|
||||||
"typescript-eslint": "^8.61.1",
|
"@types/vscode": "^1.145.0",
|
||||||
"eslint": "^10.5.0",
|
"@vscode/test-cli": "^0.0.15",
|
||||||
|
"@vscode/test-electron": "^3.0.0",
|
||||||
|
"@vscode/vsce": "^4.1.0",
|
||||||
"esbuild": "^0.28.1",
|
"esbuild": "^0.28.1",
|
||||||
|
"eslint": "^10.5.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"typescript": "^6.0.3",
|
"typescript": "^6.0.3",
|
||||||
"@vscode/test-cli": "^0.0.15",
|
"typescript-eslint": "^8.61.1"
|
||||||
"@vscode/test-electron": "^3.0.0"
|
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"diff": "^8.0.4",
|
"diff": "^8.0.4",
|
||||||
"serialize-javascript": "^7.0.6"
|
"serialize-javascript": "^7.0.6"
|
||||||
|
},
|
||||||
|
"allowScripts": {
|
||||||
|
"@vscode/vsce-sign@2.1.0": true,
|
||||||
|
"esbuild@0.28.2": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+127
-94
@@ -109,118 +109,151 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
body.tool_choice = "auto";
|
body.tool_choice = "auto";
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`${BASE_URL}/chat/completions`, {
|
if (token.isCancellationRequested) {
|
||||||
method: "POST",
|
out.appendLine(" request cancelled before it started");
|
||||||
headers: {
|
return;
|
||||||
Authorization: `Bearer ${key}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
signal: token.isCancellationRequested ? AbortSignal.abort() : undefined,
|
|
||||||
});
|
|
||||||
out.appendLine(` /chat/completions status: ${res.status}`);
|
|
||||||
if (!res.ok || !res.body) {
|
|
||||||
throw new Error(
|
|
||||||
`Inference Coop: HTTP ${res.status} — ${await res.text()}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const reader = res.body.getReader();
|
// Abort the request as soon as the user cancels, so a cancelled chat
|
||||||
const decoder = new TextDecoder();
|
// stops generating (and stops billing) server-side.
|
||||||
let buf = "";
|
const abort = new AbortController();
|
||||||
let textChunks = 0;
|
const cancelSubscription = token.onCancellationRequested(() =>
|
||||||
const pending = new Map<
|
abort.abort(),
|
||||||
number,
|
);
|
||||||
{ id?: string; name: string; args: string }
|
|
||||||
>();
|
|
||||||
|
|
||||||
const flushTools = () => {
|
try {
|
||||||
for (const call of pending.values()) {
|
const res = await fetch(`${BASE_URL}/chat/completions`, {
|
||||||
let input: object = {};
|
method: "POST",
|
||||||
try {
|
headers: {
|
||||||
input = JSON.parse(call.args || "{}");
|
Authorization: `Bearer ${key}`,
|
||||||
} catch {
|
"Content-Type": "application/json",
|
||||||
out.appendLine(
|
},
|
||||||
` WARN bad tool args for ${call.name}: ${call.args}`,
|
body: JSON.stringify(body),
|
||||||
);
|
signal: abort.signal,
|
||||||
}
|
});
|
||||||
out.appendLine(` tool call: ${call.name} ${JSON.stringify(input)}`);
|
out.appendLine(` /chat/completions status: ${res.status}`);
|
||||||
progress.report(
|
if (!res.ok || !res.body) {
|
||||||
new vscode.LanguageModelToolCallPart(
|
throw new Error(
|
||||||
call.id ?? `call_${Math.random().toString(36).slice(2)}`,
|
`Inference Coop: HTTP ${res.status} — ${await res.text()}`,
|
||||||
call.name,
|
|
||||||
input,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
pending.clear();
|
|
||||||
};
|
|
||||||
|
|
||||||
while (true) {
|
const reader = res.body.getReader();
|
||||||
const { done, value } = await reader.read();
|
const decoder = new TextDecoder();
|
||||||
if (done) {
|
let buf = "";
|
||||||
break;
|
let textChunks = 0;
|
||||||
}
|
const pending = new Map<
|
||||||
buf += decoder.decode(value, { stream: true });
|
number,
|
||||||
const frames = buf.split("\n\n");
|
{ id?: string; name: string; args: string }
|
||||||
buf = frames.pop() ?? "";
|
>();
|
||||||
|
|
||||||
for (const frame of frames) {
|
const flushTools = () => {
|
||||||
for (const line of frame.split("\n")) {
|
for (const call of pending.values()) {
|
||||||
if (!line.startsWith("data:")) {
|
let input: object = {};
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const data = line.slice(5).trim();
|
|
||||||
if (data === "[DONE]") {
|
|
||||||
if (pending.size) {
|
|
||||||
flushTools();
|
|
||||||
}
|
|
||||||
out.appendLine(` done, ${textChunks} text chunks`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let json: any;
|
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(data);
|
input = JSON.parse(call.args || "{}");
|
||||||
} catch {
|
} catch {
|
||||||
continue;
|
out.appendLine(
|
||||||
}
|
` WARN bad tool args for ${call.name}: ${call.args}`,
|
||||||
const choice = json.choices?.[0];
|
);
|
||||||
const delta = choice?.delta;
|
|
||||||
if (!delta) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
out.appendLine(` tool call: ${call.name} ${JSON.stringify(input)}`);
|
||||||
|
progress.report(
|
||||||
|
new vscode.LanguageModelToolCallPart(
|
||||||
|
call.id ?? `call_${Math.random().toString(36).slice(2)}`,
|
||||||
|
call.name,
|
||||||
|
input,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pending.clear();
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof delta.content === "string" && delta.content) {
|
while (true) {
|
||||||
textChunks++;
|
if (token.isCancellationRequested) {
|
||||||
progress.report(new vscode.LanguageModelTextPart(delta.content));
|
out.appendLine(" cancelled mid-stream; aborting request");
|
||||||
}
|
abort.abort(); // close the connection so the gateway stops generating
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf += decoder.decode(value, { stream: true });
|
||||||
|
const frames = buf.split("\n\n");
|
||||||
|
buf = frames.pop() ?? "";
|
||||||
|
|
||||||
for (const tc of delta.tool_calls ?? []) {
|
for (const frame of frames) {
|
||||||
const i = tc.index ?? 0;
|
for (const line of frame.split("\n")) {
|
||||||
const acc = pending.get(i) ?? {
|
if (!line.startsWith("data:")) {
|
||||||
id: undefined,
|
continue;
|
||||||
name: "",
|
}
|
||||||
args: "",
|
const data = line.slice(5).trim();
|
||||||
};
|
if (data === "[DONE]") {
|
||||||
acc.id = tc.id ?? acc.id;
|
if (pending.size) {
|
||||||
acc.name = tc.function?.name ?? acc.name;
|
flushTools();
|
||||||
acc.args += tc.function?.arguments ?? "";
|
}
|
||||||
pending.set(i, acc);
|
out.appendLine(` done, ${textChunks} text chunks`);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
let json: any;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(data);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const choice = json.choices?.[0];
|
||||||
|
const delta = choice?.delta;
|
||||||
|
if (!delta) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (choice?.finish_reason) {
|
if (typeof delta.content === "string" && delta.content) {
|
||||||
out.appendLine(` finish_reason: ${choice.finish_reason}`);
|
textChunks++;
|
||||||
if (pending.size) {
|
progress.report(new vscode.LanguageModelTextPart(delta.content));
|
||||||
flushTools();
|
}
|
||||||
|
|
||||||
|
for (const tc of delta.tool_calls ?? []) {
|
||||||
|
const i = tc.index ?? 0;
|
||||||
|
const acc = pending.get(i) ?? {
|
||||||
|
id: undefined,
|
||||||
|
name: "",
|
||||||
|
args: "",
|
||||||
|
};
|
||||||
|
acc.id = tc.id ?? acc.id;
|
||||||
|
acc.name = tc.function?.name ?? acc.name;
|
||||||
|
acc.args += tc.function?.arguments ?? "";
|
||||||
|
pending.set(i, acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (choice?.finish_reason) {
|
||||||
|
out.appendLine(` finish_reason: ${choice.finish_reason}`);
|
||||||
|
if (pending.size) {
|
||||||
|
flushTools();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pending.size) {
|
||||||
|
flushTools();
|
||||||
|
}
|
||||||
|
out.appendLine(` stream ended, ${textChunks} text chunks`);
|
||||||
|
} catch (e) {
|
||||||
|
// A cancellation aborts fetch (before headers) or the pending stream
|
||||||
|
// read (mid-response) - both surface as AbortError. That is the user
|
||||||
|
// pressing stop, not a failure: stop quietly instead of erroring.
|
||||||
|
if (
|
||||||
|
token.isCancellationRequested ||
|
||||||
|
(e instanceof Error && e.name === "AbortError")
|
||||||
|
) {
|
||||||
|
out.appendLine(" stream aborted after cancellation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
cancelSubscription.dispose();
|
||||||
}
|
}
|
||||||
if (pending.size) {
|
|
||||||
flushTools();
|
|
||||||
}
|
|
||||||
out.appendLine(` stream ended, ${textChunks} text chunks`);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async provideTokenCount() {
|
async provideTokenCount() {
|
||||||
|
|||||||
Reference in new issue
Block a user