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

78 lines (77 loc) • 3.94 kB
import { AIProviderName } from "../../constants/enums.js"; import type { NeurolinkCredentials, OpenAICompatBuildBodyArgs, OpenAICompatChatRequest } from "../../types/index.js"; import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js"; /** * Decide whether a NIM 400 response body is a rejection of the named * field (as opposed to an unrelated 400 that happens to mention the * field name — e.g. when the user's prompt is echoed back inside the * error envelope). * * A rejection requires both: * - the field name appears in the body, and * - a rejection keyword (`unsupported`, `not supported`, `unknown`, * `invalid`, `unrecognized`, `does not support`) appears within * 80 characters of any occurrence. * * The 80-character window is loose enough to absorb NIM's "Unsupported * argument: `chat_template`" framing and tight enough that a 1KB error * body mentioning the field once in a code sample plus an unrelated * "invalid" elsewhere won't trigger a strip. */ declare const isNimFieldRejection: (body: string, field: string) => boolean; /** * Strip an offending field from a JSON request body and return the rebuilt * stringified body. Returns `null` if the body isn't JSON-parseable or the * field isn't present (signal: nothing to retry). */ declare const stripFieldFromJsonBody: (body: string, field: string) => string | null; /** * NVIDIA NIM Provider — native HTTP+SSE, no AI SDK. * * Wraps NVIDIA's hosted (or self-hosted) inference endpoints. * Passes NIM-specific extras (top_k, min_p, repetition_penalty, min_tokens, * chat_template, chat_template_kwargs.reasoning_budget) to the wire via the * `extraBody` channel of adjustBuildBodyOptions, and retries once without * `chat_template`/`reasoning_budget` when a model server rejects them with a * 400 (adjustBodyAfter400 — applies on both generate and stream paths). * reasoning_content is surfaced automatically by the native base client * (streamed as `{ content: "", reasoning }` chunks; `result.reasoning` on * the non-streaming path); all other behavior is preserved. * * @see https://docs.api.nvidia.com/nim/reference/ */ export declare class NvidiaNimProvider extends OpenAIChatCompletionsProvider { constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["nvidiaNim"]); protected getProviderName(): AIProviderName; protected getDefaultModel(): string; /** * Inject NIM-specific body fields (top_k, min_p, repetition_penalty, * min_tokens, chat_template, chat_template_kwargs) into the wire body. * * The base passes the full StreamOptions as `opts` at runtime (typed * narrowly as OpenAICompatBuildBodyArgs["options"] for standard fields). * We access thinkingLevel via an indexed-access cast since the runtime * value is the full StreamOptions object. */ protected adjustBuildBodyOptions(_modelId: string, opts: OpenAICompatBuildBodyArgs["options"]): OpenAICompatBuildBodyArgs["options"] & Record<string, unknown>; /** * One-shot 400 retry (base hook): some NIM model servers reject * `chat_template` or `chat_template_kwargs.reasoning_budget` with a 400 * naming the field. Strip the rejected field(s) and let the base retry * once, restoring the pre-migration fetch-level behavior. Returns * undefined for unrelated 400s so they propagate unchanged. */ protected adjustBodyAfter400(body: OpenAICompatChatRequest, error: Error & { statusCode?: number; responseBody?: string; }): OpenAICompatChatRequest | undefined; protected formatProviderError(error: unknown): Error; validateConfiguration(): Promise<boolean>; getConfiguration(): { provider: AIProviderName; model: string; defaultModel: string; baseURL: string; }; } export { isNimFieldRejection, stripFieldFromJsonBody };