UNPKG

@langchain/community

Version:
1 lines • 6.25 kB
{"version":3,"file":"sagemaker_endpoint.d.ts","names":["SageMakerRuntimeClient","SageMakerRuntimeClientConfig","CallbackManagerForLLMRun","GenerationChunk","BaseLLMCallOptions","BaseLLMParams","LLM","BaseSageMakerContentHandler","InputType","OutputType","Record","Uint8Array","Promise","SageMakerLLMContentHandler","SageMakerEndpointInput","SageMakerEndpoint","AsyncGenerator"],"sources":["../../src/llms/sagemaker_endpoint.d.ts"],"sourcesContent":["import { SageMakerRuntimeClient, SageMakerRuntimeClientConfig } from \"@aws-sdk/client-sagemaker-runtime\";\nimport { CallbackManagerForLLMRun } from \"@langchain/core/callbacks/manager\";\nimport { GenerationChunk } from \"@langchain/core/outputs\";\nimport { type BaseLLMCallOptions, type BaseLLMParams, LLM } from \"@langchain/core/language_models/llms\";\n/**\n * A handler class to transform input from LLM to a format that SageMaker\n * endpoint expects. Similarily, the class also handles transforming output from\n * the SageMaker endpoint to a format that LLM class expects.\n *\n * Example:\n * ```\n * class ContentHandler implements ContentHandlerBase<string, string> {\n * contentType = \"application/json\"\n * accepts = \"application/json\"\n *\n * transformInput(prompt: string, modelKwargs: Record<string, unknown>) {\n * const inputString = JSON.stringify({\n * prompt,\n * ...modelKwargs\n * })\n * return Buffer.from(inputString)\n * }\n *\n * transformOutput(output: Uint8Array) {\n * const responseJson = JSON.parse(Buffer.from(output).toString(\"utf-8\"))\n * return responseJson[0].generated_text\n * }\n *\n * }\n * ```\n */\nexport declare abstract class BaseSageMakerContentHandler<InputType, OutputType> {\n contentType: string;\n accepts: string;\n /**\n * Transforms the prompt and model arguments into a specific format for sending to SageMaker.\n * @param {InputType} prompt The prompt to be transformed.\n * @param {Record<string, unknown>} modelKwargs Additional arguments.\n * @returns {Promise<Uint8Array>} A promise that resolves to the formatted data for sending.\n */\n abstract transformInput(prompt: InputType, modelKwargs: Record<string, unknown>): Promise<Uint8Array>;\n /**\n * Transforms SageMaker output into a desired format.\n * @param {Uint8Array} output The raw output from SageMaker.\n * @returns {Promise<OutputType>} A promise that resolves to the transformed data.\n */\n abstract transformOutput(output: Uint8Array): Promise<OutputType>;\n}\nexport type SageMakerLLMContentHandler = BaseSageMakerContentHandler<string, string>;\n/**\n * The SageMakerEndpointInput interface defines the input parameters for\n * the SageMakerEndpoint class, which includes the endpoint name, client\n * options for the SageMaker client, the content handler, and optional\n * keyword arguments for the model and the endpoint.\n */\nexport interface SageMakerEndpointInput extends BaseLLMParams {\n /**\n * The name of the endpoint from the deployed SageMaker model. Must be unique\n * within an AWS Region.\n */\n endpointName: string;\n /**\n * Options passed to the SageMaker client.\n */\n clientOptions: SageMakerRuntimeClientConfig;\n /**\n * Key word arguments to pass to the model.\n */\n modelKwargs?: Record<string, unknown>;\n /**\n * Optional attributes passed to the InvokeEndpointCommand\n */\n endpointKwargs?: Record<string, unknown>;\n /**\n * The content handler class that provides an input and output transform\n * functions to handle formats between LLM and the endpoint.\n */\n contentHandler: SageMakerLLMContentHandler;\n streaming?: boolean;\n}\n/**\n * The SageMakerEndpoint class is used to interact with SageMaker\n * Inference Endpoint models. It uses the AWS client for authentication,\n * which automatically loads credentials.\n * If a specific credential profile is to be used, the name of the profile\n * from the ~/.aws/credentials file must be passed. The credentials or\n * roles used should have the required policies to access the SageMaker\n * endpoint.\n */\nexport declare class SageMakerEndpoint extends LLM<BaseLLMCallOptions> {\n lc_serializable: boolean;\n static lc_name(): string;\n get lc_secrets(): {\n [key: string]: string;\n } | undefined;\n endpointName: string;\n modelKwargs?: Record<string, unknown>;\n endpointKwargs?: Record<string, unknown>;\n client: SageMakerRuntimeClient;\n contentHandler: SageMakerLLMContentHandler;\n streaming: boolean;\n constructor(fields: SageMakerEndpointInput);\n _llmType(): string;\n /**\n * Calls the SageMaker endpoint and retrieves the result.\n * @param {string} prompt The input prompt.\n * @param {this[\"ParsedCallOptions\"]} options Parsed call options.\n * @param {CallbackManagerForLLMRun} runManager Optional run manager.\n * @returns {Promise<string>} A promise that resolves to the generated string.\n */\n /** @ignore */\n _call(prompt: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): Promise<string>;\n private streamingCall;\n private noStreamingCall;\n /**\n * Streams response chunks from the SageMaker endpoint.\n * @param {string} prompt The input prompt.\n * @param {this[\"ParsedCallOptions\"]} options Parsed call options.\n * @returns {AsyncGenerator<GenerationChunk>} An asynchronous generator yielding generation chunks.\n */\n _streamResponseChunks(prompt: string, options: this[\"ParsedCallOptions\"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<GenerationChunk>;\n}\n//# sourceMappingURL=sagemaker_endpoint.d.ts.map"],"mappings":";;;;;;;;;AA+BA;;;;;;;;AAeyD;AAEzD;AAOA;;;;;;AAA6D;AAkC7D;;;;;;;;AAsBsGY,uBAhFxEL,2BAgFwEK,CAAAA,SAAAA,EAAAA,UAAAA,CAAAA,CAAAA;EASXV,WAAAA,EAAAA,MAAAA;EAA0CC,OAAAA,EAAAA,MAAAA;EAAfa;;AA/BpE;;;;kCAjDdR,wBAAwBE,0BAA0BE,QAAQD;;;;;;mCAMzDA,aAAaC,QAAQH;;KAE9CI,0BAAAA,GAA6BN;;;;;;;UAOxBO,sBAAAA,SAA+BT;;;;;;;;;iBAS7BJ;;;;gBAIDS;;;;mBAIGA;;;;;kBAKDG;;;;;;;;;;;;cAYCE,iBAAAA,SAA0BT,IAAIF;;;;;;;gBAOjCM;mBACGA;UACTV;kBACQa;;sBAEIC;;;;;;;;;;yEAUmDZ,2BAA2BU;;;;;;;;;yFASXV,2BAA2Bc,eAAeb"}