From 0d4a532a40b56bcc44366d10cb13bc8638fc1231 Mon Sep 17 00:00:00 2001 From: Aditya Kalia <32119652+akalia25@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:11:59 -0400 Subject: [PATCH] Chat Telemetry: Restores `prompt` and `response` text recording (#5553) Previously, chat telemetry events were not capturing `promptText` and `responseText` due to the asynchronous nature of the `truncatePromptString` function, which was modified in a recent pull request(https://github.com/sourcegraph/cody/pull/5231). Now, we have added the proper `await` calls when using `truncatePromptString`, re-enabling the collection of this data for chat telemetry events. Key changes: 1. Added `await` to `ChatController` where `truncatePromptString` is being used 2. Made `addBotMessage` an async func ## Test plan Tested locally and verified `promptText` and `responseText` are being recorded again. https://github.com/user-attachments/assets/b3952819-0945-4162-baf7-d98704aec21d ## Changelog --- vscode/src/chat/chat-view/ChatController.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vscode/src/chat/chat-view/ChatController.ts b/vscode/src/chat/chat-view/ChatController.ts index 962f08239fd2..db74242b1004 100644 --- a/vscode/src/chat/chat-view/ChatController.ts +++ b/vscode/src/chat/chat-view/ChatController.ts @@ -911,7 +911,8 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv // V2 telemetry exports privateMetadata only for DotCom users // the condition below is an additional safeguard measure promptText: - isDotCom(authStatus) && truncatePromptString(inputText, CHAT_INPUT_TOKEN_BUDGET), + isDotCom(authStatus) && + (await truncatePromptString(inputText, CHAT_INPUT_TOKEN_BUDGET)), }, billingMetadata: { product: 'cody', @@ -1423,7 +1424,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv /** * Finalizes adding a bot message to the chat model and triggers an update to the view. */ - private addBotMessage(requestID: string, rawResponse: PromptString): void { + private async addBotMessage(requestID: string, rawResponse: PromptString): Promise { const messageText = reformatBotMessageForChat(rawResponse) this.chatModel.addBotMessage({ text: messageText }) void this.saveSession() @@ -1448,7 +1449,8 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv // V2 telemetry exports privateMetadata only for DotCom users // the condition below is an aditional safegaurd measure responseText: - isDotCom(authStatus) && truncatePromptString(messageText, CHAT_OUTPUT_TOKEN_BUDGET), + isDotCom(authStatus) && + (await truncatePromptString(messageText, CHAT_OUTPUT_TOKEN_BUDGET)), chatModel: this.chatModel.modelID, }, billingMetadata: { @@ -1798,7 +1800,8 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv // V2 telemetry exports privateMetadata only for DotCom users // the condition below is an additional safeguard measure promptText: - isDotCom(authStatus) && truncatePromptString(inputText, CHAT_INPUT_TOKEN_BUDGET), + isDotCom(authStatus) && + (await truncatePromptString(inputText, CHAT_INPUT_TOKEN_BUDGET)), gitMetadata, }, billingMetadata: {