Skip to content

Commit

Permalink
Chat Telemetry: Restores prompt and response text recording (#5553)
Browse files Browse the repository at this point in the history
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(#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


<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
  • Loading branch information
akalia25 authored Sep 13, 2024
1 parent 24192e4 commit 0d4a532
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<void> {
const messageText = reformatBotMessageForChat(rawResponse)
this.chatModel.addBotMessage({ text: messageText })
void this.saveSession()
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 0d4a532

Please sign in to comment.