File size: 1,180 Bytes
e454383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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<string | null> {
  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;
}