@neutrome/open-ai-router 0.1.9 → 0.1.10
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/package.json +1 -1
- package/src/router/execute.ts +6 -7
package/package.json
CHANGED
package/src/router/execute.ts
CHANGED
|
@@ -383,7 +383,7 @@ export function createFetchProviderInvoker(
|
|
|
383
383
|
for (const event of split.events) {
|
|
384
384
|
for (const data of eventDataLines(event)) {
|
|
385
385
|
if (data === "[DONE]") {
|
|
386
|
-
|
|
386
|
+
reportProviderUsage(onProviderCall, lastChunkWithUsage, providerCtx.target);
|
|
387
387
|
return;
|
|
388
388
|
}
|
|
389
389
|
if (data[0] !== "{") continue;
|
|
@@ -400,7 +400,7 @@ export function createFetchProviderInvoker(
|
|
|
400
400
|
if (buffer.length > 0) {
|
|
401
401
|
for (const data of eventDataLines(buffer)) {
|
|
402
402
|
if (data === "[DONE]") {
|
|
403
|
-
|
|
403
|
+
reportProviderUsage(onProviderCall, lastChunkWithUsage, providerCtx.target);
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
if (data[0] !== "{") continue;
|
|
@@ -412,7 +412,7 @@ export function createFetchProviderInvoker(
|
|
|
412
412
|
yield chunk;
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
|
|
415
|
+
reportProviderUsage(onProviderCall, lastChunkWithUsage, providerCtx.target);
|
|
416
416
|
} catch (error) {
|
|
417
417
|
throw normalizeUpstreamAbort(error, timed.signal);
|
|
418
418
|
} finally {
|
|
@@ -764,13 +764,12 @@ function reportUsage(
|
|
|
764
764
|
|
|
765
765
|
function reportProviderUsage(
|
|
766
766
|
onProviderCall: ((report: ProviderCallReport) => void) | undefined,
|
|
767
|
-
response: Program,
|
|
767
|
+
response: Program | null,
|
|
768
768
|
target: Extract<import("@neutrome/lil-engine").ExecutionTarget, { kind: "provider" }>,
|
|
769
769
|
): void {
|
|
770
770
|
if (!onProviderCall) return;
|
|
771
|
-
const usage = usageObject(response);
|
|
772
|
-
|
|
773
|
-
const u = usage as Record<string, unknown>;
|
|
771
|
+
const usage = response ? usageObject(response) : undefined;
|
|
772
|
+
const u = (usage && typeof usage === "object" ? usage : {}) as Record<string, unknown>;
|
|
774
773
|
const tokensInput = asNum(u.prompt_tokens) || asNum(u.input_tokens);
|
|
775
774
|
const tokensOutput = asNum(u.completion_tokens) || asNum(u.output_tokens);
|
|
776
775
|
const details = u.prompt_tokens_details as Record<string, unknown> | undefined;
|