mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-14 05:05:09 +03:00
d51d4a1e90
* refactor: add addQuestion to chat api * test(chat): add unit tests to addQuestion
54 lines
1.1 KiB
TypeScript
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;
|
|
};
|