Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions js/plugins/google-cloud/src/telemetry/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ class GenerateTelemetry implements Telemetry {

output.candidates.forEach((cand, candIdx) => {
const parts = cand.message.content.length;
const candCounts = parts > 1 ? ` (${candIdx + 1} of ${parts})` : '';
logger.logStructured(`Output Candidate[${path}, ${model}]${candCounts}`, {
...sharedMetadata,
candidateIndex: candIdx,
totalCandidates: candidates,
messageIndex: cand.index,
finishReason: cand.finishReason,
finishMessage: cand.finishMessage,
role: cand.message.role,
usage: cand.usage,
custom: cand.custom,
});
cand.message.content.forEach((part, partIdx) => {
const partCounts = this.toPartCounts(
partIdx,
Expand All @@ -321,6 +333,12 @@ class GenerateTelemetry implements Telemetry {
finishReason: cand.finishReason,
});
});
if (output.usage) {
logger.logStructured(`Usage[${path}, ${model}]`, {
...sharedMetadata,
usage: output.usage,
});
}
});
}

Expand Down
24 changes: 24 additions & 0 deletions js/plugins/google-cloud/tests/logs_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ describe('GoogleCloudLogs no I/O', () => {
logMessages.includes('[info] Output[testFlow, testModel]'),
false
);
assert.equal(
logMessages.includes(
'[info] Output Candidate[testFlow > sub1 > sub2 > testModel, testModel]'
),
false
);
assert.equal(
logMessages.includes(
'[info] Usage[testFlow > sub1 > sub2 > testModel, testModel]'
),
false
);
});
});

Expand Down Expand Up @@ -336,6 +348,18 @@ describe('GoogleCloudLogs', () => {
logMessages.includes('[info] Output[testFlow, testFlow]'),
true
);
assert.equal(
logMessages.includes(
'[info] Output Candidate[testFlow > sub1 > sub2 > testModel, testModel]'
),
true
);
assert.equal(
logMessages.includes(
'[info] Usage[testFlow > sub1 > sub2 > testModel, testModel]'
),
true
);
});
});

Expand Down
Loading