writes the JSON to files in /tmp/
This commit is contained in:
parent
148201b5c5
commit
d021fcadad
|
@ -4,6 +4,8 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {
|
||||
Content,
|
||||
CountTokensParameters,
|
||||
|
@ -37,6 +39,8 @@ interface StructuredError {
|
|||
* A decorator that wraps a ContentGenerator to add logging to API calls.
|
||||
*/
|
||||
export class LoggingContentGenerator implements ContentGenerator {
|
||||
private requestCounter = 1;
|
||||
|
||||
constructor(
|
||||
private readonly wrapped: ContentGenerator,
|
||||
private readonly config: Config,
|
||||
|
@ -108,6 +112,12 @@ export class LoggingContentGenerator implements ContentGenerator {
|
|||
const startTime = Date.now();
|
||||
this.logApiRequest(toContents(req.contents), req.model, userPromptId);
|
||||
try {
|
||||
const sessionId = this.config.getSessionId();
|
||||
const fileName = `${sessionId}.gemini-api-request.${this.requestCounter}.json`;
|
||||
const filePath = path.join('/tmp', fileName);
|
||||
const jsonPayload = JSON.stringify(req, null, 2);
|
||||
fs.writeFileSync(filePath, jsonPayload);
|
||||
this.requestCounter++;
|
||||
const response = await this.wrapped.generateContent(req, userPromptId);
|
||||
const durationMs = Date.now() - startTime;
|
||||
this._logApiResponse(
|
||||
|
@ -131,6 +141,12 @@ export class LoggingContentGenerator implements ContentGenerator {
|
|||
const startTime = Date.now();
|
||||
this.logApiRequest(toContents(req.contents), req.model, userPromptId);
|
||||
|
||||
const sessionId = this.config.getSessionId();
|
||||
const fileName = `${sessionId}.gemini-api-request.${this.requestCounter}.json`;
|
||||
const filePath = path.join('/tmp', fileName);
|
||||
const jsonPayload = JSON.stringify(req, null, 2);
|
||||
fs.writeFileSync(filePath, jsonPayload);
|
||||
this.requestCounter++;
|
||||
let stream: AsyncGenerator<GenerateContentResponse>;
|
||||
try {
|
||||
stream = await this.wrapped.generateContentStream(req, userPromptId);
|
||||
|
|
Loading…
Reference in New Issue