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

47 lines (46 loc) • 2.33 kB
/** * Replicate Prediction Lifecycle * * Shared async-job helpers used by every Replicate-backed handler. Submits * a prediction, polls until terminal status, downloads the binary output. * * Usage pattern (for handlers — LLM, video, avatar, music): * * const auth = getReplicateAuth(credentials); * if (!auth) throw new XxxError({ code: PROVIDER_NOT_CONFIGURED, ... }); * const prediction = await predict(auth, { model, input }); * const buffer = await downloadPredictionOutput(prediction); * * @module adapters/replicate/predictionLifecycle */ import type { ReplicateAuth, ReplicateCreatePredictionInput, ReplicatePollOptions, ReplicatePrediction } from "../../types/index.js"; /** * Submit a Replicate prediction. Uses `Prefer: wait=60` so quick * predictions complete in the initial POST and skip polling entirely. */ export declare function createPrediction(auth: ReplicateAuth, input: ReplicateCreatePredictionInput, sleep?: (delayMs: number) => Promise<void>): Promise<ReplicatePrediction>; /** * Poll a Replicate prediction until it reaches a terminal status * (succeeded / failed / canceled) or the total timeout elapses. */ export declare function pollPrediction(auth: ReplicateAuth, predictionId: string, options?: ReplicatePollOptions): Promise<ReplicatePrediction>; /** * Submit + poll. Combines `createPrediction` + `pollPrediction`. * * Uses `Prefer: wait=60` in the submit call so short jobs complete in the * initial POST and bypass polling entirely. */ export declare function predict(auth: ReplicateAuth, input: ReplicateCreatePredictionInput, options?: ReplicatePollOptions): Promise<ReplicatePrediction>; /** * Download a Replicate prediction's binary output. * * Replicate models return either a single URL string or an array of URL * strings (multi-output models). For models that return base64 directly, * use a model-specific helper instead. * * @param prediction The completed prediction to download. * @param maxBytes Maximum bytes allowed. Defaults to {@link MAX_VIDEO_BYTES} * (256 MiB). Pass {@link MAX_AUDIO_BYTES} for music/TTS * outputs or {@link MAX_IMAGE_BYTES} for image outputs. */ export declare function downloadPredictionOutput(prediction: ReplicatePrediction, maxBytes?: number): Promise<Buffer>;