UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

52 lines (51 loc) • 1.42 kB
export const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v); export const asNumber = (v) => typeof v === "number" && Number.isFinite(v) ? v : undefined; export const asNumberMap = (v) => { if (!isRecord(v)) { return undefined; } const out = {}; for (const [k, raw] of Object.entries(v)) { const n = asNumber(raw); if (n === undefined) { return undefined; } out[k] = n; } return out; }; export const asStringMap = (v) => { if (!isRecord(v)) { return undefined; } const out = {}; for (const [k, raw] of Object.entries(v)) { if (typeof raw !== "string") { return undefined; } out[k] = raw; } return out; }; /** * A map whose values are shown as text: a string as is, anything else a JSON * value can hold as its JSON text. A score legend echoes each level as the * caller gave it, and a level may be a number or an object. */ export const asTextMap = (v) => { if (!isRecord(v)) { return undefined; } const out = {}; for (const [k, raw] of Object.entries(v)) { if (typeof raw === "string") { out[k] = raw; continue; } if (raw === undefined || typeof raw === "function") { return undefined; } out[k] = JSON.stringify(raw); } return out; };