@jambonz/llm 0.6.5 → 0.6.6
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/index.cjs +11 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/test-kit/index.cjs +11 -3
- package/dist/test-kit/index.cjs.map +1 -1
- package/dist/test-kit/index.js +11 -3
- package/dist/test-kit/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -142,12 +142,20 @@ async function* streamFromOpenAI(client, req, options) {
|
|
|
142
142
|
throw new Error(`OpenAI-compatible stream returned an error: ${message}`);
|
|
143
143
|
}
|
|
144
144
|
if (chunk.usage) {
|
|
145
|
-
const
|
|
145
|
+
const details = chunk.usage.prompt_tokens_details;
|
|
146
|
+
const cachedTokens = details?.cached_tokens;
|
|
147
|
+
const cacheWriteTokens = details?.cache_write_tokens;
|
|
146
148
|
usage = {
|
|
147
|
-
...chunk.usage.prompt_tokens !== void 0 ? {
|
|
149
|
+
...chunk.usage.prompt_tokens !== void 0 ? {
|
|
150
|
+
inputTokens: Math.max(
|
|
151
|
+
0,
|
|
152
|
+
chunk.usage.prompt_tokens - (cachedTokens ?? 0) - (cacheWriteTokens ?? 0)
|
|
153
|
+
)
|
|
154
|
+
} : {},
|
|
148
155
|
...chunk.usage.completion_tokens !== void 0 ? { outputTokens: chunk.usage.completion_tokens } : {},
|
|
149
156
|
...chunk.usage.total_tokens !== void 0 ? { totalTokens: chunk.usage.total_tokens } : {},
|
|
150
|
-
...cachedTokens !== void 0 ? { cacheReadTokens: cachedTokens } : {}
|
|
157
|
+
...cachedTokens !== void 0 ? { cacheReadTokens: cachedTokens } : {},
|
|
158
|
+
...cacheWriteTokens !== void 0 ? { cacheWriteTokens } : {}
|
|
151
159
|
};
|
|
152
160
|
}
|
|
153
161
|
const choice = chunk.choices?.[0];
|