UNPKG

@langchain/core

Version:
1 lines 18.1 kB
{"version":3,"file":"base.d.cts","names":["TiktokenModel","ZodType","ZodTypeV3","$ZodType","ZodTypeV4","BaseCache","BasePromptValueInterface","BaseMessage","BaseMessageLike","MessageContent","LLMResult","CallbackManager","Callbacks","AsyncCaller","AsyncCallerParams","Runnable","RunnableInterface","RunnableConfig","JSONSchema","InferInteropZodOutput","InteropZodObject","InteropZodType","ModelProfile","getModelNameForTiktoken","getEmbeddingContextSize","getModelContextSize","isOpenAITool","ToolDefinition","CalculateMaxTokenProps","calculateMaxTokens","prompt","modelName","Promise","SerializedLLM","Record","BaseLangChainParams","BaseLangChain","RunInput","RunOutput","CallOptions","BaseLanguageModelParams","BaseLanguageModelTracingCallOptions","BaseLanguageModelCallOptions","FunctionDefinition","FunctionCallOption","BaseFunctionCallOptions","BaseLanguageModelInput","StructuredOutputType","StructuredOutputMethodOptions","IncludeRaw","StructuredOutputMethodParams","BaseLanguageModelInterface","LanguageModelOutput","LanguageModelLike","BaseLanguageModel","callbacks","callbackManager","config","TokenUsage"],"sources":["../../src/language_models/base.d.ts"],"sourcesContent":["import type { TiktokenModel } from \"js-tiktoken/lite\";\nimport type { ZodType as ZodTypeV3 } from \"zod/v3\";\nimport type { $ZodType as ZodTypeV4 } from \"zod/v4/core\";\nimport { type BaseCache } from \"../caches/index.js\";\nimport { type BasePromptValueInterface } from \"../prompt_values.js\";\nimport { type BaseMessage, type BaseMessageLike, type MessageContent } from \"../messages/base.js\";\nimport { type LLMResult } from \"../outputs.js\";\nimport { CallbackManager, Callbacks } from \"../callbacks/manager.js\";\nimport { AsyncCaller, AsyncCallerParams } from \"../utils/async_caller.js\";\nimport { Runnable, type RunnableInterface } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport { InferInteropZodOutput, InteropZodObject, InteropZodType } from \"../utils/types/zod.js\";\nimport { ModelProfile } from \"./profile.js\";\nexport declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;\nexport declare const getEmbeddingContextSize: (modelName?: string | undefined) => number;\n/**\n * Get the context window size (max input tokens) for a given model.\n *\n * Context window sizes are sourced from official model documentation:\n * - OpenAI: https://platform.openai.com/docs/models\n * - Anthropic: https://docs.anthropic.com/claude/docs/models-overview\n * - Google: https://ai.google.dev/gemini/docs/models/gemini\n *\n * @param modelName - The name of the model\n * @returns The context window size in tokens\n */\nexport declare const getModelContextSize: (modelName: string) => number;\n/**\n * Whether or not the input matches the OpenAI tool definition.\n * @param {unknown} tool The input to check.\n * @returns {boolean} Whether the input is an OpenAI tool definition.\n */\nexport declare function isOpenAITool(tool: unknown): tool is ToolDefinition;\ninterface CalculateMaxTokenProps {\n prompt: string;\n modelName: TiktokenModel;\n}\nexport declare const calculateMaxTokens: ({ prompt, modelName, }: CalculateMaxTokenProps) => Promise<number>;\nexport type SerializedLLM = {\n _model: string;\n _type: string;\n} & Record<string, any>;\nexport interface BaseLangChainParams {\n verbose?: boolean;\n callbacks?: Callbacks;\n tags?: string[];\n metadata?: Record<string, unknown>;\n}\n/**\n * Base class for language models, chains, tools.\n */\nexport declare abstract class BaseLangChain<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> implements BaseLangChainParams {\n /**\n * Whether to print out response text.\n */\n verbose: boolean;\n callbacks?: Callbacks;\n tags?: string[];\n metadata?: Record<string, unknown>;\n get lc_attributes(): {\n [key: string]: undefined;\n } | undefined;\n constructor(params: BaseLangChainParams);\n}\n/**\n * Base interface for language model parameters.\n * A subclass of {@link BaseLanguageModel} should have a constructor that\n * takes in a parameter that extends this interface.\n */\nexport interface BaseLanguageModelParams extends AsyncCallerParams, BaseLangChainParams {\n /**\n * @deprecated Use `callbacks` instead\n */\n callbackManager?: CallbackManager;\n cache?: BaseCache | boolean;\n}\nexport interface BaseLanguageModelTracingCallOptions {\n /**\n * Describes the format of structured outputs.\n * This should be provided if an output is considered to be structured\n */\n ls_structured_output_format?: {\n /**\n * An object containing the method used for structured output (e.g., \"jsonMode\").\n */\n kwargs: {\n method: string;\n };\n /**\n * The JSON schema describing the expected output structure.\n */\n schema?: JSONSchema;\n };\n}\nexport interface BaseLanguageModelCallOptions extends RunnableConfig, BaseLanguageModelTracingCallOptions {\n /**\n * Stop tokens to use for this call.\n * If not provided, the default stop tokens for the model will be used.\n */\n stop?: string[];\n}\nexport interface FunctionDefinition {\n /**\n * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain\n * underscores and dashes, with a maximum length of 64.\n */\n name: string;\n /**\n * The parameters the functions accepts, described as a JSON Schema object. See the\n * [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for\n * examples, and the\n * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for\n * documentation about the format.\n *\n * To describe a function that accepts no parameters, provide the value\n * `{\"type\": \"object\", \"properties\": {}}`.\n */\n parameters: Record<string, unknown> | JSONSchema;\n /**\n * A description of what the function does, used by the model to choose when and\n * how to call the function.\n */\n description?: string;\n}\nexport interface ToolDefinition {\n type: \"function\";\n function: FunctionDefinition;\n}\nexport type FunctionCallOption = {\n name: string;\n};\nexport interface BaseFunctionCallOptions extends BaseLanguageModelCallOptions {\n function_call?: FunctionCallOption;\n functions?: FunctionDefinition[];\n}\nexport type BaseLanguageModelInput = BasePromptValueInterface | string | BaseMessageLike[];\nexport type StructuredOutputType = InferInteropZodOutput<InteropZodObject>;\nexport type StructuredOutputMethodOptions<IncludeRaw extends boolean = false> = {\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\" | \"jsonSchema\" | string;\n includeRaw?: IncludeRaw;\n /** Whether to use strict mode. Currently only supported by OpenAI models. */\n strict?: boolean;\n};\n/** @deprecated Use StructuredOutputMethodOptions instead */\nexport type StructuredOutputMethodParams<RunOutput, IncludeRaw extends boolean = false> = {\n /** @deprecated Pass schema in as the first argument */\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\nexport interface BaseLanguageModelInterface<RunOutput = any, CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions> extends RunnableInterface<BaseLanguageModelInput, RunOutput, CallOptions> {\n get callKeys(): string[];\n generatePrompt(promptValues: BasePromptValueInterface[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<LLMResult>;\n _modelType(): string;\n _llmType(): string;\n getNumTokens(content: MessageContent): Promise<number>;\n /**\n * Get the identifying parameters of the LLM.\n */\n _identifyingParams(): Record<string, any>;\n serialize(): SerializedLLM;\n}\nexport type LanguageModelOutput = BaseMessage | string;\nexport type LanguageModelLike = Runnable<BaseLanguageModelInput, LanguageModelOutput>;\n/**\n * Base class for language models.\n */\nexport declare abstract class BaseLanguageModel<RunOutput = any, CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions> extends BaseLangChain<BaseLanguageModelInput, RunOutput, CallOptions> implements BaseLanguageModelParams, BaseLanguageModelInterface<RunOutput, CallOptions> {\n /**\n * Keys that the language model accepts as call options.\n */\n get callKeys(): string[];\n /**\n * The async caller should be used by subclasses to make any async calls,\n * which will thus benefit from the concurrency and retry logic.\n */\n caller: AsyncCaller;\n cache?: BaseCache;\n constructor({ callbacks, callbackManager, ...params }: BaseLanguageModelParams);\n abstract generatePrompt(promptValues: BasePromptValueInterface[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<LLMResult>;\n abstract _modelType(): string;\n abstract _llmType(): string;\n private _encoding?;\n /**\n * Get the number of tokens in the content.\n * @param content The content to get the number of tokens for.\n * @returns The number of tokens in the content.\n */\n getNumTokens(content: MessageContent): Promise<number>;\n protected static _convertInputToPromptValue(input: BaseLanguageModelInput): BasePromptValueInterface;\n /**\n * Get the identifying parameters of the LLM.\n */\n _identifyingParams(): Record<string, any>;\n /**\n * Create a unique cache key for a specific call to a specific language model.\n * @param callOptions Call options for the model\n * @returns A unique cache key.\n */\n _getSerializedCacheKeyParametersForCall({ config, ...callOptions }: CallOptions & {\n config?: RunnableConfig;\n }): string;\n /**\n * @deprecated\n * Return a json-like object representing this LLM.\n */\n serialize(): SerializedLLM;\n /**\n * @deprecated\n * Load an LLM from a json-like object describing it.\n */\n static deserialize(_data: SerializedLLM): Promise<BaseLanguageModel>;\n /**\n * Return profiling information for the model.\n *\n * @returns {ModelProfile} An object describing the model's capabilities and constraints\n */\n get profile(): ModelProfile;\n withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n /**\n * Model wrapper that returns outputs formatted to match the given schema.\n *\n * @template {BaseLanguageModelInput} RunInput The input type for the Runnable, expected to be the same input for the LLM.\n * @template {Record<string, any>} RunOutput The output type for the Runnable, expected to be a Zod schema object for structured output validation.\n *\n * @param {InteropZodType<RunOutput>} schema The schema for the structured output. Either as a Zod schema or a valid JSON schema object.\n * If a Zod schema is passed, the returned attributes will be validated, whereas with JSON schema they will not be.\n * @param {string} name The name of the function to call.\n * @param {\"functionCalling\" | \"jsonMode\"} [method=functionCalling] The method to use for getting the structured output. Defaults to \"functionCalling\".\n * @param {boolean | undefined} [includeRaw=false] Whether to include the raw output in the result. Defaults to false.\n * @returns {Runnable<RunInput, RunOutput> | Runnable<RunInput, { raw: BaseMessage; parsed: RunOutput }>} A new runnable that calls the LLM with structured output.\n */\n withStructuredOutput?<RunOutput extends Record<string, any> = Record<string, any>>(schema: InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<boolean>): Runnable<BaseLanguageModelInput, RunOutput> | Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n}\n/**\n * Shared interface for token usage\n * return type from LLM calls.\n */\nexport interface TokenUsage {\n completionTokens?: number;\n promptTokens?: number;\n totalTokens?: number;\n}\nexport {};\n//# sourceMappingURL=base.d.ts.map"],"mappings":";;;;;;;;;;;;;;;;cAcqBuB,gDAAgDvB;cAChDwB;AADrB;AACA;AAYA;AAMA;AAA4E;AAK5E;;;;;AAAoG;AACxFS,cAZSR,mBAeX,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACV;AASA;;;;AAAiJa,iBAnBzHZ,YAAAA,CAmByHY,IAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA,IAnBpFX,cAmBoFW;UAlBvIV,sBAAAA,CAkBkJW;EAK5I3B,MAAAA,EAAAA,MAAAA;EAEDsB,SAAAA,EAvBAlC,aAuBAkC;;AAP+GnB,cAdzGc,kBAcyGd,EAAAA,CAAAA;EAAAA,MAAAA;EAAAA;AAAAA,CAAAA,EAd5Da,sBAc4Db,EAAAA,GAdjCiB,OAciCjB,CAAAA,MAAAA,CAAAA;AAAsDoB,KAbxKF,aAAAA,GAawKE;EAAmB,MAAA,EAAA,MAAA;EAkBtLK,KAAAA,EAAAA,MAAAA;CAIK7B,GAhClBuB,MAgCkBvB,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;AACVN,UAhCK8B,mBAAAA,CAgCL9B;EALqCS,OAAAA,CAAAA,EAAAA,OAAAA;EAAmBqB,SAAAA,CAAAA,EAzBpDvB,SAyBoDuB;EAAmB,IAAA,CAAA,EAAA,MAAA,E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