mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Add support for logging the entire request and response object (#4725)
This commit is contained in:
@@ -26,10 +26,6 @@ import {
|
||||
logApiResponse,
|
||||
logApiError,
|
||||
} from '../telemetry/loggers.js';
|
||||
import {
|
||||
getStructuredResponse,
|
||||
getStructuredResponseFromParts,
|
||||
} from '../utils/generateContentResponseUtilities.js';
|
||||
import {
|
||||
ApiErrorEvent,
|
||||
ApiRequestEvent,
|
||||
@@ -142,11 +138,7 @@ export class GeminiChat {
|
||||
}
|
||||
|
||||
private _getRequestTextFromContents(contents: Content[]): string {
|
||||
return contents
|
||||
.flatMap((content) => content.parts ?? [])
|
||||
.map((part) => part.text)
|
||||
.filter(Boolean)
|
||||
.join('');
|
||||
return JSON.stringify(contents);
|
||||
}
|
||||
|
||||
private async _logApiRequest(
|
||||
@@ -318,7 +310,7 @@ export class GeminiChat {
|
||||
durationMs,
|
||||
prompt_id,
|
||||
response.usageMetadata,
|
||||
getStructuredResponse(response),
|
||||
JSON.stringify(response),
|
||||
);
|
||||
|
||||
this.sendPromise = (async () => {
|
||||
@@ -554,12 +546,11 @@ export class GeminiChat {
|
||||
allParts.push(...content.parts);
|
||||
}
|
||||
}
|
||||
const fullText = getStructuredResponseFromParts(allParts);
|
||||
await this._logApiResponse(
|
||||
durationMs,
|
||||
prompt_id,
|
||||
this.getFinalUsageMetadata(chunks),
|
||||
fullText,
|
||||
JSON.stringify(chunks),
|
||||
);
|
||||
}
|
||||
this.recordHistory(inputContent, outputContent);
|
||||
|
||||
Reference in New Issue
Block a user