Skip to content

Commit

Permalink
Logging, change manually selected intent to enum instead of bool
Browse files Browse the repository at this point in the history
  • Loading branch information
janhartman committed Jan 14, 2025
1 parent 6f84685 commit a8854bc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 23 deletions.
60 changes: 49 additions & 11 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
this.setWebviewToChat()
break
case 'submit': {
logDebug(
'ChatController',
'onDidReceiveMessage.submit',
JSON.stringify({ intent: message.intent, scores: message.intentScores })
)
await this.handleUserMessage({
requestID: uuid.v4(),
inputText: PromptString.unsafe_fromUserQuery(message.text),
Expand Down Expand Up @@ -640,7 +645,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
command?: DefaultChatCommands
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
manuallySelectedIntent?: ChatMessage['intent'] | undefined | null
traceparent?: string | undefined | null
selectedAgent?: string | undefined | null
}): Promise<void> {
Expand Down Expand Up @@ -700,12 +705,14 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
signal,
detectedIntent,
detectedIntentScores,
manuallySelectedIntent,
}: {
requestID: string
input: string
signal: AbortSignal
detectedIntent?: ChatMessage['intent'] | undefined | null
detectedIntentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: ChatMessage['intent'] | undefined | null
}): Promise<{
intent: ChatMessage['intent']
intentScores: { intent: string; score: number }[]
Expand All @@ -717,9 +724,13 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
// The `detectedIntent` comes from the webview, where it can either be manually set by the user
// using the dropdown UI or automatically pre-fetched for the input while the user is typing.
// If any such intent is already detected, we use that.
if (detectedIntent) {

// TODO: detectedIntent is null here because it isn't persisted in the transcript for some reason

// TODO: differentiate between manually selected intent and detected intent
if (manuallySelectedIntent) {
return {
intent: detectedIntent,
intent: manuallySelectedIntent,
intentScores: detectedIntentScores || [],
}
}
Expand Down Expand Up @@ -784,13 +795,22 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
})
recorder.recordChatQuestionSubmitted(mentions)

logDebug(
'ChatController',
'getIntent',
JSON.stringify({
detectedIntent: detectedIntent,
detectedIntentScores: detectedIntentScores,
})
)
const { intent, intentScores } = await this.getIntentAndScores({
requestID,
input: editorState
? inputTextWithMappedContextChipsFromPromptEditorState(editorState)
: inputText.toString(),
detectedIntent,
detectedIntentScores,
manuallySelectedIntent,
signal,
})
signal.throwIfAborted()
Expand All @@ -808,16 +828,29 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
})

recorder.setIntentInfo({
userSpecifiedIntent:
manuallySelectedIntent && detectedIntent
? detectedIntent
: this.featureCodyExperimentalOneBox
? 'auto'
: 'chat',
userSpecifiedIntent: manuallySelectedIntent
? manuallySelectedIntent
: this.featureCodyExperimentalOneBox
? 'auto'
: 'chat',
detectedIntent: intent,
detectedIntentScores: intentScores,
})

logDebug(
'ChatController',
'Setting intent info',
JSON.stringify({
userSpecifiedIntent: manuallySelectedIntent
? manuallySelectedIntent
: this.featureCodyExperimentalOneBox
? 'auto'
: 'chat',
detectedIntent: intent,
detectedIntentScores: intentScores,
})
)

this.postEmptyMessageInProgress(model)
let messageInProgress: ChatMessage = { speaker: 'assistant', model }
try {
Expand Down Expand Up @@ -1053,7 +1086,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
editorState: SerializedPromptEditorState | null
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
manuallySelectedIntent?: ChatMessage['intent'] | undefined | null
}): Promise<void> {
const abortSignal = this.startNewSubmitOrEditOperation()

Expand All @@ -1070,6 +1103,11 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return
}
this.chatBuilder.removeMessagesFromIndex(humanMessage, 'human')
logDebug(
'ChatController',
'handleEdit',
JSON.stringify({ intent: intent, scores: intentScores })
)
return await this.handleUserMessage({
requestID,
inputText: text,
Expand Down Expand Up @@ -1734,4 +1772,4 @@ export function manipulateWebviewHTML(html: string, options: TransformHTMLOption
async function joinModelWaitlist(): Promise<void> {
await localStorage.setOrDeleteWaitlistO1(true)
telemetryRecorder.recordEvent('cody.joinLlmWaitlist', 'clicked')
}
}
6 changes: 4 additions & 2 deletions vscode/src/chat/chat-view/handlers/OmniboxTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
currentAuthStatusAuthed,
firstResultFromOperation,
getTokenCounterUtils,
logDebug,
logError,
telemetryEvents,
wrapInActiveSpan,
Expand Down Expand Up @@ -65,6 +66,7 @@ export class OmniboxTelemetry {
}

public setIntentInfo(intentInfo: IntentInfo) {
logDebug('OmniboxTelemetry', 'setting intent info', JSON.stringify(intentInfo))
this.intentInfo = intentInfo
}

Expand All @@ -78,7 +80,7 @@ export class OmniboxTelemetry {
if (!this.intentInfo) {
logError(
'AgentTelemetry',
'failed to log cody.chat-question/executed beacuse intent info was not set'
'failed to log cody.chat-question/executed because intent info was not set'
)
return
}
Expand All @@ -92,4 +94,4 @@ export class OmniboxTelemetry {
this.tokenCounterUtils
)
}
}
}
6 changes: 3 additions & 3 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export interface WebviewSubmitMessage extends WebviewContextMessage {
editorState?: unknown | undefined | null
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
manuallySelectedIntent?: ChatMessage['intent'] | undefined | null
traceparent?: string | undefined | null
steps?: ProcessingStep[] | undefined | null
}
Expand All @@ -226,7 +226,7 @@ interface WebviewEditMessage extends WebviewContextMessage {
editorState?: unknown | undefined | null
intent?: ChatMessage['intent'] | undefined | null
intentScores?: { intent: string; score: number }[] | undefined | null
manuallySelectedIntent?: boolean | undefined | null
manuallySelectedIntent?: ChatMessage['intent'] | undefined | null
steps?: ProcessingStep[] | undefined | null
}

