Download web/src/assistant/turnClient.ts from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/assistant/turnClient.ts
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/assistant/turnClient.ts
-
curl -L -o turnClient.ts https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/assistant/turnClient.ts
1.28 kB
| import { call, type ChatResult, type Result } from "../query/queryApi"; | |
| import type { ChatStreamRequest } from "./streamClient"; | |
| type JoinedTurn = { status: "joined" }; | |
| /** Keep C4 acknowledgements intact when the C3 stream is unavailable. */ | |
| export async function submitChat(body: ChatStreamRequest, signal?: AbortSignal): Promise<Result<ChatResult | JoinedTurn>> { | |
| const result = await call("/query/chat", { | |
| method: "POST", signal, headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), | |
| }, (body: unknown) => body as Partial<ChatResult> | JoinedTurn | null); | |
| if (!result.ok) return result; | |
| const reply = result.value; | |
| if (reply && "status" in reply && reply.status === "joined") return { ok: true, value: reply }; | |
| if (!reply || !("message" in reply) || !reply.message?.id || !reply.userMessage?.id | |
| || !Array.isArray(reply.citations)) return { ok: false, status: 502, message: "This answer could not be loaded." }; | |
| return { ok: true, value: reply as ChatResult }; | |
| } | |
| /** Stop the caller's running turn through C4. */ | |
| export function stopTurn(): Promise<Result<unknown>> { | |
| return call("/assistant/stop", { | |
| method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), | |
| }, (body: unknown) => body); | |
| } | |