copilot-api-plus 1.0.45 → 1.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +21 -11
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2954,10 +2954,14 @@ const createChatCompletions = async (payload) => {
|
|
|
2954
2954
|
endpoint: `${copilotBaseUrl(state)}/chat/completions`
|
|
2955
2955
|
});
|
|
2956
2956
|
const url = `${copilotBaseUrl(state)}/chat/completions`;
|
|
2957
|
+
const body = payload.stream ? {
|
|
2958
|
+
...payload,
|
|
2959
|
+
stream_options: { include_usage: true }
|
|
2960
|
+
} : payload;
|
|
2957
2961
|
const fetchOptions = {
|
|
2958
2962
|
method: "POST",
|
|
2959
2963
|
headers,
|
|
2960
|
-
body: JSON.stringify(
|
|
2964
|
+
body: JSON.stringify(body)
|
|
2961
2965
|
};
|
|
2962
2966
|
const maxRetries = 2;
|
|
2963
2967
|
let lastError;
|
|
@@ -3043,11 +3047,14 @@ async function handleCompletion$1(c) {
|
|
|
3043
3047
|
const sseChunk = chunk;
|
|
3044
3048
|
if (sseChunk.data && sseChunk.data !== "[DONE]") {
|
|
3045
3049
|
const parsed = JSON.parse(sseChunk.data);
|
|
3046
|
-
if (parsed.usage)
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3050
|
+
if (parsed.usage) {
|
|
3051
|
+
setTokenUsage({
|
|
3052
|
+
inputTokens: parsed.usage.prompt_tokens ?? 0,
|
|
3053
|
+
outputTokens: parsed.usage.completion_tokens ?? 0,
|
|
3054
|
+
cacheReadTokens: parsed.usage.prompt_tokens_details?.cached_tokens
|
|
3055
|
+
});
|
|
3056
|
+
consola.info(`Token usage: in:${parsed.usage.prompt_tokens ?? 0} out:${parsed.usage.completion_tokens ?? 0}` + (parsed.usage.prompt_tokens_details?.cached_tokens ? ` cache_read:${parsed.usage.prompt_tokens_details.cached_tokens}` : ""));
|
|
3057
|
+
}
|
|
3051
3058
|
}
|
|
3052
3059
|
} catch {}
|
|
3053
3060
|
await stream.writeSSE(chunk);
|
|
@@ -3516,11 +3523,14 @@ async function handleCompletion(c) {
|
|
|
3516
3523
|
if (!rawEvent.data) continue;
|
|
3517
3524
|
const chunk = JSON.parse(rawEvent.data);
|
|
3518
3525
|
const events$1 = translateChunkToAnthropicEvents(chunk, streamState);
|
|
3519
|
-
if (chunk.usage)
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3526
|
+
if (chunk.usage) {
|
|
3527
|
+
setTokenUsage({
|
|
3528
|
+
inputTokens: chunk.usage.prompt_tokens - (chunk.usage.prompt_tokens_details?.cached_tokens ?? 0),
|
|
3529
|
+
outputTokens: chunk.usage.completion_tokens,
|
|
3530
|
+
cacheReadTokens: chunk.usage.prompt_tokens_details?.cached_tokens
|
|
3531
|
+
});
|
|
3532
|
+
consola.info(`Token usage: in:${chunk.usage.prompt_tokens - (chunk.usage.prompt_tokens_details?.cached_tokens ?? 0)} out:${chunk.usage.completion_tokens}` + (chunk.usage.prompt_tokens_details?.cached_tokens ? ` cache_read:${chunk.usage.prompt_tokens_details.cached_tokens}` : ""));
|
|
3533
|
+
}
|
|
3524
3534
|
for (const event of events$1) await stream.writeSSE({
|
|
3525
3535
|
event: event.type,
|
|
3526
3536
|
data: JSON.stringify(event)
|