Download web/src/assistant/dockClient.ts from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 2.23 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/assistant/dockClient.ts
- Command line
-
hf download hf://spaces/fsanyoto/loopable@9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/assistant/dockClient.ts
-
curl -L -o dockClient.ts https://huggingface.co/spaces/fsanyoto/loopable/resolve/9291c0100f4e7b8da2efcbbf1ebdea72ee1663e7/web/src/assistant/dockClient.ts
2.23 kB
| import { call as queryRequest } from "../query/queryApi"; | |
| import type { ChatResult, Result } from "../query/queryApi"; | |
| import type { AssistantLogTurn } from "./AssistantPage"; | |
| export { refusalSentence } from "../query/queryApi"; | |
| export type DockSurface = "data" | "sheet" | "automation" | "field"; | |
| export interface DockContext { | |
| surface: DockSurface; | |
| database?: string; | |
| databases?: string[]; | |
| } | |
| export interface DockHistory { turns: AssistantLogTurn[]; hasMore: boolean; } | |
| export type DockTurnInput = DockContext & { question: string; model?: string }; | |
| export interface DockExchange { | |
| question: string; | |
| answer: string; | |
| context: DockContext; | |
| } | |
| export interface DockExchangeReceipt { | |
| ok: true; | |
| userTurnId: string; | |
| assistantTurnId: string; | |
| } | |
| export type DockRequest = typeof queryRequest; | |
| export function fetchDockHistory(request: DockRequest = queryRequest): Promise<Result<DockHistory>> { | |
| return request("/assistant/log?limit=50", {}, (body) => body as DockHistory); | |
| } | |
| export function sendDockTurn(input: DockTurnInput, request: DockRequest = queryRequest): Promise<Result<ChatResult>> { | |
| const sources = [...new Set((input.databases || []).filter(Boolean))]; | |
| const database = sources.length | |
| ? (sources.includes(input.database || "") ? input.database! : sources[0]) | |
| : input.database || ""; | |
| if (!sources.length && database) sources.push(database); | |
| const dock: DockContext = { surface: input.surface, | |
| ...(database ? { database } : {}), | |
| ...(input.databases ? { databases: sources } : {}), | |
| }; | |
| return request("/query/chat", { | |
| method: "POST", headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ question: input.question, database, sources, model: input.model || "auto", dock }), | |
| }, (body) => body as ChatResult); | |
| } | |
| export function logExchange(exchange: DockExchange, request: DockRequest = queryRequest): Promise<Result<DockExchangeReceipt>> { | |
| return request("/assistant/exchange", { | |
| method: "POST", headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify(exchange), | |
| }, (body) => body as DockExchangeReceipt); | |
| } | |
| export const dockClient = { fetchDockHistory, sendDockTurn, logExchange }; | |
| export type DockClient = typeof dockClient; | |