From b01eb60174ccf2667f555ceefb5492ea2ed850e2 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Thu, 4 May 2023 18:28:34 +0200 Subject: [PATCH] Cody: Log chat prediction usage (#51474) Adds logging to the chat prediction experimental feature. ## Test plan https://user-images.githubusercontent.com/458591/236258186-697fcbfb-1ce8-45dd-8703-86a1e7b8dbee.mov --- client/cody-ui/src/Chat.tsx | 10 +++++----- client/cody/CHANGELOG.md | 2 ++ client/cody/src/chat/ChatViewProvider.ts | 9 ++++++--- client/cody/src/chat/protocol.ts | 2 +- client/cody/webviews/Chat.tsx | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/client/cody-ui/src/Chat.tsx b/client/cody-ui/src/Chat.tsx index 0aa23ac6819..76dd72eacb2 100644 --- a/client/cody-ui/src/Chat.tsx +++ b/client/cody-ui/src/Chat.tsx @@ -23,7 +23,7 @@ interface ChatProps extends ChatClassNames { setFormInput: (input: string) => void inputHistory: string[] setInputHistory: (history: string[]) => void - onSubmit: (text: string) => void + onSubmit: (text: string, submitType: 'user' | 'suggestion') => void textAreaComponent: React.FunctionComponent submitButtonComponent: React.FunctionComponent suggestionButtonComponent?: React.FunctionComponent @@ -138,12 +138,12 @@ export const Chat: React.FunctionComponent = ({ ) const submitInput = useCallback( - (input: string): void => { + (input: string, submitType: 'user' | 'suggestion'): void => { if (messageInProgress) { return } - onSubmit(input) + onSubmit(input, submitType) setSuggestions?.(undefined) setHistoryIndex(input.length + 1) setInputHistory([...inputHistory, input]) @@ -156,7 +156,7 @@ export const Chat: React.FunctionComponent = ({ if (formInput.trim() && !messageInProgress) { setInputRows(5) setFormInput('') - submitInput(formInput) + submitInput(formInput, 'user') } }, [formInput, messageInProgress, setFormInput, submitInput]) @@ -223,7 +223,7 @@ export const Chat: React.FunctionComponent = ({ submitInput(suggestion)} + onClick={() => submitInput(suggestion, 'suggestion')} /> ) : null )} diff --git a/client/cody/CHANGELOG.md b/client/cody/CHANGELOG.md index cbeb4b26175..5c7d1ec0212 100644 --- a/client/cody/CHANGELOG.md +++ b/client/cody/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to Sourcegraph Cody will be documented in this file. ### Added +- Adds usage metrics to the experimental chat predictions feature [pull/51474](https://github.com/sourcegraph/sourcegraph/pull/51474) + ### Fixed ### Changed diff --git a/client/cody/src/chat/ChatViewProvider.ts b/client/cody/src/chat/ChatViewProvider.ts index 673dab1a60a..dace49b09fb 100644 --- a/client/cody/src/chat/ChatViewProvider.ts +++ b/client/cody/src/chat/ChatViewProvider.ts @@ -155,11 +155,11 @@ export class ChatViewProvider implements vscode.WebviewViewProvider, vscode.Disp this.sendChatHistory() break case 'submit': - await this.onHumanMessageSubmitted(message.text) + await this.onHumanMessageSubmitted(message.text, message.submitType) break case 'edit': this.transcript.removeLastInteraction() - await this.onHumanMessageSubmitted(message.text) + await this.onHumanMessageSubmitted(message.text, 'user') break case 'executeRecipe': await this.executeRecipe(message.recipe) @@ -287,7 +287,10 @@ export class ChatViewProvider implements vscode.WebviewViewProvider, vscode.Disp void this.saveTranscriptToChatHistory() } - private async onHumanMessageSubmitted(text: string): Promise { + private async onHumanMessageSubmitted(text: string, submitType: 'user' | 'suggestion'): Promise { + if (submitType === 'suggestion') { + logEvent('CodyVSCodeExtension:chatPredictions:used') + } this.inputHistory.push(text) if (this.config.experimentalChatPredictions) { diff --git a/client/cody/src/chat/protocol.ts b/client/cody/src/chat/protocol.ts index 2d5293c6e3a..a54a93ab6a5 100644 --- a/client/cody/src/chat/protocol.ts +++ b/client/cody/src/chat/protocol.ts @@ -12,7 +12,7 @@ export type WebviewMessage = command: 'initialized' } | { command: 'event'; event: string; value: string } - | { command: 'submit'; text: string } + | { command: 'submit'; text: string; submitType: 'user' | 'suggestion' } | { command: 'executeRecipe'; recipe: string } | { command: 'settings'; serverEndpoint: string; accessToken: string } | { command: 'removeToken' } diff --git a/client/cody/webviews/Chat.tsx b/client/cody/webviews/Chat.tsx index f3315a3eecc..d64f93ce1f9 100644 --- a/client/cody/webviews/Chat.tsx +++ b/client/cody/webviews/Chat.tsx @@ -51,8 +51,8 @@ export const Chat: React.FunctionComponent setSuggestions, }) => { const onSubmit = useCallback( - (text: string) => { - vscodeAPI.postMessage({ command: 'submit', text: escapeCodyMarkdown(text) }) + (text: string, submitType: 'user' | 'suggestion') => { + vscodeAPI.postMessage({ command: 'submit', text: escapeCodyMarkdown(text), submitType }) }, [vscodeAPI] )