From a640bedbc313fa87c836d390a3db5d3a09cd628b Mon Sep 17 00:00:00 2001 From: Oliver Stanley Date: Tue, 18 Apr 2023 09:47:13 +0100 Subject: [PATCH] Update website for new routes (#2704) --- website/src/components/Chat/ChatListItem.tsx | 8 ++++---- website/src/lib/oasst_inference_client.ts | 9 +++------ website/src/lib/routes.ts | 3 +-- website/src/pages/api/chat/hide.ts | 2 +- website/src/pages/api/chat/title.ts | 2 +- website/src/types/Chat.ts | 6 ++++++ 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/website/src/components/Chat/ChatListItem.tsx b/website/src/components/Chat/ChatListItem.tsx index 6ab57d733e..2a30a5d777 100644 --- a/website/src/components/Chat/ChatListItem.tsx +++ b/website/src/components/Chat/ChatListItem.tsx @@ -33,13 +33,13 @@ export const ChatListItem = ({ }, }); const { trigger: updateChatTitle, isMutating: isUpdatingTitle } = useSWRMutation( - API_ROUTES.UPDATE_CHAT_TITLE(chat.id), + API_ROUTES.UPDATE_CHAT(chat.id), put ); const handleConfirmEdit = useCallback(async () => { const title = inputRef.current?.value.trim(); if (!title) return; - await updateChatTitle({ title, chat_id: chat.id }); + await updateChatTitle({ chat_id: chat.id, title }); setIsEditing.off(); onUpdateTitle({ chatId: chat.id, title }); }, [chat.id, onUpdateTitle, setIsEditing, updateChatTitle]); @@ -145,10 +145,10 @@ const EditChatButton = ({ onClick }: { onClick: () => void }) => { }; const HideChatButton = ({ chatId, onHide }: { chatId: string; onHide?: (params: { chatId: string }) => void }) => { - const { trigger: triggerHide } = useSWRMutation(API_ROUTES.HIDE_CHAT(chatId), put); + const { trigger: triggerHide } = useSWRMutation(API_ROUTES.UPDATE_CHAT(chatId), put); const onClick = useCallback(async () => { - await triggerHide({ chat_id: chatId }); + await triggerHide({ chat_id: chatId, hidden: true }); onHide?.({ chatId }); }, [onHide, triggerHide, chatId]); diff --git a/website/src/lib/oasst_inference_client.ts b/website/src/lib/oasst_inference_client.ts index 854f22464a..34c68cbf0e 100644 --- a/website/src/lib/oasst_inference_client.ts +++ b/website/src/lib/oasst_inference_client.ts @@ -6,6 +6,7 @@ import { InferenceMessage, InferencePostAssistantMessageParams, InferencePostPrompterMessageParams, + InferenceUpdateChatParams, ModelInfo, TrustedClient, } from "src/types/Chat"; @@ -96,12 +97,8 @@ export class OasstInferenceClient { return this.request("/configs/model_configs"); } - update_chat_title({ chat_id, title }: { chat_id: string; title: string }) { - return this.request(`/chats/${chat_id}/title`, { method: "PUT", data: { title } }); - } - - hide_chat({ chat_id }: { chat_id: string }) { - return this.request(`/chats/${chat_id}/hide`, { method: "PUT", data: { hidden: true } }); + update_chat({ chat_id, ...data }: InferenceUpdateChatParams) { + return this.request(`/chats/${chat_id}`, { method: "PUT", data: data }); } delete_account() { diff --git a/website/src/lib/routes.ts b/website/src/lib/routes.ts index 2ad591112c..3e0eeedcf1 100644 --- a/website/src/lib/routes.ts +++ b/website/src/lib/routes.ts @@ -60,6 +60,5 @@ export const API_ROUTES = { STREAM_CHAT_MESSAGE: (chat_id: string, message_id: string) => createRoute(`/api/chat/events`, { chat_id, message_id }), GET_CHAT_MODELS: "/api/chat/models", - UPDATE_CHAT_TITLE: (id: string) => `/api/chat/title`, - HIDE_CHAT: (id: string) => `/api/chat/hide`, + UPDATE_CHAT: (id: string) => `/api/chat`, }; diff --git a/website/src/pages/api/chat/hide.ts b/website/src/pages/api/chat/hide.ts index 9b3a628799..ee92debe21 100644 --- a/website/src/pages/api/chat/hide.ts +++ b/website/src/pages/api/chat/hide.ts @@ -9,7 +9,7 @@ const handler = withoutRole("banned", async (req, res, token) => { const client = createInferenceClient(token); const { chat_id } = req.body as { chat_id: string }; - await client.hide_chat({ chat_id }); + await client.update_chat({ chat_id, hidden: true }); res.status(200).end(); }); diff --git a/website/src/pages/api/chat/title.ts b/website/src/pages/api/chat/title.ts index 7491e62ed2..c89f19ae61 100644 --- a/website/src/pages/api/chat/title.ts +++ b/website/src/pages/api/chat/title.ts @@ -9,7 +9,7 @@ const handler = withoutRole("banned", async (req, res, token) => { const client = createInferenceClient(token); const { chat_id, title } = req.body as { chat_id: string; title: string }; - await client.update_chat_title({ chat_id, title }); + await client.update_chat({ chat_id, title }); res.status(200).end(); }); diff --git a/website/src/types/Chat.ts b/website/src/types/Chat.ts index 2b2a868d97..639e54c4bf 100644 --- a/website/src/types/Chat.ts +++ b/website/src/types/Chat.ts @@ -115,3 +115,9 @@ export interface InferencePostAssistantMessageParams { model_config_name: string; sampling_parameters: SamplingParameters; } + +export interface InferenceUpdateChatParams { + chat_id: string; + title?: string; + hidden?: boolean; +}