UNPKG

@sap-ai-sdk/langchain

Version:

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for **SAP AI Core**, **SAP Generative AI Hub**, and **Orchestration Service**.

92 lines 4.17 kB
import { AIMessageChunk } from '@langchain/core/messages'; import type { FunctionDefinition, ToolDefinition } from '@langchain/core/language_models/base'; import type { ChatOrchestrationToolType } from './types.js'; import type { ChatResult } from '@langchain/core/outputs'; import type { ChatCompletionTool, ChatMessage, CompletionPostResponse, FunctionObject, FunctionParameters, Template, TemplatingModuleConfig, TemplateRef, OrchestrationStreamChunkResponse, TokenUsage } from '@sap-ai-sdk/orchestration'; import type { BaseMessage } from '@langchain/core/messages'; /** * Maps a {@link ChatOrchestrationToolType} to {@link FunctionObject}. * @param tool - Base class for tools that accept input of any shape defined by a Zod schema. * @param strict - Whether to enforce strict mode for the function call. * @returns The Orchestration chat completion function. * @internal */ export declare function mapToolToOrchestrationFunction(tool: ChatOrchestrationToolType, strict?: boolean): FunctionObject; /** * Maps a LangChain {@link ChatOrchestrationToolType} to {@link ChatCompletionTool}. * @param tool - Base class for tools that accept input of any shape defined by a Zod schema. * @param strict - Whether to enforce strict mode for the function call. * @returns The Orchestration chat completion tool. * @internal */ export declare function mapToolToChatCompletionTool(tool: ChatOrchestrationToolType, strict?: boolean): ChatCompletionTool; /** * Checks if the object is a {@link Template}. * @param object - The object to check. * @returns True if the object is a {@link Template}. * @internal */ export declare function isTemplate(object: TemplatingModuleConfig): object is Template; /** * Checks if the object is a {@link TemplateRef}. * @param object - The object to check. * @returns True if the object is a {@link TemplateRef}. * @internal */ export declare function isTemplateRef(object: TemplatingModuleConfig): object is TemplateRef; /** * Maps LangChain messages to orchestration messages. * @param messages - The LangChain messages to map. * @returns The orchestration messages mapped from LangChain messages. * @internal */ export declare function mapLangChainMessagesToOrchestrationMessages(messages: BaseMessage[]): ChatMessage[]; /** * Maps the completion response to a {@link ChatResult}. * @param completionResponse - The completion response to map. * @returns The mapped {@link ChatResult}. * @internal */ export declare function mapOutputToChatResult(completionResponse: CompletionPostResponse): ChatResult; type ToolDefinitionLike = Pick<ToolDefinition, 'type'> & { function: Omit<FunctionDefinition, 'parameters'> & { parameters?: FunctionParameters; }; }; /** * @internal */ export declare function isToolDefinitionLike(tool: ChatOrchestrationToolType): tool is ToolDefinitionLike; /** * Converts orchestration stream chunk to a LangChain message chunk. * @param chunk - The orchestration stream chunk. * @returns An {@link AIMessageChunk} * @internal */ export declare function mapOrchestrationChunkToLangChainMessageChunk(chunk: OrchestrationStreamChunkResponse): AIMessageChunk; /** * Sets finish reason on a LangChain message chunk if available. * @param messageChunk - The LangChain message chunk to update. * @param finishReason - The finish reason from the response. * @internal */ export declare function setFinishReason(messageChunk: AIMessageChunk, finishReason?: string): void; /** * Sets usage metadata on a message chunk if available. * @param messageChunk - The LangChain message chunk to update. * @param tokenUsage - The token usage information. * @internal */ export declare function setTokenUsage(messageChunk: AIMessageChunk, tokenUsage?: TokenUsage): void; /** * Computes token indices for a chunk of the orchestration stream response. * @param chunk - A chunk of the orchestration stream response. * @returns An object with prompt and completion indices. * @internal */ export declare function computeTokenIndices(chunk: OrchestrationStreamChunkResponse): { prompt: number; completion: number; }; export {}; //# sourceMappingURL=util.d.ts.map