quivr/frontend/lib/api/chat/chat.ts
Mamadou DICKO d51d4a1e90
Frontend/test/chat 3 (#517)
* refactor: add addQuestion to chat api

* test(chat): add unit tests to addQuestion
2023-07-05 13:39:07 +02:00

54 lines
1.1 KiB
TypeScript

import { AxiosInstance } from "axios";
import {
ChatEntity,
ChatHistory,
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;
};