@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
61 lines (60 loc) • 3.2 kB
TypeScript
import { AIProviderName } from "../../constants/enums.js";
import type { NeurolinkCredentials, OpenAICompatBuildBodyArgs, OpenAICompatChatRequest } from "../../types/index.js";
import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js";
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: "reasoning_budget" | "chat_template") => 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 };