Skip to content

Commit

Permalink
add duration for askPlayground and stopPlayground
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Feb 6, 2024
1 parent b9c14cf commit 97e3915
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/backend/src/managers/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class PlayGroundManager {
}

async stopPlayground(modelId: string): Promise<void> {
const startTime = performance.now();
const state = this.playgrounds.get(modelId);
if (state?.container === undefined) {
throw new Error('model is not running');
Expand All @@ -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<number> {
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' });
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 97e3915

Please sign in to comment.