Download src/lib/api.ts from IOE-IFAD/test: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/IOE-IFAD/test/resolve/main/src/lib/api.ts
- Command line
-
hf download hf://spaces/IOE-IFAD/test/src/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/IOE-IFAD/test/resolve/main/src/lib/api.ts
1.18 kB
| 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; | |
| } | |