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

feat: Allow an option for opting out of training data collection for each chat #3104

Merged
merged 1 commit into from May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions website/public/locales/en/chat.json
Expand Up @@ -6,6 +6,13 @@
"delete_chat": "Delete chat",
"delete_confirmation": "Are you sure you want to delete this chat?",
"delete_confirmation_detail": "If you delete this chat, it won't be part of our data, and we won't be able to use it to improve our models. Please take the time to upvote and downvote responses in other chats to help us make Open Assistant better!",
"opt_out": {
"button": "Opt out of training data",
"success_message": "You have opted out of training data.",
"dialog": {
"title": "Confirm opting of training data"
}
},
"edit_plugin": "Edit Plugin",
"empty": "Untitled",
"input_placeholder": "Ask the assistant anything",
Expand Down
53 changes: 51 additions & 2 deletions website/src/components/Chat/ChatListItem.tsx
Expand Up @@ -20,8 +20,9 @@ import {
useBoolean,
useDisclosure,
useOutsideClick,
useToast,
} from "@chakra-ui/react";
import { Check, EyeOff, LucideIcon, MoreHorizontal, Pencil, Trash, X } from "lucide-react";
import { Check, EyeOff, LucideIcon, MoreHorizontal, Pencil, Trash, X, FolderX } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
Expand Down Expand Up @@ -162,6 +163,7 @@ export const ChatListItem = ({
<Portal>
{/* higher z-index so that it is displayed over the mobile sidebar */}
<MenuList zIndex="var(--chakra-zIndices-popover)">
<OptOutDataButton chatId={chat.id} />
<DeleteChatButton chatId={chat.id} onDelete={onDelete} />
</MenuList>
</Portal>
Expand Down Expand Up @@ -235,14 +237,61 @@ const DeleteChatButton = ({
);
return (
<>
<MenuItem onClick={onOpen} icon={<Trash />}>
<MenuItem onClick={onOpen} icon={<Trash size={16} />}>
{t("common:delete")}
</MenuItem>
{alert}
</>
);
};

const OptOutDataButton = ({ chatId }: { chatId: string }) => {
const { t } = useTranslation(["chat", "common"]);
const { isOpen, onOpen, onClose } = useDisclosure();
const cancelRef = useRef();
const { trigger: updateChat, isMutating: isUpdating } = useSWRMutation(API_ROUTES.UPDATE_CHAT(), put);
const toast = useToast();

const handleOptOut = useCallback(async () => {
await updateChat({ chat_id: chatId, allow_data_use: false });
onClose();
toast({
title: t("chat:opt_out.success_message"),
status: "success",
position: "top",
});
}, [chatId, onClose, updateChat]);

const alert = (
<AlertDialog isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}>
<AlertDialogOverlay>
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
{t("chat:opt_out.dialog.title")}
</AlertDialogHeader>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>
{t("common:cancel")}
</Button>
<Button colorScheme="red" onClick={handleOptOut} ml={3} isLoading={isUpdating}>
{t("common:confirm")}
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialogOverlay>
</AlertDialog>
);

return (
<>
<MenuItem onClick={onOpen} icon={<FolderX size={16} />}>
{t("chat:opt_out.button")}
</MenuItem>
{alert}
</>
);
};

type ChatListItemIconButtonProps = {
onClick?: () => void;
label?: string;
Expand Down