Expand Down Expand Up @@ -309,4 +309,4 @@ export function isSourcegraphToken(text: string): boolean {

interface CodyIDECssVariables {
[key: string]: string
}
}
24 changes: 17 additions & 7 deletions vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,17 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
return
}

console.log(
'Transcript',
'onUserAction',
JSON.stringify({ msg: humanMessage.intent, intentResults: intentResults })
)

const commonProps = {
editorValue,
intent: intentFromSubmit || intentResults.current?.intent,
intentScores: intentFromSubmit ? undefined : intentResults.current?.allScores,
manuallySelectedIntent: !!intentFromSubmit,
intent: intentResults.current?.intent,
intentScores: intentResults.current?.allScores,
manuallySelectedIntent: intentFromSubmit,
traceparent,
}

Expand All @@ -322,7 +328,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
// reference search results that don't exist anymore.
// This is a no-op if the input does not contain any search context chips.
// NOTE: Doing this for the penultimate input only seems to suffice because
// editing a message earlier in the transcript will clear the converstation
// editing a message earlier in the transcript will clear the conversation
// and reset the last input anyway.
if (isLastSentInteraction) {
lastEditorRef.current?.filterMentions(item => !isCodeSearchContextItem(item))
Expand All @@ -341,6 +347,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {

const onEditSubmit = useCallback(
(intentFromSubmit?: ChatMessage['intent']): void => {
console.log('Transcript', 'onEditSubmit', JSON.stringify(intentFromSubmit))
onUserAction('edit', intentFromSubmit)
},
[onUserAction]
Expand Down Expand Up @@ -369,6 +376,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
return
}

console.log('Transcript', 'onChange', 'setting to undefined')
setIntentResults(undefined)

const subscription = extensionAPI
Expand All @@ -377,6 +385,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
)
.subscribe({
next: value => {
console.log('Transcript', 'onDetectedIntent', JSON.stringify(value))
setIntentResults(value)
},
error: error => {
Expand Down Expand Up @@ -524,6 +533,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
const telemetryRecorder = useTelemetryRecorder()
const reSubmitWithIntent = useCallback(
(intent: ChatMessage['intent']) => {
console.log('Transcript', 'resubmitWithIntent', intent)
const editorState = humanEditorRef.current?.getSerializedValue()
if (editorState) {
onEditSubmit(intent)
Expand Down Expand Up @@ -721,7 +731,7 @@ export function editHumanMessage({
editorValue: SerializedPromptEditorValue
intent?: ChatMessage['intent']
intentScores?: { intent: string; score: number }[]
manuallySelectedIntent?: boolean
manuallySelectedIntent?: ChatMessage['intent']
}): void {
getVSCodeAPI().postMessage({
command: 'edit',
Expand All @@ -746,7 +756,7 @@ function submitHumanMessage({
editorValue: SerializedPromptEditorValue
intent?: ChatMessage['intent']
intentScores?: { intent: string; score: number }[]
manuallySelectedIntent?: boolean
manuallySelectedIntent?: ChatMessage['intent']
traceparent: string
}): void {
getVSCodeAPI().postMessage({
Expand Down Expand Up @@ -774,4 +784,4 @@ function reevaluateSearchWithSelectedFilters({
index: messageIndexInTranscript,
selectedFilters,
})
}
}

0 comments on commit a8854bc

Please sign in to comment.