Log all parts of a streaming response (#6855)
This commit is contained in:
parent
5030ced9e1
commit
4c1c6d2b0d
1 changed files with 4 additions and 1 deletions
|
|
@ -149,9 +149,12 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||||
userPromptId: string,
|
userPromptId: string,
|
||||||
): AsyncGenerator<GenerateContentResponse> {
|
): AsyncGenerator<GenerateContentResponse> {
|
||||||
let lastResponse: GenerateContentResponse | undefined;
|
let lastResponse: GenerateContentResponse | undefined;
|
||||||
|
const responses: GenerateContentResponse[] = [];
|
||||||
|
|
||||||
let lastUsageMetadata: GenerateContentResponseUsageMetadata | undefined;
|
let lastUsageMetadata: GenerateContentResponseUsageMetadata | undefined;
|
||||||
try {
|
try {
|
||||||
for await (const response of stream) {
|
for await (const response of stream) {
|
||||||
|
responses.push(response);
|
||||||
lastResponse = response;
|
lastResponse = response;
|
||||||
if (response.usageMetadata) {
|
if (response.usageMetadata) {
|
||||||
lastUsageMetadata = response.usageMetadata;
|
lastUsageMetadata = response.usageMetadata;
|
||||||
|
|
@ -169,7 +172,7 @@ export class LoggingContentGenerator implements ContentGenerator {
|
||||||
durationMs,
|
durationMs,
|
||||||
userPromptId,
|
userPromptId,
|
||||||
lastUsageMetadata,
|
lastUsageMetadata,
|
||||||
JSON.stringify(lastResponse),
|
JSON.stringify(responses),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue