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

Show hidden chats in chat list #3075

Merged
merged 4 commits into from
May 7, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions website/public/locales/en/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"chat_date": "{{val, datetime}}",
"config_title": "Chat configuration",
"delete_chat": "Delete 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!",
"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!",
"edit_plugin": "Edit Plugin",
"empty": "Untitled",
"input_placeholder": "Ask the assistant anything",
"login_message": "To use this feature, you need to login again. Login using one of these providers:",
"max_new_tokens": "Max new tokens",
"model": "Model",
"more_actions": "More Actions",
"only_visible": "Only visible",
"parameter_description": {
"max_new_tokens": "Max new tokens: This parameter tells the model how many new tokens it should generate at most for the response.",
"repetition_penalty": "Repetition Penalty: This parameter reduces the probability of repeating the same tokens again and again by making repeated tokens less likely than the model would ordinarily predict.",
Expand All @@ -23,8 +24,8 @@
},
"plugin_url_placeholder": "Enter plugin URL",
"plugins": "Plugins",
"preset_custom": "Custom",
"preset": "Preset",
"preset_custom": "Custom",
"queue_info": "Your message is queued, you are at position {{ queuePosition, number, integer }} in the queue.",
"remove_plugin": "Remove Plugin",
"repetition_penalty": "Repetition penalty",
Expand All @@ -33,12 +34,13 @@
"top_k": "Top K",
"top_p": "Top P",
"typical_p": "Typical P",
"unverified_plugin_description": "This plugin has not been verified by the Open Assistant team. Use at your own risk.",
"unverified_plugin": "UNVERIFIED",
"unverified_plugin_description": "This plugin has not been verified by the Open Assistant team. Use at your own risk.",
"used": "Used",
"verified_plugin_description": "This plugin has been verified by the Open Assistant team.",
"verified_plugin": "VERIFIED",
"verified_plugin_description": "This plugin has been verified by the Open Assistant team.",
"view_plugin": "View Plugin",
"visible_hidden": "Visible & hidden",
"warning": "This Assistant is a demonstration version that does not have internet access. It may generate incorrect or misleading information. It is not suitable for important use cases or for giving advice.",
"you_are_logged_in": "You are logged in to the chat service",
"your_chats": "Your Chats"
Expand Down
49 changes: 25 additions & 24 deletions website/src/components/Chat/ChatListBase.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import "simplebar-react/dist/simplebar.min.css";

import { Box, CardProps } from "@chakra-ui/react";
import { Box, CardProps, Flex } from "@chakra-ui/react";
import { Plus } from "lucide-react";
import { useTranslation } from "next-i18next";
import { memo, useCallback } from "react";
import { memo, useCallback, useState } from "react";
import SimpleBar from "simplebar-react";
import { GetChatsResponse } from "src/types/Chat";

import { ChatListItem } from "./ChatListItem";
import { ChatViewSelection } from "./ChatViewSelection";
import { CreateChatButton } from "./CreateChatButton";
import { InferencePoweredBy } from "./InferencePoweredBy";
import { useListChatPagination } from "./useListChatPagination";
import { ChatListViewSelection, useListChatPagination } from "./useListChatPagination";

export const ChatListBase = memo(function ChatListBase({
initialChats, // TODO: can we remove this?
...props
}: CardProps & { initialChats?: GetChatsResponse }) {
const { loadMoreRef, responses, mutateChatResponses } = useListChatPagination(initialChats);
export const ChatListBase = memo(function ChatListBase({ allowViews, ...props }: CardProps & { allowViews?: boolean }) {
const [view, setView] = useState<ChatListViewSelection>("visible");
const { loadMoreRef, responses, mutateChatResponses } = useListChatPagination(view);
const chats = responses?.flatMap((response) => response.chats) || [];

const { t } = useTranslation(["common", "chat"]);
Expand Down Expand Up @@ -78,23 +76,26 @@ export const ChatListBase = memo(function ChatListBase({
}}
{...props}
>
<CreateChatButton
py="5"
leftIcon={<Plus size="16px"></Plus>}
variant="outline"
justifyContent="start"
colorScheme="blue"
borderRadius="lg"
mx="3"
mb="2"
onUpdated={handleCreateChat}
>
{t("create_chat")}
</CreateChatButton>
<Flex flexDirection={["column", "row"]} alignItems="stretch" p="2" gap="3">
<CreateChatButton
leftIcon={<Plus size="16px" />}
variant="outline"
justifyContent="start"
colorScheme="blue"
borderRadius="lg"
onUpdated={handleCreateChat}
flexGrow="1"
>
{t("create_chat")}
</CreateChatButton>
{allowViews && (
<ChatViewSelection w={["full", "auto"]} onChange={(e) => setView(e.target.value as ChatListViewSelection)} />
)}
</Flex>
<SimpleBar
style={{ padding: "4px 0", maxHeight: "100%", height: "100%", minHeight: "0" }}
style={{ padding: "8px", maxHeight: "100%", height: "100%", minHeight: "0" }}
classNames={{
contentEl: "space-y-2 mx-3 flex flex-col overflow-y-auto",
contentEl: "space-y-2 flex flex-col overflow-y-auto",
}}
>
{chats.map((chat) => (
Expand Down
13 changes: 13 additions & 0 deletions website/src/components/Chat/ChatViewSelection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Select, SelectProps } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";

export const ChatViewSelection = (props: SelectProps) => {
const { t } = useTranslation("chat");

return (
<Select {...props}>
<option value="visible">{t("only_visible")}</option>
<option value="visible_hidden">{t("visible_hidden")}</option>
</Select>
);
};
15 changes: 8 additions & 7 deletions website/src/components/Chat/useListChatPagination.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { useEffect, useMemo, useRef } from "react";
import { get } from "src/lib/api";
import { API_ROUTES } from "src/lib/routes";
import { GetChatsResponse } from "src/types/Chat";
import useSWRInfinite from "swr/infinite";

export function useListChatPagination(initialChats?: GetChatsResponse) {
export type ChatListViewSelection = "visible" | "visible_hidden";

export function useListChatPagination(view: ChatListViewSelection) {
const {
data: responses,
mutate: mutateChatResponses,
setSize,
isLoading,
} = useSWRInfinite<GetChatsResponse>(
(pageIndex, previousPageData: GetChatsResponse) => {
if (!previousPageData && pageIndex === 0) return "/api/chat"; // initial call
const params = { include_hidden: view === "visible_hidden" };
if (!previousPageData && pageIndex === 0) return API_ROUTES.LIST_CHAT_WITH_PARMS(params); // initial call
if (previousPageData && !previousPageData.next) return null; // reached the end
return `/api/chat?after=${previousPageData.next}`; // paginated call
return API_ROUTES.LIST_CHAT_WITH_PARMS({ ...params, after: previousPageData.next }); // paginated call
},
get,
{
keepPreviousData: true,
revalidateFirstPage: false,
fallbackData: initialChats ? [initialChats] : undefined,
}
);
const loadMoreRef = useRef(null);
Expand All @@ -29,9 +32,7 @@ export function useListChatPagination(initialChats?: GetChatsResponse) {
const handleObserver: IntersectionObserverCallback = (entries) => {
const target = entries[0];
if (target.isIntersecting && !isLoading && !isEnd) {
setSize((size) => {
return size + 1;
});
setSize((size) => size + 1);
}
};
const observer = new IntersectionObserver(handleObserver);
Expand Down
1 change: 1 addition & 0 deletions website/src/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const API_ROUTES = {
// chat:
GET_CHAT: (chat_id: string) => createRoute(`/api/chat`, { chat_id }),
LIST_CHAT: "/api/chat",
LIST_CHAT_WITH_PARMS: (params: RouteQuery) => createRoute(API_ROUTES.LIST_CHAT, params),
GET_MESSAGE: (chat_id: string, message_id: string) => createRoute(`/api/chat/message`, { chat_id, message_id }),
CREATE_PROMPTER_MESSAGE: `/api/chat/prompter_message`,
CREATE_ASSISTANT_MESSAGE: `/api/chat/assistant_message`,
Expand Down
3 changes: 3 additions & 0 deletions website/src/pages/api/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const handler = withoutRole("banned", async (req, res, token) => {
if (req.query.after) {
params["after"] = req.query.after as string;
}
if (req.query.include_hidden) {
params.include_hidden = req.query.include_hidden as string;
}
data = await client.get_my_chats(params);
}
} else if (req.method === "POST") {
Expand Down
2 changes: 2 additions & 0 deletions website/src/pages/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const ChatList = () => {
<title>{t("chat")}</title>
</Head>
<ChatListBase
// TODO: enable this after visually differentiating hidden from visible chats & allowing 'unhide'
allowViews={process.env.NODE_ENV === "development"}
className="max-w-5xl mx-auto"
pt="4"
px="4"
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 @@ -184,4 +184,5 @@ export interface GetChatsParams {
limit?: number;
before?: string;
after?: string;
include_hidden?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have an option to only show hidden chat, since include_hidden will result in all chats, we still have to make the UI to show whether the chat is hidden or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, this will require some changes in the backend, so I am going to move it to a different PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to work in the inference backend, I suggest we have a filter like this, and apply when it is not null

type Filter = {
  hidden?: boolean
  allow_data_use?: boolean
  shared?: boolean // future
}

So the user can compose the filter they want. I can work on the frontend UI

}