Skip to content

Commit

Permalink
Update website for new routes (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
olliestanley authored Apr 18, 2023
1 parent e8510c3 commit a640bed
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions website/src/components/Chat/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);

Expand Down
9 changes: 3 additions & 6 deletions website/src/lib/oasst_inference_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
InferenceMessage,
InferencePostAssistantMessageParams,
InferencePostPrompterMessageParams,
InferenceUpdateChatParams,
ModelInfo,
TrustedClient,
} from "src/types/Chat";
Expand Down Expand Up @@ -96,12 +97,8 @@ export class OasstInferenceClient {
return this.request<ModelInfo[]>("/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() {
Expand Down
3 changes: 1 addition & 2 deletions website/src/lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
};
2 changes: 1 addition & 1 deletion website/src/pages/api/chat/hide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/api/chat/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
6 changes: 6 additions & 0 deletions website/src/types/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ export interface InferencePostAssistantMessageParams {
model_config_name: string;
sampling_parameters: SamplingParameters;
}

export interface InferenceUpdateChatParams {
chat_id: string;
title?: string;
hidden?: boolean;
}

0 comments on commit a640bed

Please sign in to comment.