Skip to content

Commit

Permalink
Disable data collection features on opt-out (#3425)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
someone13574 authored Jun 16, 2023
1 parent e1ed96a commit f7f4459
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
44 changes: 27 additions & 17 deletions website/src/components/Chat/ChatConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf

const toast = useToast();

const { isLoading: isLoadingMessages } = useSWR<ChatItem>(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<ChatItem>(
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 }) => {
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -470,6 +479,7 @@ export const ChatConversation = memo(function ChatConversation({ chatId, getConf
onEditPrompt={handleEditPrompt}
showEncourageMessage={showEncourageMessage}
onEncourageMessageClose={setShowEncourageMessage.off}
showFeedbackOptions={chatData?.allow_data_use}
></ChatConversationTree>
{isSending && streamedResponse && <PendingMessageEntry isAssistant content={streamedResponse} />}
{(isSending || isAwaitingMessageSelect) &&
Expand Down
12 changes: 9 additions & 3 deletions website/src/components/Chat/ChatMessageEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type ChatMessageEntryProps = {
"data-id"?: string;
showEncourageMessage: boolean;
onEncourageMessageClose: () => void;
showFeedbackOptions: boolean;
};

export const ChatMessageEntry = memo(function ChatMessageEntry({
Expand All @@ -50,6 +51,7 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
canRetry,
showEncourageMessage,
onEncourageMessageClose,
showFeedbackOptions,
...props
}: ChatMessageEntryProps) {
const { t } = useTranslation("common");
Expand Down Expand Up @@ -179,8 +181,12 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
) : (
<BaseMessageEmojiButton emoji={Check} />
)}
<BaseMessageEmojiButton emoji={ThumbsUp} checked={score === 1} onClick={handleThumbsUp} />
<BaseMessageEmojiButton emoji={ThumbsDown} checked={score === -1} onClick={handleThumbsDown} />
{showFeedbackOptions && (
<BaseMessageEmojiButton emoji={ThumbsUp} checked={score === 1} onClick={handleThumbsUp} />
)}
{showFeedbackOptions && (
<BaseMessageEmojiButton emoji={ThumbsDown} checked={score === -1} onClick={handleThumbsDown} />
)}
</>
)}
</MessageInlineEmojiRow>
Expand All @@ -189,7 +195,7 @@ export const ChatMessageEntry = memo(function ChatMessageEntry({
)}
{work_parameters && <WorkParametersDisplay parameters={work_parameters} />}
</PendingMessageEntry>
{state === "complete" && isAssistant && showEncourageMessage && (
{state === "complete" && isAssistant && showEncourageMessage && showFeedbackOptions && (
<EncourageMessage
onThumbsUp={handleThumbsUp}
onThumbsDown={handleThumbsDown}
Expand Down
1 change: 1 addition & 0 deletions website/src/types/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ChatItem {
created_at: string; //timestamp
modified_at: string; //timestamp
messages: InferenceMessage[];
allow_data_use: boolean;

// those are not available when you first create a chat
title?: string;
Expand Down

0 comments on commit f7f4459

Please sign in to comment.