diff --git a/client/src/plus/ai-help/constants.tsx b/client/src/plus/ai-help/constants.tsx index 2b4159ee1270..32c0f643fd1d 100644 --- a/client/src/plus/ai-help/constants.tsx +++ b/client/src/plus/ai-help/constants.tsx @@ -1,6 +1,6 @@ -export const SORRY_BACKEND = "Sorry, I don't know how to help with that."; +export const SORRY_BACKEND_PREFIX = "I'm sorry, but I can't"; export const SORRY_FRONTEND = - "Sorry, I don’t know how to help with that.\n\nPlease keep in mind that I am only limited to answer based on the MDN documentation."; + "I'm sorry, but I can't answer questions outside web development."; export const MESSAGE_SEARCHING = "Searching for MDN content…"; export const MESSAGE_SEARCHED = "Consulted MDN content:"; diff --git a/client/src/plus/ai-help/index.tsx b/client/src/plus/ai-help/index.tsx index 7373d8daa374..2c1943b92c51 100644 --- a/client/src/plus/ai-help/index.tsx +++ b/client/src/plus/ai-help/index.tsx @@ -48,7 +48,7 @@ import { useUIStatus } from "../../ui-context"; import { QueueEntry } from "../../types/playground"; import { AIHelpLanding } from "./landing"; import { - SORRY_BACKEND, + SORRY_BACKEND_PREFIX, SORRY_FRONTEND, MESSAGE_SEARCHING, MESSAGE_ANSWERING, @@ -288,6 +288,10 @@ function AIHelpAssistantResponse({ let sample = 0; + const isOffTopic = + message.role === MessageRole.Assistant && + message.content?.startsWith(SORRY_BACKEND_PREFIX); + function messageForStatus(status: MessageStatus) { switch (status) { case MessageStatus.Errored: @@ -314,33 +318,7 @@ function AIHelpAssistantResponse({ return ( <> -
- {message.status === MessageStatus.Pending - ? MESSAGE_SEARCHING - : MESSAGE_SEARCHED} -
- {message.sources && message.sources.length > 0 && ( - - )} + {!isOffTopic && } {(message.content || message.status === MessageStatus.InProgress || message.status === MessageStatus.Errored) && ( @@ -509,12 +487,12 @@ function AIHelpAssistantResponse({ }, }} > - {message.content?.replace(SORRY_BACKEND, SORRY_FRONTEND)} + {isOffTopic ? SORRY_FRONTEND : message.content} - {message.status === "complete" && - !message.content?.includes(SORRY_BACKEND) && ( - <> -
+ {(message.status === "complete" || isOffTopic) && ( + <> +
+ {!isOffTopic && ( - - Report an issue with this answer on GitHub - -
- - )} + )} + + Report an issue with this answer on GitHub + +
+ + )} )} ); } +function AIHelpAssistantResponseSources({ + message, +}: { + message: Pick; +}) { + const gleanClick = useGleanClick(); + + return ( + <> +
+ {message.status === MessageStatus.Pending + ? MESSAGE_SEARCHING + : MESSAGE_SEARCHED} +
+ {message.sources && message.sources.length > 0 && ( + + )} + + ); +} + export function AIHelpInner() { const formRef = useRef(null); const inputRef = useRef(null);