mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-17 23:51:51 +03:00
da8e7513e6
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate): --------- Co-authored-by: Stan Girard <girard.stanislas@gmail.com>
92 lines
2.0 KiB
TypeScript
92 lines
2.0 KiB
TypeScript
import { AxiosInstance } from "axios";
|
|
|
|
import {
|
|
ChatEntity,
|
|
ChatItem,
|
|
ChatMessage,
|
|
ChatQuestion,
|
|
} from "@/app/chat/[chatId]/types";
|
|
|
|
export type ChatUpdatableProperties = {
|
|
chat_name?: string;
|
|
};
|
|
|
|
export type ChatMessageUpdatableProperties = {
|
|
thumbs?: boolean | null;
|
|
};
|
|
|
|
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<ChatMessage> => {
|
|
const response = await axiosInstance.post<ChatMessage>(
|
|
`/chat/${chatId}/question?brain_id=${brainId}`,
|
|
chatQuestion
|
|
);
|
|
|
|
return response.data;
|
|
};
|
|
|
|
export const getChatItems = async (
|
|
chatId: string,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatItem[]> =>
|
|
(await axiosInstance.get<ChatItem[]>(`/chat/${chatId}/history`)).data;
|
|
|
|
export const updateChat = async (
|
|
chatId: string,
|
|
chat: ChatUpdatableProperties,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatEntity> => {
|
|
return (await axiosInstance.put<ChatEntity>(`/chat/${chatId}/metadata`, chat))
|
|
.data;
|
|
};
|
|
|
|
export const updateChatMessage = async (
|
|
chatId: string,
|
|
messageId: string,
|
|
chatMessageUpdatableProperties: ChatMessageUpdatableProperties,
|
|
axiosInstance: AxiosInstance
|
|
): Promise<ChatItem> => {
|
|
return (
|
|
await axiosInstance.put<ChatItem>(
|
|
`/chat/${chatId}/${messageId}`,
|
|
chatMessageUpdatableProperties
|
|
)
|
|
).data;
|
|
};
|