@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
77 lines (76 loc) • 3.66 kB
TypeScript
import type { AIProviderName } from "../../constants/enums.js";
import type { EmbedInput, EnhancedGenerateResult, NeurolinkCredentials, OpenAICompatStreamLifecycleListeners, TextGenerationOptions } from "../../types/index.js";
import { OpenAIChatCompletionsProvider } from "../openaiChatCompletionsBase.js";
/**
* OpenAI Provider — direct HTTP, no AI SDK.
*
* OpenAI chat completions at api.openai.com/v1. All request / stream /
* tool-loop orchestration lives in `OpenAIChatCompletionsProvider`; this
* class adds:
* - OTel span wrap with cost (`onStreamStart`)
* - Native `/v1/embeddings` (`embed` / `embedMany`)
* - Image generation via `/v1/images/generations` (`executeImageGeneration`)
* - OpenAI-specific error mapping (`formatProviderError`)
*
* @see https://platform.openai.com/docs/api-reference
*/
export declare class OpenAIProvider extends OpenAIChatCompletionsProvider {
constructor(modelName?: string, sdk?: unknown, _region?: string, credentials?: NeurolinkCredentials["openai"]);
/**
* OpenAI natively supports `response_format: json_schema` together with
* tool calling in one request, so structured output stays wire-enforced
* mid-loop instead of deferring to post-hoc coercion.
*/
protected suppressResponseFormatWithTools(): boolean;
protected getProviderName(): AIProviderName;
protected getDefaultModel(): string;
formatProviderError(error: unknown): Error;
/**
* Wrap the stream in an OTel span to capture provider-level latency,
* token usage, finish reason, and cost. Mirrors the pre-migration
* `streamText`-span behaviour.
*/
protected onStreamStart(modelId: string): OpenAICompatStreamLifecycleListeners | undefined;
/**
* Default embedding model, overridable via OPENAI_EMBEDDING_MODEL env var.
*/
protected getDefaultEmbeddingModel(): string;
/**
* Generate an embedding for a single text input via native /v1/embeddings.
*
* @param input - The text to embed (string or EmbedInput)
* @param modelName - The embedding model to use (default: text-embedding-3-small)
* @returns Promise resolving to the embedding vector
*/
embed(input: string | EmbedInput, modelName?: string): Promise<number[]>;
/**
* Generate embeddings for multiple texts in a single batch via native /v1/embeddings.
*
* @param texts - The texts to embed
* @param modelName - The embedding model to use (default: text-embedding-3-small)
* @returns Promise resolving to an array of embedding vectors
*/
embedMany(texts: string[], modelName?: string): Promise<number[][]>;
private callEmbeddings;
/**
* Image generation via the OpenAI Images API (`/v1/images/generations`).
*
* Supports `gpt-image-1`, `dall-e-3`, and `dall-e-2`. The three models
* differ in which body params they accept:
*
* - `gpt-image-1` returns base64 by default; does NOT accept `response_format`.
* - `dall-e-3` / `dall-e-2` accept `response_format: "b64_json"` to get base64.
* - `dall-e-2` does NOT accept `quality` / `style`.
*
* The model is taken from `options.model || this.modelName`.
*
* @see https://platform.openai.com/docs/api-reference/images/create
*/
protected executeImageGeneration(options: TextGenerationOptions): Promise<EnhancedGenerateResult>;
/**
* Map a NeuroLink-style aspect ratio (e.g. "16:9") to the OpenAI
* `size` parameter accepted by the active image model. Falls back to
* the per-model square default when the ratio is unknown.
*/
private aspectRatioToOpenAISize;
}