mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-18 08:02:03 +03:00
9464707d40
* feat: add chat_id to upload and crawl payload * feat(chat): return chat_history_with_notifications * feat: explicit notification status on create * feat: handle notifications in frontend * feat: delete chat notifications on chat delete request
73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
import { AxiosInstance } from "axios";
|
|
|
|
import {
|
|
ChatEntity,
|
|
ChatHistory,
|
|
ChatItem,
|
|
ChatQuestion,
|
|
} from "@/app/chat/[chatId]/types";
|
|
|
|
export const createChat = async (
|
|
name: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity> => {
|
|
const createdChat = (
|
|
await axiosInstance.post<ChatEntity>("/chat", { name: name })
|
|
).data;
|
|
|
|
return createdChat;
|
|
};
|
|
|
|
export const getChats = async (
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity[]> => {
|
|
const response = await axiosInstance.get<{
|
|
chats: ChatEntity[];
|
|
}>(`/chat`);
|
|
|
|
return response.data.chats;
|
|
};
|
|
|
|
export const deleteChat = async (
|
|
chatId: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<void> => {
|
|
await axiosInstance.delete(`/chat/${chatId}`);
|
|
};
|
|
|
|
export type AddQuestionParams = {
|
|
chatId: string;
|
|
chatQuestion: ChatQuestion;
|
|
brainId: string;
|
|
};
|
|
|
|
export const addQuestion = async (
|
|
{ chatId, chatQuestion, brainId }: AddQuestionParams,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatHistory> => {
|
|
const response = await axiosInstance.post<ChatHistory>(
|
|
`/chat/${chatId}/question?brain_id=${brainId}`,
|
|
chatQuestion
|
|
);
|
|
|
|
return response.data;
|
|
};
|
|
|
|
export const getHistory = async (
|
|
chatId: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatItem[]> =>
|
|
(await axiosInstance.get<ChatItem[]>(`/chat/${chatId}/history`)).data;
|
|
|
|
export type ChatUpdatableProperties = {
|
|
chat_name?: string;
|
|
};
|
|
export const updateChat = async (
|
|
chatId: string,
|
|
chat: ChatUpdatableProperties,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity> => {
|
|
return (await axiosInstance.put<ChatEntity>(`/chat/${chatId}/metadata`, chat))
|
|
.data;
|
|
};
|