@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
53 lines (52 loc) • 2.88 kB
TypeScript
import type { DecisionError, DecisionPreparedMedia, DecisionState, NeurolinkCredentials } from "../types/index.js";
import { SystemOneDecisionProvider } from "./systemOneDecision.js";
/**
* Cloudflare Clef — the `decide` inference type only.
*
* `@cf/cloudflare/clef` (27B) and `@cf/cloudflare/clef-flash` (9B) answer the
* same typed `noul` / `choice` / `score` questions as the other decision
* providers, follow the System One wire, and read images. They are reached
* through the Workers AI REST API, which wraps every answer in Cloudflare's own
* `{ result, success, errors }` envelope and puts the model in the URL path.
*
* The token and account id are the ones the Cloudflare Workers AI text provider
* reads (`CLOUDFLARE_API_KEY`, `CLOUDFLARE_ACCOUNT_ID`), so a host that has
* configured that provider has also configured this one.
*
* The Workers AI endpoint ignores text past about 2,048 tokens, far below
* the documented 64K (hosted service or model: unknown). See `decisionLimits`
* on the descriptor for the measured figures.
*
* @see https://developers.cloudflare.com/workers-ai/models/clef/
*/
export declare class CloudflareClefProvider extends SystemOneDecisionProvider {
private readonly apiKey;
private readonly accountId;
private readonly baseURL;
constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["cloudflareClef"]);
protected getDefaultModel(): string;
protected vendorLabel(): string;
protected vendorDisplayName(): string;
protected decisionApiKey(): string;
protected missingKeyMessage(): string;
protected missingConfigMessage(): string | undefined;
/** The model is part of the path, so the endpoint depends on the model asked for. */
protected decisionEndpoint(model: string): string;
protected decisionHeaders(): Record<string, string>;
/**
* Images travel in their own `images` array, as `data:` URLs, placed before
* the state by the server. `model` is sent although the path already names
* it: the API documents it as required, and refuses a body whose `model`
* differs from the path.
*/
protected buildDecisionBody(state: DecisionState, questions: Record<string, Record<string, unknown>>, model: string, media?: DecisionPreparedMedia): Record<string, unknown>;
/** A success is `{ result: { model, answers, usage }, success: true }`. */
protected readDecisionPayload(payload: unknown): unknown;
protected parseDecisionError(status: number, payload: unknown, requestId: string | undefined): DecisionError;
/**
* `cf-ai-req-id` is on every answer that reached the model, success or
* refusal. A 401 and a wrong-path 400 never reach it, so they carry only the
* edge's `cf-ray`.
*/
protected readRequestId(headers: Headers): string | undefined;
}