From f7f445951b919b72bd8008fab7cbeb6d41408001 Mon Sep 17 00:00:00 2001 From: someone13574 <81528246+someone13574@users.noreply.github.com> Date: Fri, 16 Jun 2023 01:28:35 -0400 Subject: [PATCH] Disable data collection features on opt-out (#3425) - Prevents draft messages from being generated when a user opts-out from data for a chat - Hides the thumbs up and down buttons - Disables encourage message --- .../src/components/Chat/ChatConversation.tsx | 44 ++++++++++++------- .../src/components/Chat/ChatMessageEntry.tsx | 12 +++-- website/src/types/Chat.ts | 1 + 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/website/src/components/Chat/ChatConversation.tsx b/website/src/components/Chat/ChatConversation.tsx index 8ae4133393..a0242a9900 100644 --- a/website/src/components/Chat/ChatConversation.tsx +++ b/website/src/components/Chat/ChatConversation.tsx @@ -52,22 +52,26 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf const toast = useToast(); - const { isLoading: isLoadingMessages } = useSWR(chatId ? API_ROUTES.GET_CHAT(chatId) : null, get, { - onSuccess(data) { - setMessages(data.messages.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at))); - setActiveThreadTailMessageId(data.active_thread_tail_message_id); - }, - onError: (err) => { - if (err instanceof OasstError && err.httpStatusCode === 404) { - // chat does not exist, probably deleted - return router.push("/chat"); - } - toast({ - title: "Failed to load chat", - status: "error", - }); - }, - }); + const { isLoading: isLoadingMessages, data: chatData } = useSWR( + chatId ? API_ROUTES.GET_CHAT(chatId) : null, + get, + { + onSuccess(data) { + setMessages(data.messages.sort((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at))); + setActiveThreadTailMessageId(data.active_thread_tail_message_id); + }, + onError: (err) => { + if (err instanceof OasstError && err.httpStatusCode === 404) { + // chat does not exist, probably deleted + return router.push("/chat"); + } + toast({ + title: "Failed to load chat", + status: "error", + }); + }, + } + ); const createAndFetchAssistantMessage = useCallback( async ({ parentId, chatId }: { parentId: string; chatId: string }) => { @@ -306,7 +310,11 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf setReytryingParentId(params.parentId); const { plugins } = getConfigValues(); - if ((!ENABLE_DRAFTS_WITH_PLUGINS && plugins.length !== 0) || NUM_GENERATED_DRAFTS <= 1) { + if ( + (!ENABLE_DRAFTS_WITH_PLUGINS && plugins.length !== 0) || + NUM_GENERATED_DRAFTS <= 1 || + !chatData.allow_data_use + ) { await createAndFetchAssistantMessage(params); setReytryingParentId(null); } else { @@ -320,6 +328,7 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf ENABLE_DRAFTS_WITH_PLUGINS, NUM_GENERATED_DRAFTS, createAndFetchAssistantMessage, + chatData?.allow_data_use, ] ); const handleOnVote: ChatMessageEntryProps["onVote"] = useCallback( @@ -470,6 +479,7 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf onEditPrompt={handleEditPrompt} showEncourageMessage={showEncourageMessage} onEncourageMessageClose={setShowEncourageMessage.off} + showFeedbackOptions={chatData?.allow_data_use} > {isSending && streamedResponse && } {(isSending || isAwaitingMessageSelect) && diff --git a/website/src/components/Chat/ChatMessageEntry.tsx b/website/src/components/Chat/ChatMessageEntry.tsx index a0fdaab3fa..22be984dbb 100644 --- a/website/src/components/Chat/ChatMessageEntry.tsx +++ b/website/src/components/Chat/ChatMessageEntry.tsx @@ -38,6 +38,7 @@ export type ChatMessageEntryProps = { "data-id"?: string; showEncourageMessage: boolean; onEncourageMessageClose: () => void; + showFeedbackOptions: boolean; }; export const ChatMessageEntry = memo(function ChatMessageEntry({ @@ -50,6 +51,7 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({ canRetry, showEncourageMessage, onEncourageMessageClose, + showFeedbackOptions, ...props }: ChatMessageEntryProps) { const { t } = useTranslation("common"); @@ -179,8 +181,12 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({ ) : ( )} - - + {showFeedbackOptions && ( + + )} + {showFeedbackOptions && ( + + )} )} @@ -189,7 +195,7 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({ )} {work_parameters && } - {state === "complete" && isAssistant && showEncourageMessage && ( + {state === "complete" && isAssistant && showEncourageMessage && showFeedbackOptions && (