Skip to content

Commit

Permalink
Cody: Hide feedback button on err response (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak2431 authored Aug 2, 2023
1 parent 4de2490 commit e8317b2
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/ui/src/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ChatProps extends ChatClassNames {
isCodyEnabled: boolean
ChatButtonComponent?: React.FunctionComponent<ChatButtonProps>
pluginsDevMode?: boolean
isTranscriptError?: boolean
}

interface ChatClassNames extends TranscriptItemClassNames {
Expand Down Expand Up @@ -148,6 +149,7 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
isCodyEnabled,
ChatButtonComponent,
pluginsDevMode,
isTranscriptError,
}) => {
const [inputRows, setInputRows] = useState(1)
const [historyIndex, setHistoryIndex] = useState(inputHistory.length)
Expand Down Expand Up @@ -284,6 +286,7 @@ export const Chat: React.FunctionComponent<ChatProps> = ({
chatInputClassName={chatInputClassName}
ChatButtonComponent={ChatButtonComponent}
pluginsDevMode={pluginsDevMode}
isTranscriptError={isTranscriptError}
/>
)}

Expand Down
4 changes: 3 additions & 1 deletion lib/ui/src/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Transcript: React.FunctionComponent<
submitButtonComponent?: React.FunctionComponent<ChatUISubmitButtonProps>
ChatButtonComponent?: React.FunctionComponent<ChatButtonProps>
pluginsDevMode?: boolean
isTranscriptError?: boolean
} & TranscriptItemClassNames
> = React.memo(function TranscriptContent({
transcript,
Expand All @@ -59,6 +60,7 @@ export const Transcript: React.FunctionComponent<
chatInputClassName,
ChatButtonComponent,
pluginsDevMode,
isTranscriptError,
}) {
const transcriptContainerRef = useRef<HTMLDivElement>(null)
useEffect(() => {
Expand Down Expand Up @@ -118,7 +120,7 @@ export const Transcript: React.FunctionComponent<
FeedbackButtonsContainer={FeedbackButtonsContainer}
feedbackButtonsOnSubmit={feedbackButtonsOnSubmit}
copyButtonOnSubmit={copyButtonOnSubmit}
showFeedbackButtons={index !== 0}
showFeedbackButtons={index !== 0 && !isTranscriptError}
submitButtonComponent={submitButtonComponent}
chatInputClassName={chatInputClassName}
ChatButtonComponent={ChatButtonComponent}
Expand Down
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi
### Changed

- Removed the experimental hallucination detection that highlighted nonexistent file paths.
- Hide the feedback button in case of error assistant response. [pull/448](https://github.com/sourcegraph/cody/pull/448)

## [0.6.2]

Expand Down
7 changes: 7 additions & 0 deletions vscode/src/chat/ChatViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ export class ChatViewProvider extends MessageProvider implements vscode.WebviewV
})
}

/**
* Send transcript error to webview
*/
protected handleTranscriptErrors(transcriptError: boolean): void {
void this.webview?.postMessage({ type: 'transcript-errors', isTranscriptError: transcriptError })
}

protected handleSuggestions(suggestions: string[]): void {
void this.webview?.postMessage({
type: 'suggestions',
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/chat/InlineChatViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ export class InlineChatViewProvider extends MessageProvider {
protected handleMyPrompts(): void {
// my prompts not yet implemented for inline chat
}

protected handleTranscriptErrors(): void {
// handle transcript errors not yet implemented for inline chat
}
}
3 changes: 3 additions & 0 deletions vscode/src/chat/MessageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ abstract class MessageHandler {
protected abstract handleSuggestions(suggestions: string[]): void
protected abstract handleEnabledPlugins(plugins: string[]): void
protected abstract handleMyPrompts(prompts: string[], isEnabled: boolean): void
protected abstract handleTranscriptErrors(transciptError: boolean): void
}

export interface MessageProviderOptions {
Expand Down Expand Up @@ -271,6 +272,7 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
}
// Display error message as assistant response
this.transcript.addErrorAsAssistantResponse(err)
this.handleTranscriptErrors(true)
// We ignore embeddings errors in this instance because we're already showing an
// error message and don't want to overwhelm the user.
void this.onCompletionEnd(true)
Expand Down Expand Up @@ -653,6 +655,7 @@ export abstract class MessageProvider extends MessageHandler implements vscode.D
// Display error message as assistant response for users with indexed codebase but getting search errors
if (this.contextProvider.context.checkEmbeddingsConnection() && searchErrors) {
this.transcript.addErrorAsAssistantResponse(searchErrors)
this.handleTranscriptErrors(true)
debug('ChatViewProvider:onLogEmbeddingsErrors', '', { verbose: searchErrors })
}
}
Expand Down
1 change: 1 addition & 0 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ExtensionMessage =
| { type: 'app-state'; isInstalled: boolean }
| { type: 'enabled-plugins'; plugins: string[] }
| { type: 'my-prompts'; prompts: string[]; isEnabled: boolean }
| { type: 'transcript-errors'; isTranscriptError: boolean }

/**
* The subset of configuration that is visible to the webview.
Expand Down
6 changes: 6 additions & 0 deletions vscode/webviews/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
const [isAppInstalled, setIsAppInstalled] = useState<boolean>(false)
const [enabledPlugins, setEnabledPlugins] = useState<string[]>([])
const [myPrompts, setMyPrompts] = useState<string[] | null>(null)
const [isTranscriptError, setIsTranscriptError] = useState<boolean>(false)

useEffect(
() =>
Expand All @@ -50,6 +51,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
const msgLength = message.messages.length - 1
setTranscript(message.messages.slice(0, msgLength))
setMessageInProgress(message.messages[msgLength])
setIsTranscriptError(false)
} else {
setTranscript(message.messages)
setMessageInProgress(null)
Expand Down Expand Up @@ -90,6 +92,9 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
case 'my-prompts':
setMyPrompts(message.isEnabled ? message.prompts : null)
break
case 'transcript-errors':
setIsTranscriptError(message.isTranscriptError)
break
}
}),
[errorMessages, view, vscodeAPI]
Expand Down Expand Up @@ -177,6 +182,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
pluginsDevMode={Boolean(config?.pluginsDebugEnabled)}
setSuggestions={setSuggestions}
telemetryService={telemetryService}
isTranscriptError={isTranscriptError}
showOnboardingButtons={userHistory && Object.entries(userHistory).length === 0}
/>
)}
Expand Down
3 changes: 3 additions & 0 deletions vscode/webviews/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface ChatboxProps {
suggestions?: string[]
setSuggestions?: (suggestions: undefined | string[]) => void
pluginsDevMode?: boolean
isTranscriptError: boolean
showOnboardingButtons?: boolean | null
}

Expand All @@ -57,6 +58,7 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
suggestions,
setSuggestions,
pluginsDevMode,
isTranscriptError,
showOnboardingButtons,
}) => {
const [abortMessageInProgressInternal, setAbortMessageInProgress] = useState<() => void>(() => () => undefined)
Expand Down Expand Up @@ -149,6 +151,7 @@ export const Chat: React.FunctionComponent<React.PropsWithChildren<ChatboxProps>
setSuggestions={setSuggestions}
abortMessageInProgressComponent={AbortMessageInProgress}
onAbortMessageInProgress={abortMessageInProgress}
isTranscriptError={isTranscriptError}
// TODO: We should fetch this from the server and pass a pretty component
// down here to render cody is disabled on the instance nicely.
isCodyEnabled={true}
Expand Down

0 comments on commit e8317b2

Please sign in to comment.