@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
195 lines (194 loc) • 6.22 kB
TypeScript
/**
* SageMaker Language Model Implementation
*
* This module implements the LanguageModel interface for Amazon SageMaker
* integration with the Vercel AI SDK.
*/
import type { ConnectivityResult, SageMakerAsLanguageModel, SageMakerConfig, SageMakerModelConfig } from "../../types/index.js";
/**
* SageMaker Language Model implementing LanguageModel interface
*
* Token Limit Behavior:
* - When maxTokens is undefined, SageMaker uses the model's default token limits
* - When maxTokens is specified, it sets max_new_tokens parameter explicitly
* - This aligns with the unlimited-by-default token policy across all providers
*/
export declare class SageMakerLanguageModel implements SageMakerAsLanguageModel {
/**
* Specification version for the AI SDK LanguageModel interface.
* Uses "v2" for structural compatibility with AI SDK v6's `LanguageModelV2`.
* The AI SDK checks this field to determine which interface version to use.
*/
readonly specificationVersion: "v2";
readonly provider = "sagemaker";
readonly modelId: string;
readonly supportsStreaming = true;
readonly defaultObjectGenerationMode: "json";
/**
* Supported URL patterns by media type.
* SageMaker endpoints do not natively download URLs, so this is empty.
* Required by the LanguageModelV2 interface.
*/
readonly supportedUrls: Record<string, RegExp[]>;
private client;
private config;
private modelConfig;
constructor(modelId: string, config: SageMakerConfig, modelConfig: SageMakerModelConfig);
/**
* Generate text synchronously using SageMaker endpoint
*/
doGenerate(options: Record<string, unknown>): Promise<{
text?: string;
reasoning?: string | Array<{
type: "text";
text: string;
signature?: string;
} | {
type: "redacted";
data: string;
}>;
files?: Array<{
data: string | Uint8Array;
mimeType: string;
}>;
logprobs?: Array<{
token: string;
logprob: number;
topLogprobs: Array<{
token: string;
logprob: number;
}>;
}>;
usage: {
inputTokens: number;
outputTokens: number;
totalTokens?: number;
};
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "unknown";
warnings?: Array<{
type: "other";
message: string;
}>;
rawCall: {
rawPrompt: unknown;
rawSettings: Record<string, unknown>;
};
rawResponse?: {
headers?: Record<string, string>;
};
request?: {
body?: string;
};
}>;
/**
* Generate text with streaming using SageMaker endpoint
*/
doStream(options: Record<string, unknown>): Promise<{
stream: ReadableStream<Record<string, unknown>>;
rawCall: {
rawPrompt: unknown;
rawSettings: Record<string, unknown>;
};
rawResponse?: {
headers?: Record<string, string>;
};
request?: {
body?: string;
};
warnings?: Array<{
type: "other";
message: string;
}>;
}>;
/**
* Convert AI SDK options to SageMaker request format
*/
private convertToSageMakerRequest;
/**
* Convert Vercel AI SDK tools to SageMaker format
*/
private convertToolsToSageMakerFormat;
/**
* Convert Vercel AI SDK tool choice to SageMaker format
*/
private convertToolChoiceToSageMakerFormat;
/**
* Convert Vercel AI SDK response format to SageMaker format (Phase 4)
*/
private convertResponseFormatToSageMakerFormat;
/**
* Extract text content from AI SDK prompt format
*/
private extractPromptText;
/**
* Extract generated text from SageMaker response
*/
private extractTextFromResponse;
/**
* Extract tool calls from SageMaker response (Phase 4)
*/
private extractToolCallsFromResponse;
/**
* Map SageMaker finish reason to standardized format
*/
private mapSageMakerFinishReason;
/**
* Get model configuration summary for debugging
*/
getModelInfo(): {
modelId: string;
provider: string;
specificationVersion: "v2";
endpointName: string;
modelType: "huggingface" | "mistral" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
region: string;
};
/**
* Test basic connectivity to the SageMaker endpoint
*/
testConnectivity(): Promise<ConnectivityResult>;
/**
* Batch inference support (Phase 4)
* Process multiple prompts in a single request for efficiency
*/
doBatchGenerate(prompts: string[], options?: {
maxTokens?: number;
temperature?: number;
topP?: number;
}): Promise<Array<{
text: string;
usage: {
promptTokens: number;
completionTokens: number;
total: number;
};
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "unknown";
}>>;
/**
* Process prompts in parallel with advanced concurrency control and error handling
*/
private processPromptsInParallel;
/**
* Enhanced model information with batch capabilities
*/
getModelCapabilities(): {
capabilities: {
streaming: boolean;
toolCalling: boolean;
structuredOutput: boolean;
batchInference: boolean;
supportedResponseFormats: string[];
supportedToolTypes: string[];
maxBatchSize: number;
adaptiveConcurrency: boolean;
errorRecovery: boolean;
};
modelId: string;
provider: string;
specificationVersion: "v2";
endpointName: string;
modelType: "huggingface" | "mistral" | "custom" | "claude" | "llama" | "jumpstart" | undefined;
region: string;
};
}
export default SageMakerLanguageModel;