mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-17 11:21:35 +03:00
59fe7b089b
* feat(chat): use openai function for answer (backend) * feat(chat): use openai function for answer (frontend) * chore: refacto BrainPicking * feat: update chat creation logic * feat: simplify chat system logic * feat: set default method to gpt-3.5-turbo-0613 * feat: use user own openai key * feat(chat): slightly improve prompts * feat: add global error interceptor * feat: remove unused endpoints * docs: update chat system doc * chore(linter): add unused import remove config * feat: improve dx * feat: improve OpenAiFunctionBasedAnswerGenerator prompt
41 lines
963 B
TypeScript
41 lines
963 B
TypeScript
import { useAxios } from "@/lib/hooks";
|
|
|
|
import { ChatEntity, ChatHistory, ChatQuestion } from "../types";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useChatService = () => {
|
|
const { axiosInstance } = useAxios();
|
|
|
|
const createChat = async ({ name }: { name: string }) => {
|
|
return axiosInstance.post<ChatEntity>(`/chat`, { name });
|
|
};
|
|
|
|
const getChatHistory = async (chatId: string | undefined) => {
|
|
if (chatId === undefined) {
|
|
return [];
|
|
}
|
|
const rep = (
|
|
await axiosInstance.get<ChatHistory[]>(`/chat/${chatId}/history`)
|
|
).data;
|
|
|
|
return rep;
|
|
};
|
|
const addQuestion = async (
|
|
chatId: string,
|
|
chatQuestion: ChatQuestion
|
|
): Promise<ChatHistory> => {
|
|
return (
|
|
await axiosInstance.post<ChatHistory>(
|
|
`/chat/${chatId}/question`,
|
|
chatQuestion
|
|
)
|
|
).data;
|
|
};
|
|
|
|
return {
|
|
createChat,
|
|
getChatHistory,
|
|
addQuestion,
|
|
};
|
|
};
|