From 84c96e7c4cca42f65decd1466f1055d8909c6e21 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Tue, 6 Feb 2024 10:07:29 +0100 Subject: [PATCH] add duration for askPlayground and stopPlayground --- packages/backend/src/managers/playground.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/managers/playground.ts b/packages/backend/src/managers/playground.ts index 46bd26c91..57a87518a 100644 --- a/packages/backend/src/managers/playground.ts +++ b/packages/backend/src/managers/playground.ts @@ -263,6 +263,7 @@ export class PlayGroundManager { } async stopPlayground(modelId: string): Promise { + const startTime = performance.now(); const state = this.playgrounds.get(modelId); if (state?.container === undefined) { throw new Error('model is not running'); @@ -283,10 +284,12 @@ export class PlayGroundManager { error: error, }); }); - this.telemetry.logUsage('playground.stop', { 'model.id': modelId }); + const durationSeconds = getDurationSecondsSince(startTime); + this.telemetry.logUsage('playground.stop', { 'model.id': modelId, durationSeconds }); } async askPlayground(modelInfo: LocalModelInfo, prompt: string): Promise { + const startTime = performance.now(); const state = this.playgrounds.get(modelInfo.id); if (state?.container === undefined) { this.telemetry.logError('playground.ask', { 'model.id': modelInfo.id, message: 'model is not running' }); @@ -323,7 +326,8 @@ export class PlayGroundManager { this.sendQueriesState(); } })().catch((err: unknown) => console.warn(`Error while reading streamed response for model ${modelInfo.id}`, err)); - this.telemetry.logUsage('playground.ask', { 'model.id': modelInfo.id }); + const durationSeconds = getDurationSecondsSince(startTime); + this.telemetry.logUsage('playground.ask', { 'model.id': modelInfo.id, durationSeconds }); return query.id; }