Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure precomputed intent is not stale #6572

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ interface TranscriptInteractionProps
}) => void
}

interface IntentResults {
query: string
intent: ChatMessage['intent']
allScores?: { intent: string; score: number }[]
}

const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
const {
interaction: { humanMessage, assistantMessage },
Expand All @@ -266,14 +272,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
smartApplyEnabled,
editorRef: parentEditorRef,
} = props
const [intentResults, setIntentResults] = useMutatedValue<
| {
intent: ChatMessage['intent']
allScores?: { intent: string; score: number }[]
}
| undefined
| null
>()
const [intentResults, setIntentResults] = useMutatedValue<IntentResults | undefined | null>()

const { activeChatContext, setActiveChatContext } = props
const humanEditorRef = useRef<PromptEditorRefAPI | null>(null)
Expand Down Expand Up @@ -309,10 +308,14 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
return
}

const { intent, intentScores } = intentFromSubmit
? { intent: intentFromSubmit, intentScores: undefined }
: getIntentProps(editorValue, intentResults.current)

const commonProps = {
editorValue,
intent: intentFromSubmit || intentResults.current?.intent,
intentScores: intentFromSubmit ? undefined : intentResults.current?.allScores,
intent,
intentScores,
manuallySelectedIntent: !!intentFromSubmit,
traceparent,
}
Expand Down Expand Up @@ -371,18 +374,16 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {

setIntentResults(undefined)

const subscription = extensionAPI
.detectIntent(
inputTextWithMappedContextChipsFromPromptEditorState(editorValue.editorState)
)
.subscribe({
next: value => {
setIntentResults(value)
},
error: error => {
console.error('Error detecting intent:', error)
},
})
const query = inputTextWithMappedContextChipsFromPromptEditorState(editorValue.editorState)

const subscription = extensionAPI.detectIntent(query).subscribe({
next: value => {
setIntentResults(value && { ...value, query })
},
error: error => {
console.error('Error detecting intent:', error)
},
})

// Clean up subscription if component unmounts
return () => subscription.unsubscribe()
Expand Down Expand Up @@ -775,3 +776,13 @@ function reevaluateSearchWithSelectedFilters({
selectedFilters,
})
}

const getIntentProps = (editorValue: SerializedPromptEditorValue, results?: IntentResults | null) => {
const query = inputTextWithMappedContextChipsFromPromptEditorState(editorValue.editorState)

if (query === results?.query) {
return { intent: results.intent, intentScores: results.allScores }
}

return {}
}
Loading