import { get, post } from "./http"; import { Message, messageToJson } from "./types"; export async function sendChat(chatHistory: Message[], lastUserQuery: Message) { // converting the chathistory to json const chatJson = chatHistory.map((message) => messageToJson(message)); const data = { chat_history: chatJson, message: lastUserQuery.content, }; return post("/chat", data); } export async function getTranscripts(filename: string) { const data = { file_name: filename }; const response = await post("/transcript", data); if (!response.ok || !response.body) { return null; } const response_json = await response.json(); if (!response_json) { return null; } return response_json; } export async function getNameForNewChat( userQuery: string, assistantResponse: string ): Promise { const data = { user_query: userQuery, assistant_response: assistantResponse, }; const response = await post("/generate_name", data); if (!response.ok || !response.body) { return null; } const response_json = await response.json(); if (!response_json) { return null; } return response_json; }