@langchain/core 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -19
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.cjs +5 -18
- package/dist/caches/base.cjs.map +1 -1
- package/dist/caches/base.d.cts +4 -20
- package/dist/caches/base.d.cts.map +1 -1
- package/dist/caches/base.d.ts +4 -20
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/caches/base.js +5 -18
- package/dist/caches/base.js.map +1 -1
- package/dist/callbacks/base.d.cts +3 -2
- package/dist/callbacks/base.d.cts.map +1 -1
- package/dist/callbacks/base.d.ts +3 -2
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/callbacks/manager.d.cts +1 -1
- package/dist/callbacks/manager.d.ts +1 -1
- package/dist/document_loaders/langsmith.cjs +1 -1
- package/dist/document_loaders/langsmith.cjs.map +1 -1
- package/dist/document_loaders/langsmith.js +1 -1
- package/dist/document_loaders/langsmith.js.map +1 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +6 -6
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +6 -6
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/indexing/base.cjs +2 -2
- package/dist/indexing/base.cjs.map +1 -1
- package/dist/indexing/base.d.cts +0 -3
- package/dist/indexing/base.d.cts.map +1 -1
- package/dist/indexing/base.d.ts +0 -3
- package/dist/indexing/base.d.ts.map +1 -1
- package/dist/indexing/base.js +2 -2
- package/dist/indexing/base.js.map +1 -1
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +4 -4
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +4 -4
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs +1 -0
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.cts +2 -1
- package/dist/language_models/chat_models.d.cts.map +1 -1
- package/dist/language_models/chat_models.d.ts +2 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js +2 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +1 -5
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +3 -7
- package/dist/load/import_map.js.map +1 -1
- package/dist/load/index.cjs.map +1 -1
- package/dist/load/index.js.map +1 -1
- package/dist/load/serializable.cjs.map +1 -1
- package/dist/load/serializable.d.cts +1 -3
- package/dist/load/serializable.d.cts.map +1 -1
- package/dist/load/serializable.d.ts +1 -3
- package/dist/load/serializable.d.ts.map +1 -1
- package/dist/load/serializable.js.map +1 -1
- package/dist/messages/ai.cjs +34 -62
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.d.cts +26 -119
- package/dist/messages/ai.d.cts.map +1 -1
- package/dist/messages/ai.d.ts +26 -119
- package/dist/messages/ai.d.ts.map +1 -1
- package/dist/messages/ai.js +34 -62
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +53 -33
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +38 -41
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +38 -41
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +53 -33
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs +1 -1
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js +1 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/chat.cjs +18 -12
- package/dist/messages/chat.cjs.map +1 -1
- package/dist/messages/chat.d.cts +21 -13
- package/dist/messages/chat.d.cts.map +1 -1
- package/dist/messages/chat.d.ts +21 -13
- package/dist/messages/chat.d.ts.map +1 -1
- package/dist/messages/chat.js +18 -12
- package/dist/messages/chat.js.map +1 -1
- package/dist/messages/content/index.cjs.map +1 -1
- package/dist/messages/content/index.d.cts +1 -1
- package/dist/messages/content/index.d.cts.map +1 -1
- package/dist/messages/content/index.d.ts +1 -1
- package/dist/messages/content/index.d.ts.map +1 -1
- package/dist/messages/content/index.js.map +1 -1
- package/dist/messages/function.cjs +8 -13
- package/dist/messages/function.cjs.map +1 -1
- package/dist/messages/function.d.cts +11 -11
- package/dist/messages/function.d.cts.map +1 -1
- package/dist/messages/function.d.ts +11 -11
- package/dist/messages/function.d.ts.map +1 -1
- package/dist/messages/function.js +8 -13
- package/dist/messages/function.js.map +1 -1
- package/dist/messages/human.cjs +20 -11
- package/dist/messages/human.cjs.map +1 -1
- package/dist/messages/human.d.cts +20 -15
- package/dist/messages/human.d.cts.map +1 -1
- package/dist/messages/human.d.ts +20 -15
- package/dist/messages/human.d.ts.map +1 -1
- package/dist/messages/human.js +20 -11
- package/dist/messages/human.js.map +1 -1
- package/dist/messages/index.cjs +11 -1
- package/dist/messages/index.cjs.map +1 -1
- package/dist/messages/index.d.cts +9 -7
- package/dist/messages/index.d.ts +9 -7
- package/dist/messages/index.js +8 -2
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.cjs +15 -0
- package/dist/messages/message.cjs.map +1 -0
- package/dist/messages/message.d.cts +598 -0
- package/dist/messages/message.d.cts.map +1 -0
- package/dist/messages/message.d.ts +598 -0
- package/dist/messages/message.d.ts.map +1 -0
- package/dist/messages/message.js +14 -0
- package/dist/messages/message.js.map +1 -0
- package/dist/messages/metadata.cjs +41 -0
- package/dist/messages/metadata.cjs.map +1 -0
- package/dist/messages/metadata.d.cts +98 -0
- package/dist/messages/metadata.d.cts.map +1 -0
- package/dist/messages/metadata.d.ts +98 -0
- package/dist/messages/metadata.d.ts.map +1 -0
- package/dist/messages/metadata.js +40 -0
- package/dist/messages/metadata.js.map +1 -0
- package/dist/messages/modifier.cjs +5 -4
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.d.cts +7 -5
- package/dist/messages/modifier.d.cts.map +1 -1
- package/dist/messages/modifier.d.ts +7 -5
- package/dist/messages/modifier.d.ts.map +1 -1
- package/dist/messages/modifier.js +5 -4
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/system.cjs +20 -11
- package/dist/messages/system.cjs.map +1 -1
- package/dist/messages/system.d.cts +20 -15
- package/dist/messages/system.d.cts.map +1 -1
- package/dist/messages/system.d.ts +20 -15
- package/dist/messages/system.d.ts.map +1 -1
- package/dist/messages/system.js +20 -11
- package/dist/messages/system.js.map +1 -1
- package/dist/messages/tool.cjs +21 -19
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.d.cts +72 -46
- package/dist/messages/tool.d.cts.map +1 -1
- package/dist/messages/tool.d.ts +72 -46
- package/dist/messages/tool.d.ts.map +1 -1
- package/dist/messages/tool.js +21 -19
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.d.cts +2 -1
- package/dist/messages/transformers.d.cts.map +1 -1
- package/dist/messages/transformers.d.ts +2 -1
- package/dist/messages/transformers.d.ts.map +1 -1
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs +13 -1
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.d.cts +83 -3
- package/dist/messages/utils.d.cts.map +1 -1
- package/dist/messages/utils.d.ts +83 -3
- package/dist/messages/utils.d.ts.map +1 -1
- package/dist/messages/utils.js +13 -2
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.cjs.map +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/output_parsers/list.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
- package/dist/output_parsers/structured.cjs +2 -1
- package/dist/output_parsers/structured.cjs.map +1 -1
- package/dist/output_parsers/structured.js +2 -1
- package/dist/output_parsers/structured.js.map +1 -1
- package/dist/prompt_values.d.cts +4 -3
- package/dist/prompt_values.d.cts.map +1 -1
- package/dist/prompt_values.d.ts +4 -3
- package/dist/prompt_values.d.ts.map +1 -1
- package/dist/prompts/chat.cjs +3 -1
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +7 -15
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +7 -15
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +3 -1
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/few_shot.d.cts +1 -1
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.cjs.map +1 -1
- package/dist/prompts/image.d.cts +1 -3
- package/dist/prompts/image.d.cts.map +1 -1
- package/dist/prompts/image.d.ts +1 -3
- package/dist/prompts/image.d.ts.map +1 -1
- package/dist/prompts/image.js.map +1 -1
- package/dist/prompts/pipeline.cjs.map +1 -1
- package/dist/prompts/pipeline.js.map +1 -1
- package/dist/prompts/prompt.cjs.map +1 -1
- package/dist/prompts/prompt.d.cts +5 -17
- package/dist/prompts/prompt.d.cts.map +1 -1
- package/dist/prompts/prompt.d.ts +5 -17
- package/dist/prompts/prompt.d.ts.map +1 -1
- package/dist/prompts/prompt.js.map +1 -1
- package/dist/prompts/structured.cjs.map +1 -1
- package/dist/prompts/structured.js.map +1 -1
- package/dist/prompts/template.cjs +4 -2
- package/dist/prompts/template.cjs.map +1 -1
- package/dist/prompts/template.d.cts +1 -1
- package/dist/prompts/template.d.ts +1 -1
- package/dist/prompts/template.js +4 -2
- package/dist/prompts/template.js.map +1 -1
- package/dist/runnables/base.cjs +6 -6
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +1 -4
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +1 -4
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +6 -6
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/branch.cjs +2 -2
- package/dist/runnables/branch.cjs.map +1 -1
- package/dist/runnables/branch.js +2 -2
- package/dist/runnables/branch.js.map +1 -1
- package/dist/runnables/config.cjs.map +1 -1
- package/dist/runnables/config.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +1 -1
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +26 -3
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +26 -3
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/remote.cjs.map +1 -1
- package/dist/runnables/remote.js.map +1 -1
- package/dist/runnables/types.d.cts +0 -1
- package/dist/runnables/types.d.cts.map +1 -1
- package/dist/runnables/types.d.ts +0 -1
- package/dist/runnables/types.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.cjs.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -1
- package/dist/singletons/async_local_storage/context.d.cts.map +1 -1
- package/dist/singletons/async_local_storage/context.d.ts +0 -1
- package/dist/singletons/async_local_storage/context.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.js.map +1 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.cts +6 -6
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +6 -6
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.d.cts +1 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/console.cjs +1 -1
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.js +1 -1
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.cjs +1 -1
- package/dist/tracers/event_stream.cjs.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -1
- package/dist/tracers/event_stream.d.cts.map +1 -1
- package/dist/tracers/event_stream.d.ts +0 -1
- package/dist/tracers/event_stream.d.ts.map +1 -1
- package/dist/tracers/event_stream.js +1 -1
- package/dist/tracers/event_stream.js.map +1 -1
- package/dist/tracers/log_stream.cjs.map +1 -1
- package/dist/tracers/log_stream.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/tracers/tracer_langchain_v1.d.cts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/chunk_array.cjs.map +1 -1
- package/dist/utils/chunk_array.js.map +1 -1
- package/dist/utils/env.cjs +1 -1
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.js +1 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/event_source_parse.cjs.map +1 -1
- package/dist/utils/event_source_parse.d.cts.map +1 -1
- package/dist/utils/event_source_parse.d.ts.map +1 -1
- package/dist/utils/event_source_parse.js.map +1 -1
- package/dist/utils/hash.cjs +3 -8
- package/dist/utils/hash.cjs.map +1 -1
- package/dist/utils/hash.d.cts +1 -2
- package/dist/utils/hash.d.cts.map +1 -1
- package/dist/utils/hash.d.ts +1 -2
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +2 -6
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/js-sha256/hash.cjs +0 -9
- package/dist/utils/js-sha256/hash.cjs.map +1 -1
- package/dist/utils/js-sha256/hash.js +1 -5
- package/dist/utils/js-sha256/hash.js.map +1 -1
- package/dist/utils/json.cjs +2 -2
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.js +2 -2
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/json_schema.cjs +3 -2
- package/dist/utils/json_schema.cjs.map +1 -1
- package/dist/utils/json_schema.d.cts +8 -4
- package/dist/utils/json_schema.d.cts.map +1 -1
- package/dist/utils/json_schema.d.ts +8 -4
- package/dist/utils/json_schema.d.ts.map +1 -1
- package/dist/utils/json_schema.js +2 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/testing/index.cjs.map +1 -1
- package/dist/utils/testing/index.d.cts +8 -12
- package/dist/utils/testing/index.d.cts.map +1 -1
- package/dist/utils/testing/index.d.ts +8 -12
- package/dist/utils/testing/index.d.ts.map +1 -1
- package/dist/utils/testing/index.js.map +1 -1
- package/dist/utils/zod-to-json-schema/Options.cjs +40 -0
- package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Options.js +37 -0
- package/dist/utils/zod-to-json-schema/Options.js.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs +30 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.js +30 -0
- package/dist/utils/zod-to-json-schema/Refs.js.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs +18 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js +16 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs +11 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js +10 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -0
- package/dist/utils/zod-to-json-schema/index.cjs +37 -0
- package/dist/utils/zod-to-json-schema/index.js +37 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parseDef.js +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs +24 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js +23 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs +9 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js +8 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js +56 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs +255 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts +28 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts +29 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js +254 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs +67 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts +24 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts +25 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js +66 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs +81 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.js +80 -0
- package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
- package/package.json +7 -36
- package/dist/utils/js-sha1/hash.cjs +0 -291
- package/dist/utils/js-sha1/hash.cjs.map +0 -1
- package/dist/utils/js-sha1/hash.d.cts +0 -9
- package/dist/utils/js-sha1/hash.d.cts.map +0 -1
- package/dist/utils/js-sha1/hash.d.ts +0 -9
- package/dist/utils/js-sha1/hash.d.ts.map +0 -1
- package/dist/utils/js-sha1/hash.js +0 -284
- package/dist/utils/js-sha1/hash.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":["VectorStore","RecordManagerInterface","HashKeyEncoder","DocumentInterface","BaseDocumentLoader","Metadata","Record","IndexingResult","StringOrDocFunc","HashedDocumentInterface","HashedDocumentArgs","_HashedDocument","CleanupMode","IndexOptions","_batch","T","_deduplicateInOrder","_getSourceIdAssigner","_isBaseDocumentLoader","IndexArgs","index","Promise"],"sources":["../../src/indexing/base.d.ts"],"sourcesContent":["import { VectorStore } from \"../vectorstores.js\";\nimport { RecordManagerInterface } from \"./record_manager.js\";\nimport { type HashKeyEncoder } from \"../utils/hash.js\";\nimport { DocumentInterface } from \"../documents/document.js\";\nimport { BaseDocumentLoader } from \"../document_loaders/base.js\";\ntype Metadata = Record<string, unknown>;\ntype IndexingResult = {\n numAdded: number;\n numDeleted: number;\n numUpdated: number;\n numSkipped: number;\n};\ntype StringOrDocFunc = string | ((doc: DocumentInterface) => string);\nexport interface HashedDocumentInterface extends DocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n calculateHashes(): void;\n toDocument(): DocumentInterface;\n}\ninterface HashedDocumentArgs {\n pageContent: string;\n metadata: Metadata;\n uid: string;\n}\n/**\n * HashedDocument is a Document with hashes calculated.\n * Hashes are calculated based on page content and metadata.\n * It is used for indexing.\n */\nexport declare class _HashedDocument implements HashedDocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n
|
|
1
|
+
{"version":3,"file":"base.d.ts","names":["VectorStore","RecordManagerInterface","HashKeyEncoder","DocumentInterface","BaseDocumentLoader","Metadata","Record","IndexingResult","StringOrDocFunc","HashedDocumentInterface","HashedDocumentArgs","_HashedDocument","CleanupMode","IndexOptions","_batch","T","_deduplicateInOrder","_getSourceIdAssigner","_isBaseDocumentLoader","IndexArgs","index","Promise"],"sources":["../../src/indexing/base.d.ts"],"sourcesContent":["import { VectorStore } from \"../vectorstores.js\";\nimport { RecordManagerInterface } from \"./record_manager.js\";\nimport { type HashKeyEncoder } from \"../utils/hash.js\";\nimport { DocumentInterface } from \"../documents/document.js\";\nimport { BaseDocumentLoader } from \"../document_loaders/base.js\";\ntype Metadata = Record<string, unknown>;\ntype IndexingResult = {\n numAdded: number;\n numDeleted: number;\n numUpdated: number;\n numSkipped: number;\n};\ntype StringOrDocFunc = string | ((doc: DocumentInterface) => string);\nexport interface HashedDocumentInterface extends DocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n calculateHashes(): void;\n toDocument(): DocumentInterface;\n}\ninterface HashedDocumentArgs {\n pageContent: string;\n metadata: Metadata;\n uid: string;\n}\n/**\n * HashedDocument is a Document with hashes calculated.\n * Hashes are calculated based on page content and metadata.\n * It is used for indexing.\n */\nexport declare class _HashedDocument implements HashedDocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n private keyEncoder;\n constructor(fields: HashedDocumentArgs);\n makeDefaultKeyEncoder(keyEncoderFn: HashKeyEncoder): void;\n calculateHashes(): void;\n toDocument(): DocumentInterface;\n static fromDocument(document: DocumentInterface, uid?: string): _HashedDocument;\n private _hashStringToUUID;\n private _hashNestedDictToUUID;\n}\nexport type CleanupMode = \"full\" | \"incremental\";\nexport type IndexOptions = {\n /**\n * The number of documents to index in one batch.\n */\n batchSize?: number;\n /**\n * The cleanup mode to use. Can be \"full\", \"incremental\" or undefined.\n * - **Incremental**: Cleans up all documents that haven't been updated AND\n * that are associated with source ids that were seen\n * during indexing.\n * Clean up is done continuously during indexing helping\n * to minimize the probability of users seeing duplicated\n * content.\n * - **Full**: Delete all documents that haven to been returned by the loader.\n * Clean up runs after all documents have been indexed.\n * This means that users may see duplicated content during indexing.\n * - **undefined**: Do not delete any documents.\n */\n cleanup?: CleanupMode;\n /**\n * Optional key that helps identify the original source of the document.\n * Must either be a string representing the key of the source in the metadata\n * or a function that takes a document and returns a string representing the source.\n * **Required when cleanup is incremental**.\n */\n sourceIdKey?: StringOrDocFunc;\n /**\n * Batch size to use when cleaning up documents.\n */\n cleanupBatchSize?: number;\n /**\n * Force update documents even if they are present in the\n * record manager. Useful if you are re-indexing with updated embeddings.\n */\n forceUpdate?: boolean;\n};\nexport declare function _batch<T>(size: number, iterable: T[]): T[][];\nexport declare function _deduplicateInOrder(hashedDocuments: HashedDocumentInterface[]): HashedDocumentInterface[];\nexport declare function _getSourceIdAssigner(sourceIdKey: StringOrDocFunc | null): (doc: DocumentInterface) => string | null;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare const _isBaseDocumentLoader: (arg: any) => arg is BaseDocumentLoader;\ninterface IndexArgs {\n docsSource: BaseDocumentLoader | DocumentInterface[];\n recordManager: RecordManagerInterface;\n vectorStore: VectorStore;\n options?: IndexOptions;\n}\n/**\n * Index data from the doc source into the vector store.\n *\n * Indexing functionality uses a manager to keep track of which documents\n * are in the vector store.\n *\n * This allows us to keep track of which documents were updated, and which\n * documents were deleted, which documents should be skipped.\n *\n * For the time being, documents are indexed using their hashes, and users\n * are not able to specify the uid of the document.\n *\n * @param {IndexArgs} args\n * @param {BaseDocumentLoader | DocumentInterface[]} args.docsSource The source of documents to index. Can be a DocumentLoader or a list of Documents.\n * @param {RecordManagerInterface} args.recordManager The record manager to use for keeping track of indexed documents.\n * @param {VectorStore} args.vectorStore The vector store to use for storing the documents.\n * @param {IndexOptions | undefined} args.options Options for indexing.\n * @returns {Promise<IndexingResult>}\n */\nexport declare function index(args: IndexArgs): Promise<IndexingResult>;\nexport {};\n"],"mappings":";;;;;;;KAKKK,QAAAA,GAAWC;KACXC,cAAAA;EADAF,QAAAA,EAAAA,MAAQ;EACRE,UAAAA,EAAAA,MAAc;EAMdC,UAAAA,EAAAA,MAAe;EACHC,UAAAA,EAAAA,MAAAA;CAAuB;KADnCD,eAAAA,GAOSH,MAAAA,GAAAA,CAAAA,CAAAA,GAAAA,EAPyBF,iBAOzBE,EAAAA,GAAAA,MAAAA,CAAAA;AAEIF,UARDM,uBAAAA,SAAgCN,iBAQ/BA,CAAAA;EAAiB,GARcA,EAAAA,MAAAA;EAAiB,KAAA,CAAA,EAAA,MAAA;EAUxDO,WAAAA,CAAAA,EAAAA,MAAAA;EAUWC,YAAAA,CAAAA,EAAAA,MAAe;EAAA,WAAA,EAAA,MAAA;EAAA,QAMtBN,EApBAA,QAoBAA;EAAQ,eAEEK,EAAAA,EAAAA,IAAAA;EAAkB,UACFR,EAAAA,EArBtBC,iBAqBsBD;;UAnB9BQ,kBAAAA,CAsBwBP;EAAiB,WAAiBQ,EAAAA,MAAAA;EAAe,QAZnCF,EARlCJ,QAQkCI;EAAuB,GAAA,EAAA,MAAA;AAgBvE;AACA;;;;AAyBiC;AAWTK,cArDHH,eAAAA,YAA2BF,uBAqDlB,CAAA;EAAA,GAAA,EAAA,MAAA;EAAA,KAA4BM,CAAAA,EAAAA,MAAAA;EAAC,WAAKA,CAAAA,EAAAA,MAAAA;EAAC,YAAA,CAAA,EAAA,MAAA;EACzCC,WAAAA,EAAAA,MAAAA;EAAmB,QAAA,EAhD7BX,QAgD6B;EAAA,QAAkBI,UAAAA;EAAuB,WAAKA,CAAAA,MAAAA,EA9CjEC,kBA8CiED;EAAuB,qBAAA,CAAA,YAAA,EA7CxEP,cA6CwE,CAAA,EAAA,IAAA;EACxFe,eAAAA,CAAAA,CAAAA,EAAAA,IAAoB;EAAA,UAAA,CAAA,CAAA,EA5C1Bd,iBA4C0B;EAAA,OAAcK,YAAAA,CAAAA,QAAAA,EA3CxBL,iBA2CwBK,EAAAA,GAAAA,CAAAA,EAAAA,MAAAA,CAAAA,EA3CUG,eA2CVH;EAAe,QAAgBL,iBAAAA;EAAiB,QAAA,qBAAA;AAE1G;AACUgB,KA1CEP,WAAAA,GA0CO,MAAA,GAAA,aAAA;AAAA,KAzCPC,YAAAA,GAyCO;EAAA;;;EAEsB,SACxBb,CAAAA,EAAAA,MAAAA;EAAW;AACF;AAqB1B;;;;;AAAuD;;;;;;YAhDzCY;;;;;;;gBAOIJ;;;;;;;;;;;iBAWMM,kCAAkCC,MAAMA;iBACxCC,mBAAAA,kBAAqCP,4BAA4BA;iBACjEQ,oBAAAA,cAAkCT,+BAA+BL;;cAEpEe,4CAA4Cd;UACvDe,SAAAA;cACMf,qBAAqBD;iBAClBF;eACFD;YACHa;;;;;;;;;;;;;;;;;;;;;iBAqBUO,KAAAA,OAAYD,YAAYE,QAAQd"}
|
package/dist/indexing/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sha256 } from "../utils/js-sha256/hash.js";
|
|
2
2
|
import "../utils/hash.js";
|
|
3
3
|
import { Document } from "../documents/document.js";
|
|
4
4
|
import { UUIDV5_NAMESPACE } from "./record_manager.js";
|
|
@@ -17,7 +17,7 @@ var _HashedDocument = class {
|
|
|
17
17
|
metadataHash;
|
|
18
18
|
pageContent;
|
|
19
19
|
metadata;
|
|
20
|
-
keyEncoder =
|
|
20
|
+
keyEncoder = sha256;
|
|
21
21
|
constructor(fields) {
|
|
22
22
|
this.uid = fields.uid;
|
|
23
23
|
this.pageContent = fields.pageContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":["fields: HashedDocumentArgs","keyEncoderFn: HashKeyEncoder","document: DocumentInterface","uid?: string","inputString: string","uuidv5","data: Record<string, unknown>","size: number","iterable: T[]","batches: T[][]","currentBatch: T[]","hashedDocuments: HashedDocumentInterface[]","deduplicated: HashedDocumentInterface[]","sourceIdKey: StringOrDocFunc | null","_doc: DocumentInterface","doc: DocumentInterface","arg: any","args: IndexArgs","index","uids: string[]","docsToIndex: DocumentInterface[]","docsToUpdate: string[]"],"sources":["../../src/indexing/base.ts"],"sourcesContent":["import { v5 as uuidv5 } from \"uuid\";\nimport { VectorStore } from \"../vectorstores.js\";\nimport { RecordManagerInterface, UUIDV5_NAMESPACE } from \"./record_manager.js\";\nimport { insecureHash, type HashKeyEncoder } from \"../utils/hash.js\";\nimport { DocumentInterface, Document } from \"../documents/document.js\";\nimport { BaseDocumentLoader } from \"../document_loaders/base.js\";\n\ntype Metadata = Record<string, unknown>;\n\ntype IndexingResult = {\n numAdded: number;\n numDeleted: number;\n numUpdated: number;\n numSkipped: number;\n};\n\ntype StringOrDocFunc = string | ((doc: DocumentInterface) => string);\n\nexport interface HashedDocumentInterface extends DocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n calculateHashes(): void;\n toDocument(): DocumentInterface;\n}\n\ninterface HashedDocumentArgs {\n pageContent: string;\n metadata: Metadata;\n uid: string;\n}\n\n/**\n * HashedDocument is a Document with hashes calculated.\n * Hashes are calculated based on page content and metadata.\n * It is used for indexing.\n */\nexport class _HashedDocument implements HashedDocumentInterface {\n uid: string;\n\n hash_?: string;\n\n contentHash?: string;\n\n metadataHash?: string;\n\n pageContent: string;\n\n metadata: Metadata;\n\n // For backwards compatibility, we use a default key encoder\n // that uses SHA-1 to hash the prompt and LLM key. This will also print a warning\n // about the security implications of using SHA-1 as a key encoder.\n private keyEncoder: HashKeyEncoder = insecureHash;\n\n constructor(fields: HashedDocumentArgs) {\n this.uid = fields.uid;\n this.pageContent = fields.pageContent;\n this.metadata = fields.metadata;\n }\n\n makeDefaultKeyEncoder(keyEncoderFn: HashKeyEncoder): void {\n this.keyEncoder = keyEncoderFn;\n }\n\n calculateHashes(): void {\n const forbiddenKeys = [\"hash_\", \"content_hash\", \"metadata_hash\"];\n\n for (const key of forbiddenKeys) {\n if (key in this.metadata) {\n throw new Error(\n `Metadata cannot contain key ${key} as it is reserved for internal use. Restricted keys: [${forbiddenKeys.join(\n \", \"\n )}]`\n );\n }\n }\n\n const contentHash = this._hashStringToUUID(this.pageContent);\n\n try {\n const metadataHash = this._hashNestedDictToUUID(this.metadata);\n this.contentHash = contentHash;\n this.metadataHash = metadataHash;\n } catch (e) {\n throw new Error(\n `Failed to hash metadata: ${e}. Please use a dict that can be serialized using json.`\n );\n }\n\n this.hash_ = this._hashStringToUUID(this.contentHash + this.metadataHash);\n\n if (!this.uid) {\n this.uid = this.hash_;\n }\n }\n\n toDocument(): DocumentInterface {\n return new Document({\n pageContent: this.pageContent,\n metadata: this.metadata,\n });\n }\n\n static fromDocument(\n document: DocumentInterface,\n uid?: string\n ): _HashedDocument {\n const doc = new this({\n pageContent: document.pageContent,\n metadata: document.metadata,\n uid: uid || (document as DocumentInterface & { uid: string }).uid,\n });\n doc.calculateHashes();\n return doc;\n }\n\n private _hashStringToUUID(inputString: string): string {\n const hash_value = this.keyEncoder(inputString);\n return uuidv5(hash_value, UUIDV5_NAMESPACE);\n }\n\n private _hashNestedDictToUUID(data: Record<string, unknown>): string {\n const serialized_data = JSON.stringify(data, Object.keys(data).sort());\n const hash_value = this.keyEncoder(serialized_data);\n return uuidv5(hash_value, UUIDV5_NAMESPACE);\n }\n}\n\nexport type CleanupMode = \"full\" | \"incremental\";\n\nexport type IndexOptions = {\n /**\n * The number of documents to index in one batch.\n */\n batchSize?: number;\n /**\n * The cleanup mode to use. Can be \"full\", \"incremental\" or undefined.\n * - **Incremental**: Cleans up all documents that haven't been updated AND\n * that are associated with source ids that were seen\n * during indexing.\n * Clean up is done continuously during indexing helping\n * to minimize the probability of users seeing duplicated\n * content.\n * - **Full**: Delete all documents that haven to been returned by the loader.\n * Clean up runs after all documents have been indexed.\n * This means that users may see duplicated content during indexing.\n * - **undefined**: Do not delete any documents.\n */\n cleanup?: CleanupMode;\n /**\n * Optional key that helps identify the original source of the document.\n * Must either be a string representing the key of the source in the metadata\n * or a function that takes a document and returns a string representing the source.\n * **Required when cleanup is incremental**.\n */\n sourceIdKey?: StringOrDocFunc;\n /**\n * Batch size to use when cleaning up documents.\n */\n cleanupBatchSize?: number;\n /**\n * Force update documents even if they are present in the\n * record manager. Useful if you are re-indexing with updated embeddings.\n */\n forceUpdate?: boolean;\n};\n\nexport function _batch<T>(size: number, iterable: T[]): T[][] {\n const batches: T[][] = [];\n let currentBatch: T[] = [];\n\n iterable.forEach((item) => {\n currentBatch.push(item);\n\n if (currentBatch.length >= size) {\n batches.push(currentBatch);\n currentBatch = [];\n }\n });\n\n if (currentBatch.length > 0) {\n batches.push(currentBatch);\n }\n\n return batches;\n}\n\nexport function _deduplicateInOrder(\n hashedDocuments: HashedDocumentInterface[]\n): HashedDocumentInterface[] {\n const seen = new Set<string>();\n const deduplicated: HashedDocumentInterface[] = [];\n\n for (const hashedDoc of hashedDocuments) {\n if (!hashedDoc.hash_) {\n throw new Error(\"Hashed document does not have a hash\");\n }\n\n if (!seen.has(hashedDoc.hash_)) {\n seen.add(hashedDoc.hash_);\n deduplicated.push(hashedDoc);\n }\n }\n return deduplicated;\n}\n\nexport function _getSourceIdAssigner(\n sourceIdKey: StringOrDocFunc | null\n): (doc: DocumentInterface) => string | null {\n if (sourceIdKey === null) {\n return (_doc: DocumentInterface) => null;\n } else if (typeof sourceIdKey === \"string\") {\n return (doc: DocumentInterface) => doc.metadata[sourceIdKey];\n } else if (typeof sourceIdKey === \"function\") {\n return sourceIdKey;\n } else {\n throw new Error(\n `sourceIdKey should be null, a string or a function, got ${typeof sourceIdKey}`\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const _isBaseDocumentLoader = (arg: any): arg is BaseDocumentLoader => {\n if (\n \"load\" in arg &&\n typeof arg.load === \"function\" &&\n \"loadAndSplit\" in arg &&\n typeof arg.loadAndSplit === \"function\"\n ) {\n return true;\n }\n return false;\n};\n\ninterface IndexArgs {\n docsSource: BaseDocumentLoader | DocumentInterface[];\n recordManager: RecordManagerInterface;\n vectorStore: VectorStore;\n options?: IndexOptions;\n}\n\n/**\n * Index data from the doc source into the vector store.\n *\n * Indexing functionality uses a manager to keep track of which documents\n * are in the vector store.\n *\n * This allows us to keep track of which documents were updated, and which\n * documents were deleted, which documents should be skipped.\n *\n * For the time being, documents are indexed using their hashes, and users\n * are not able to specify the uid of the document.\n *\n * @param {IndexArgs} args\n * @param {BaseDocumentLoader | DocumentInterface[]} args.docsSource The source of documents to index. Can be a DocumentLoader or a list of Documents.\n * @param {RecordManagerInterface} args.recordManager The record manager to use for keeping track of indexed documents.\n * @param {VectorStore} args.vectorStore The vector store to use for storing the documents.\n * @param {IndexOptions | undefined} args.options Options for indexing.\n * @returns {Promise<IndexingResult>}\n */\nexport async function index(args: IndexArgs): Promise<IndexingResult> {\n const { docsSource, recordManager, vectorStore, options } = args;\n const {\n batchSize = 100,\n cleanup,\n sourceIdKey,\n cleanupBatchSize = 1000,\n forceUpdate = false,\n } = options ?? {};\n\n if (cleanup === \"incremental\" && !sourceIdKey) {\n throw new Error(\n \"sourceIdKey is required when cleanup mode is incremental. Please provide through 'options.sourceIdKey'.\"\n );\n }\n\n const docs = _isBaseDocumentLoader(docsSource)\n ? await docsSource.load()\n : docsSource;\n\n const sourceIdAssigner = _getSourceIdAssigner(sourceIdKey ?? null);\n\n const indexStartDt = await recordManager.getTime();\n let numAdded = 0;\n let numDeleted = 0;\n let numUpdated = 0;\n let numSkipped = 0;\n\n const batches = _batch<DocumentInterface>(batchSize ?? 100, docs);\n\n for (const batch of batches) {\n const hashedDocs = _deduplicateInOrder(\n batch.map((doc) => _HashedDocument.fromDocument(doc))\n );\n\n const sourceIds = hashedDocs.map((doc) => sourceIdAssigner(doc));\n\n if (cleanup === \"incremental\") {\n hashedDocs.forEach((_hashedDoc, index) => {\n const source = sourceIds[index];\n if (source === null) {\n throw new Error(\n \"sourceIdKey must be provided when cleanup is incremental\"\n );\n }\n });\n }\n\n const batchExists = await recordManager.exists(\n hashedDocs.map((doc) => doc.uid)\n );\n\n const uids: string[] = [];\n const docsToIndex: DocumentInterface[] = [];\n const docsToUpdate: string[] = [];\n const seenDocs = new Set<string>();\n hashedDocs.forEach((hashedDoc, i) => {\n const docExists = batchExists[i];\n if (docExists) {\n if (forceUpdate) {\n seenDocs.add(hashedDoc.uid);\n } else {\n docsToUpdate.push(hashedDoc.uid);\n return;\n }\n }\n uids.push(hashedDoc.uid);\n docsToIndex.push(hashedDoc.toDocument());\n });\n\n if (docsToUpdate.length > 0) {\n await recordManager.update(docsToUpdate, { timeAtLeast: indexStartDt });\n numSkipped += docsToUpdate.length;\n }\n\n if (docsToIndex.length > 0) {\n await vectorStore.addDocuments(docsToIndex, { ids: uids });\n numAdded += docsToIndex.length - seenDocs.size;\n numUpdated += seenDocs.size;\n }\n\n await recordManager.update(\n hashedDocs.map((doc) => doc.uid),\n { timeAtLeast: indexStartDt, groupIds: sourceIds }\n );\n\n if (cleanup === \"incremental\") {\n sourceIds.forEach((sourceId) => {\n if (!sourceId) throw new Error(\"Source id cannot be null\");\n });\n const uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n groupIds: sourceIds,\n });\n\n if (uidsToDelete.length > 0) {\n await vectorStore.delete({ ids: uidsToDelete });\n await recordManager.deleteKeys(uidsToDelete);\n numDeleted += uidsToDelete.length;\n }\n }\n }\n\n if (cleanup === \"full\") {\n let uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n limit: cleanupBatchSize,\n });\n while (uidsToDelete.length > 0) {\n await vectorStore.delete({ ids: uidsToDelete });\n await recordManager.deleteKeys(uidsToDelete);\n numDeleted += uidsToDelete.length;\n uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n limit: cleanupBatchSize,\n });\n }\n }\n\n return {\n numAdded,\n numDeleted,\n numUpdated,\n numSkipped,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAwCA,IAAa,kBAAb,MAAgE;CAC9D;CAEA;CAEA;CAEA;CAEA;CAEA;CAKA,AAAQ,aAA6B;CAErC,YAAYA,QAA4B;EACtC,KAAK,MAAM,OAAO;EAClB,KAAK,cAAc,OAAO;EAC1B,KAAK,WAAW,OAAO;CACxB;CAED,sBAAsBC,cAAoC;EACxD,KAAK,aAAa;CACnB;CAED,kBAAwB;EACtB,MAAM,gBAAgB;GAAC;GAAS;GAAgB;EAAgB;AAEhE,OAAK,MAAM,OAAO,cAChB,KAAI,OAAO,KAAK,SACd,OAAM,IAAI,MACR,CAAC,4BAA4B,EAAE,IAAI,uDAAuD,EAAE,cAAc,KACxG,KACD,CAAC,CAAC,CAAC;EAKV,MAAM,cAAc,KAAK,kBAAkB,KAAK,YAAY;AAE5D,MAAI;GACF,MAAM,eAAe,KAAK,sBAAsB,KAAK,SAAS;GAC9D,KAAK,cAAc;GACnB,KAAK,eAAe;EACrB,SAAQ,GAAG;AACV,SAAM,IAAI,MACR,CAAC,yBAAyB,EAAE,EAAE,sDAAsD,CAAC;EAExF;EAED,KAAK,QAAQ,KAAK,kBAAkB,KAAK,cAAc,KAAK,aAAa;AAEzE,MAAI,CAAC,KAAK,KACR,KAAK,MAAM,KAAK;CAEnB;CAED,aAAgC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OAAO;GACR,EAAC;EACH;CACF;AAED,QAAO;EACL;EACA;EACA;EACA;CACD;AACF"}
|
|
1
|
+
{"version":3,"file":"base.js","names":["fields: HashedDocumentArgs","keyEncoderFn: HashKeyEncoder","document: DocumentInterface","uid?: string","inputString: string","uuidv5","data: Record<string, unknown>","size: number","iterable: T[]","batches: T[][]","currentBatch: T[]","hashedDocuments: HashedDocumentInterface[]","deduplicated: HashedDocumentInterface[]","sourceIdKey: StringOrDocFunc | null","_doc: DocumentInterface","doc: DocumentInterface","arg: any","args: IndexArgs","index","uids: string[]","docsToIndex: DocumentInterface[]","docsToUpdate: string[]"],"sources":["../../src/indexing/base.ts"],"sourcesContent":["import { v5 as uuidv5 } from \"uuid\";\nimport { VectorStore } from \"../vectorstores.js\";\nimport { RecordManagerInterface, UUIDV5_NAMESPACE } from \"./record_manager.js\";\nimport { sha256, type HashKeyEncoder } from \"../utils/hash.js\";\nimport { DocumentInterface, Document } from \"../documents/document.js\";\nimport { BaseDocumentLoader } from \"../document_loaders/base.js\";\n\ntype Metadata = Record<string, unknown>;\n\ntype IndexingResult = {\n numAdded: number;\n numDeleted: number;\n numUpdated: number;\n numSkipped: number;\n};\n\ntype StringOrDocFunc = string | ((doc: DocumentInterface) => string);\n\nexport interface HashedDocumentInterface extends DocumentInterface {\n uid: string;\n hash_?: string;\n contentHash?: string;\n metadataHash?: string;\n pageContent: string;\n metadata: Metadata;\n calculateHashes(): void;\n toDocument(): DocumentInterface;\n}\n\ninterface HashedDocumentArgs {\n pageContent: string;\n metadata: Metadata;\n uid: string;\n}\n\n/**\n * HashedDocument is a Document with hashes calculated.\n * Hashes are calculated based on page content and metadata.\n * It is used for indexing.\n */\nexport class _HashedDocument implements HashedDocumentInterface {\n uid: string;\n\n hash_?: string;\n\n contentHash?: string;\n\n metadataHash?: string;\n\n pageContent: string;\n\n metadata: Metadata;\n\n private keyEncoder: HashKeyEncoder = sha256;\n\n constructor(fields: HashedDocumentArgs) {\n this.uid = fields.uid;\n this.pageContent = fields.pageContent;\n this.metadata = fields.metadata;\n }\n\n makeDefaultKeyEncoder(keyEncoderFn: HashKeyEncoder): void {\n this.keyEncoder = keyEncoderFn;\n }\n\n calculateHashes(): void {\n const forbiddenKeys = [\"hash_\", \"content_hash\", \"metadata_hash\"];\n\n for (const key of forbiddenKeys) {\n if (key in this.metadata) {\n throw new Error(\n `Metadata cannot contain key ${key} as it is reserved for internal use. Restricted keys: [${forbiddenKeys.join(\n \", \"\n )}]`\n );\n }\n }\n\n const contentHash = this._hashStringToUUID(this.pageContent);\n\n try {\n const metadataHash = this._hashNestedDictToUUID(this.metadata);\n this.contentHash = contentHash;\n this.metadataHash = metadataHash;\n } catch (e) {\n throw new Error(\n `Failed to hash metadata: ${e}. Please use a dict that can be serialized using json.`\n );\n }\n\n this.hash_ = this._hashStringToUUID(this.contentHash + this.metadataHash);\n\n if (!this.uid) {\n this.uid = this.hash_;\n }\n }\n\n toDocument(): DocumentInterface {\n return new Document({\n pageContent: this.pageContent,\n metadata: this.metadata,\n });\n }\n\n static fromDocument(\n document: DocumentInterface,\n uid?: string\n ): _HashedDocument {\n const doc = new this({\n pageContent: document.pageContent,\n metadata: document.metadata,\n uid: uid || (document as DocumentInterface & { uid: string }).uid,\n });\n doc.calculateHashes();\n return doc;\n }\n\n private _hashStringToUUID(inputString: string): string {\n const hash_value = this.keyEncoder(inputString);\n return uuidv5(hash_value, UUIDV5_NAMESPACE);\n }\n\n private _hashNestedDictToUUID(data: Record<string, unknown>): string {\n const serialized_data = JSON.stringify(data, Object.keys(data).sort());\n const hash_value = this.keyEncoder(serialized_data);\n return uuidv5(hash_value, UUIDV5_NAMESPACE);\n }\n}\n\nexport type CleanupMode = \"full\" | \"incremental\";\n\nexport type IndexOptions = {\n /**\n * The number of documents to index in one batch.\n */\n batchSize?: number;\n /**\n * The cleanup mode to use. Can be \"full\", \"incremental\" or undefined.\n * - **Incremental**: Cleans up all documents that haven't been updated AND\n * that are associated with source ids that were seen\n * during indexing.\n * Clean up is done continuously during indexing helping\n * to minimize the probability of users seeing duplicated\n * content.\n * - **Full**: Delete all documents that haven to been returned by the loader.\n * Clean up runs after all documents have been indexed.\n * This means that users may see duplicated content during indexing.\n * - **undefined**: Do not delete any documents.\n */\n cleanup?: CleanupMode;\n /**\n * Optional key that helps identify the original source of the document.\n * Must either be a string representing the key of the source in the metadata\n * or a function that takes a document and returns a string representing the source.\n * **Required when cleanup is incremental**.\n */\n sourceIdKey?: StringOrDocFunc;\n /**\n * Batch size to use when cleaning up documents.\n */\n cleanupBatchSize?: number;\n /**\n * Force update documents even if they are present in the\n * record manager. Useful if you are re-indexing with updated embeddings.\n */\n forceUpdate?: boolean;\n};\n\nexport function _batch<T>(size: number, iterable: T[]): T[][] {\n const batches: T[][] = [];\n let currentBatch: T[] = [];\n\n iterable.forEach((item) => {\n currentBatch.push(item);\n\n if (currentBatch.length >= size) {\n batches.push(currentBatch);\n currentBatch = [];\n }\n });\n\n if (currentBatch.length > 0) {\n batches.push(currentBatch);\n }\n\n return batches;\n}\n\nexport function _deduplicateInOrder(\n hashedDocuments: HashedDocumentInterface[]\n): HashedDocumentInterface[] {\n const seen = new Set<string>();\n const deduplicated: HashedDocumentInterface[] = [];\n\n for (const hashedDoc of hashedDocuments) {\n if (!hashedDoc.hash_) {\n throw new Error(\"Hashed document does not have a hash\");\n }\n\n if (!seen.has(hashedDoc.hash_)) {\n seen.add(hashedDoc.hash_);\n deduplicated.push(hashedDoc);\n }\n }\n return deduplicated;\n}\n\nexport function _getSourceIdAssigner(\n sourceIdKey: StringOrDocFunc | null\n): (doc: DocumentInterface) => string | null {\n if (sourceIdKey === null) {\n return (_doc: DocumentInterface) => null;\n } else if (typeof sourceIdKey === \"string\") {\n return (doc: DocumentInterface) => doc.metadata[sourceIdKey];\n } else if (typeof sourceIdKey === \"function\") {\n return sourceIdKey;\n } else {\n throw new Error(\n `sourceIdKey should be null, a string or a function, got ${typeof sourceIdKey}`\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const _isBaseDocumentLoader = (arg: any): arg is BaseDocumentLoader => {\n if (\n \"load\" in arg &&\n typeof arg.load === \"function\" &&\n \"loadAndSplit\" in arg &&\n typeof arg.loadAndSplit === \"function\"\n ) {\n return true;\n }\n return false;\n};\n\ninterface IndexArgs {\n docsSource: BaseDocumentLoader | DocumentInterface[];\n recordManager: RecordManagerInterface;\n vectorStore: VectorStore;\n options?: IndexOptions;\n}\n\n/**\n * Index data from the doc source into the vector store.\n *\n * Indexing functionality uses a manager to keep track of which documents\n * are in the vector store.\n *\n * This allows us to keep track of which documents were updated, and which\n * documents were deleted, which documents should be skipped.\n *\n * For the time being, documents are indexed using their hashes, and users\n * are not able to specify the uid of the document.\n *\n * @param {IndexArgs} args\n * @param {BaseDocumentLoader | DocumentInterface[]} args.docsSource The source of documents to index. Can be a DocumentLoader or a list of Documents.\n * @param {RecordManagerInterface} args.recordManager The record manager to use for keeping track of indexed documents.\n * @param {VectorStore} args.vectorStore The vector store to use for storing the documents.\n * @param {IndexOptions | undefined} args.options Options for indexing.\n * @returns {Promise<IndexingResult>}\n */\nexport async function index(args: IndexArgs): Promise<IndexingResult> {\n const { docsSource, recordManager, vectorStore, options } = args;\n const {\n batchSize = 100,\n cleanup,\n sourceIdKey,\n cleanupBatchSize = 1000,\n forceUpdate = false,\n } = options ?? {};\n\n if (cleanup === \"incremental\" && !sourceIdKey) {\n throw new Error(\n \"sourceIdKey is required when cleanup mode is incremental. Please provide through 'options.sourceIdKey'.\"\n );\n }\n\n const docs = _isBaseDocumentLoader(docsSource)\n ? await docsSource.load()\n : docsSource;\n\n const sourceIdAssigner = _getSourceIdAssigner(sourceIdKey ?? null);\n\n const indexStartDt = await recordManager.getTime();\n let numAdded = 0;\n let numDeleted = 0;\n let numUpdated = 0;\n let numSkipped = 0;\n\n const batches = _batch<DocumentInterface>(batchSize ?? 100, docs);\n\n for (const batch of batches) {\n const hashedDocs = _deduplicateInOrder(\n batch.map((doc) => _HashedDocument.fromDocument(doc))\n );\n\n const sourceIds = hashedDocs.map((doc) => sourceIdAssigner(doc));\n\n if (cleanup === \"incremental\") {\n hashedDocs.forEach((_hashedDoc, index) => {\n const source = sourceIds[index];\n if (source === null) {\n throw new Error(\n \"sourceIdKey must be provided when cleanup is incremental\"\n );\n }\n });\n }\n\n const batchExists = await recordManager.exists(\n hashedDocs.map((doc) => doc.uid)\n );\n\n const uids: string[] = [];\n const docsToIndex: DocumentInterface[] = [];\n const docsToUpdate: string[] = [];\n const seenDocs = new Set<string>();\n hashedDocs.forEach((hashedDoc, i) => {\n const docExists = batchExists[i];\n if (docExists) {\n if (forceUpdate) {\n seenDocs.add(hashedDoc.uid);\n } else {\n docsToUpdate.push(hashedDoc.uid);\n return;\n }\n }\n uids.push(hashedDoc.uid);\n docsToIndex.push(hashedDoc.toDocument());\n });\n\n if (docsToUpdate.length > 0) {\n await recordManager.update(docsToUpdate, { timeAtLeast: indexStartDt });\n numSkipped += docsToUpdate.length;\n }\n\n if (docsToIndex.length > 0) {\n await vectorStore.addDocuments(docsToIndex, { ids: uids });\n numAdded += docsToIndex.length - seenDocs.size;\n numUpdated += seenDocs.size;\n }\n\n await recordManager.update(\n hashedDocs.map((doc) => doc.uid),\n { timeAtLeast: indexStartDt, groupIds: sourceIds }\n );\n\n if (cleanup === \"incremental\") {\n sourceIds.forEach((sourceId) => {\n if (!sourceId) throw new Error(\"Source id cannot be null\");\n });\n const uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n groupIds: sourceIds,\n });\n\n if (uidsToDelete.length > 0) {\n await vectorStore.delete({ ids: uidsToDelete });\n await recordManager.deleteKeys(uidsToDelete);\n numDeleted += uidsToDelete.length;\n }\n }\n }\n\n if (cleanup === \"full\") {\n let uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n limit: cleanupBatchSize,\n });\n while (uidsToDelete.length > 0) {\n await vectorStore.delete({ ids: uidsToDelete });\n await recordManager.deleteKeys(uidsToDelete);\n numDeleted += uidsToDelete.length;\n uidsToDelete = await recordManager.listKeys({\n before: indexStartDt,\n limit: cleanupBatchSize,\n });\n }\n }\n\n return {\n numAdded,\n numDeleted,\n numUpdated,\n numSkipped,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAwCA,IAAa,kBAAb,MAAgE;CAC9D;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA,AAAQ,aAA6B;CAErC,YAAYA,QAA4B;EACtC,KAAK,MAAM,OAAO;EAClB,KAAK,cAAc,OAAO;EAC1B,KAAK,WAAW,OAAO;CACxB;CAED,sBAAsBC,cAAoC;EACxD,KAAK,aAAa;CACnB;CAED,kBAAwB;EACtB,MAAM,gBAAgB;GAAC;GAAS;GAAgB;EAAgB;AAEhE,OAAK,MAAM,OAAO,cAChB,KAAI,OAAO,KAAK,SACd,OAAM,IAAI,MACR,CAAC,4BAA4B,EAAE,IAAI,uDAAuD,EAAE,cAAc,KACxG,KACD,CAAC,CAAC,CAAC;EAKV,MAAM,cAAc,KAAK,kBAAkB,KAAK,YAAY;AAE5D,MAAI;GACF,MAAM,eAAe,KAAK,sBAAsB,KAAK,SAAS;GAC9D,KAAK,cAAc;GACnB,KAAK,eAAe;EACrB,SAAQ,GAAG;AACV,SAAM,IAAI,MACR,CAAC,yBAAyB,EAAE,EAAE,sDAAsD,CAAC;EAExF;EAED,KAAK,QAAQ,KAAK,kBAAkB,KAAK,cAAc,KAAK,aAAa;AAEzE,MAAI,CAAC,KAAK,KACR,KAAK,MAAM,KAAK;CAEnB;CAED,aAAgC;AAC9B,SAAO,IAAI,SAAS;GAClB,aAAa,KAAK;GAClB,UAAU,KAAK;EAChB;CACF;CAED,OAAO,aACLC,UACAC,KACiB;EACjB,MAAM,MAAM,IAAI,KAAK;GACnB,aAAa,SAAS;GACtB,UAAU,SAAS;GACnB,KAAK,OAAQ,SAAiD;EAC/D;EACD,IAAI,iBAAiB;AACrB,SAAO;CACR;CAED,AAAQ,kBAAkBC,aAA6B;EACrD,MAAM,aAAa,KAAK,WAAW,Y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,GAAG;GAC3B,MAAM,cAAc,OAAO,cAAc,EAAE,aAAa,aAAc,EAAC;GACvE,cAAc,aAAa;EAC5B;AAED,MAAI,YAAY,SAAS,GAAG;GAC1B,MAAM,YAAY,aAAa,aAAa,EAAE,KAAK,KAAM,EAAC;GAC1D,YAAY,YAAY,SAAS,SAAS;GAC1C,cAAc,SAAS;EACxB;EAED,MAAM,cAAc,OAClB,WAAW,IAAI,CAAC,QAAQ,IAAI,IAAI,EAChC;GAAE,aAAa;GAAc,UAAU;EAAW,EACnD;AAED,MAAI,YAAY,eAAe;GAC7B,UAAU,QAAQ,CAAC,aAAa;AAC9B,QAAI,CAAC,SAAU,OAAM,IAAI,MAAM;GAChC,EAAC;GACF,MAAM,eAAe,MAAM,cAAc,SAAS;IAChD,QAAQ;IACR,UAAU;GACX,EAAC;AAEF,OAAI,aAAa,SAAS,GAAG;IAC3B,MAAM,YAAY,OAAO,EAAE,KAAK,aAAc,EAAC;IAC/C,MAAM,cAAc,WAAW,aAAa;IAC5C,cAAc,aAAa;GAC5B;EACF;CACF;AAED,KAAI,YAAY,QAAQ;EACtB,IAAI,eAAe,MAAM,cAAc,SAAS;GAC9C,QAAQ;GACR,OAAO;EACR,EAAC;AACF,SAAO,aAAa,SAAS,GAAG;GAC9B,MAAM,YAAY,OAAO,EAAE,KAAK,aAAc,EAAC;GAC/C,MAAM,cAAc,WAAW,aAAa;GAC5C,cAAc,aAAa;GAC3B,eAAe,MAAM,cAAc,SAAS;IAC1C,QAAQ;IACR,OAAO;GACR,EAAC;EACH;CACF;AAED,QAAO;EACL;EACA;EACA;EACA;CACD;AACF"}
|
|
@@ -60,7 +60,7 @@ const calculateMaxTokens = async ({ prompt, modelName }) => {
|
|
|
60
60
|
let numTokens;
|
|
61
61
|
try {
|
|
62
62
|
numTokens = (await require_utils_tiktoken.encodingForModel(getModelNameForTiktoken(modelName))).encode(prompt).length;
|
|
63
|
-
} catch
|
|
63
|
+
} catch {
|
|
64
64
|
console.warn("Failed to calculate number of tokens, falling back to approximate count");
|
|
65
65
|
numTokens = Math.ceil(prompt.length / 4);
|
|
66
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.cjs","names":["modelName: string","modelName?: string","tool: unknown","encodingForModel","Runnable","params: BaseLangChainParams","InMemoryCache","AsyncCaller","content: MessageContent","textContent: string","input: BaseLanguageModelInput","StringPromptValue","ChatPromptValue","coerceMessageLikeToMessage","params: Record<string, any>","_data: SerializedLLM"],"sources":["../../src/language_models/base.ts"],"sourcesContent":["import type { Tiktoken, TiktokenModel } from \"js-tiktoken/lite\";\nimport type { ZodType as ZodTypeV3 } from \"zod/v3\";\nimport type { $ZodType as ZodTypeV4 } from \"zod/v4/core\";\n\nimport { type BaseCache, InMemoryCache } from \"../caches/base.js\";\nimport {\n type BasePromptValueInterface,\n StringPromptValue,\n ChatPromptValue,\n} from \"../prompt_values.js\";\nimport {\n type BaseMessage,\n type BaseMessageLike,\n type MessageContent,\n} from \"../messages/base.js\";\nimport { coerceMessageLikeToMessage } from \"../messages/utils.js\";\nimport { type LLMResult } from \"../outputs.js\";\nimport { CallbackManager, Callbacks } from \"../callbacks/manager.js\";\nimport { AsyncCaller, AsyncCallerParams } from \"../utils/async_caller.js\";\nimport { encodingForModel } from \"../utils/tiktoken.js\";\nimport { Runnable, type RunnableInterface } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport {\n InferInteropZodOutput,\n InteropZodObject,\n InteropZodType,\n} from \"../utils/types/zod.js\";\n\n// https://www.npmjs.com/package/js-tiktoken\n\nexport const getModelNameForTiktoken = (modelName: string): TiktokenModel => {\n if (modelName.startsWith(\"gpt-3.5-turbo-16k\")) {\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (modelName.startsWith(\"gpt-3.5-turbo-\")) {\n return \"gpt-3.5-turbo\";\n }\n\n if (modelName.startsWith(\"gpt-4-32k\")) {\n return \"gpt-4-32k\";\n }\n\n if (modelName.startsWith(\"gpt-4-\")) {\n return \"gpt-4\";\n }\n\n if (modelName.startsWith(\"gpt-4o\")) {\n return \"gpt-4o\";\n }\n\n return modelName as TiktokenModel;\n};\n\nexport const getEmbeddingContextSize = (modelName?: string): number => {\n switch (modelName) {\n case \"text-embedding-ada-002\":\n return 8191;\n default:\n return 2046;\n }\n};\n\nexport const getModelContextSize = (modelName: string): number => {\n switch (getModelNameForTiktoken(modelName)) {\n case \"gpt-3.5-turbo-16k\":\n return 16384;\n case \"gpt-3.5-turbo\":\n return 4096;\n case \"gpt-4-32k\":\n return 32768;\n case \"gpt-4\":\n return 8192;\n case \"text-davinci-003\":\n return 4097;\n case \"text-curie-001\":\n return 2048;\n case \"text-babbage-001\":\n return 2048;\n case \"text-ada-001\":\n return 2048;\n case \"code-davinci-002\":\n return 8000;\n case \"code-cushman-001\":\n return 2048;\n default:\n return 4097;\n }\n};\n\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 function isOpenAITool(tool: unknown): tool is ToolDefinition {\n if (typeof tool !== \"object\" || !tool) return false;\n if (\n \"type\" in tool &&\n tool.type === \"function\" &&\n \"function\" in tool &&\n typeof tool.function === \"object\" &&\n tool.function &&\n \"name\" in tool.function &&\n \"parameters\" in tool.function\n ) {\n return true;\n }\n return false;\n}\n\ninterface CalculateMaxTokenProps {\n prompt: string;\n modelName: TiktokenModel;\n}\n\nexport const calculateMaxTokens = async ({\n prompt,\n modelName,\n}: CalculateMaxTokenProps) => {\n let numTokens;\n\n try {\n numTokens = (\n await encodingForModel(getModelNameForTiktoken(modelName))\n ).encode(prompt).length;\n } catch (error) {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\"\n );\n\n // fallback to approximate calculation if tiktoken is not available\n // each token is ~4 characters: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them#\n numTokens = Math.ceil(prompt.length / 4);\n }\n\n const maxTokens = getModelContextSize(modelName);\n return maxTokens - numTokens;\n};\n\nconst getVerbosity = () => false;\n\nexport type SerializedLLM = {\n _model: string;\n _type: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport interface BaseLangChainParams {\n verbose?: boolean;\n callbacks?: Callbacks;\n tags?: string[];\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Base class for language models, chains, tools.\n */\nexport abstract class BaseLangChain<\n RunInput,\n RunOutput,\n CallOptions extends RunnableConfig = RunnableConfig\n >\n extends Runnable<RunInput, RunOutput, CallOptions>\n implements BaseLangChainParams\n{\n /**\n * Whether to print out response text.\n */\n verbose: boolean;\n\n callbacks?: Callbacks;\n\n tags?: string[];\n\n metadata?: Record<string, unknown>;\n\n get lc_attributes(): { [key: string]: undefined } | undefined {\n return {\n callbacks: undefined,\n verbose: undefined,\n };\n }\n\n constructor(params: BaseLangChainParams) {\n super(params);\n this.verbose = params.verbose ?? getVerbosity();\n this.callbacks = params.callbacks;\n this.tags = params.tags ?? [];\n this.metadata = params.metadata ?? {};\n }\n}\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\n extends AsyncCallerParams,\n BaseLangChainParams {\n /**\n * @deprecated Use `callbacks` instead\n */\n callbackManager?: CallbackManager;\n\n cache?: BaseCache | boolean;\n}\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: { method: string };\n /**\n * The JSON schema describing the expected output structure.\n */\n schema?: JSONSchema;\n };\n}\n\nexport interface BaseLanguageModelCallOptions\n extends RunnableConfig,\n 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}\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 /**\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 /**\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}\n\nexport interface ToolDefinition {\n type: \"function\";\n function: FunctionDefinition;\n}\n\nexport type FunctionCallOption = {\n name: string;\n};\n\nexport interface BaseFunctionCallOptions extends BaseLanguageModelCallOptions {\n function_call?: FunctionCallOption;\n functions?: FunctionDefinition[];\n}\n\nexport type BaseLanguageModelInput =\n | BasePromptValueInterface\n | string\n | BaseMessageLike[];\n\nexport type StructuredOutputType = InferInteropZodOutput<InteropZodObject>;\n\nexport type StructuredOutputMethodOptions<IncludeRaw extends boolean = false> =\n {\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\n/** @deprecated Use StructuredOutputMethodOptions instead */\nexport type StructuredOutputMethodParams<\n RunOutput,\n IncludeRaw extends boolean = false\n> = {\n /** @deprecated Pass schema in as the first argument */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\n\nexport interface BaseLanguageModelInterface<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions\n> extends RunnableInterface<BaseLanguageModelInput, RunOutput, CallOptions> {\n get callKeys(): string[];\n\n generatePrompt(\n promptValues: BasePromptValueInterface[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<LLMResult>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(\n text: string,\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<string>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(\n messages: BaseMessage[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<BaseMessage>;\n\n _modelType(): string;\n\n _llmType(): string;\n\n getNumTokens(content: MessageContent): Promise<number>;\n\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _identifyingParams(): Record<string, any>;\n\n serialize(): SerializedLLM;\n}\n\nexport type LanguageModelOutput = BaseMessage | string;\n\nexport type LanguageModelLike = Runnable<\n BaseLanguageModelInput,\n LanguageModelOutput\n>;\n\n/**\n * Base class for language models.\n */\nexport abstract class BaseLanguageModel<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions\n >\n extends BaseLangChain<BaseLanguageModelInput, RunOutput, CallOptions>\n implements\n BaseLanguageModelParams,\n BaseLanguageModelInterface<RunOutput, CallOptions>\n{\n /**\n * Keys that the language model accepts as call options.\n */\n get callKeys(): string[] {\n return [\"stop\", \"timeout\", \"signal\", \"tags\", \"metadata\", \"callbacks\"];\n }\n\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\n cache?: BaseCache;\n\n constructor({\n callbacks,\n callbackManager,\n ...params\n }: BaseLanguageModelParams) {\n const { cache, ...rest } = params;\n super({\n callbacks: callbacks ?? callbackManager,\n ...rest,\n });\n if (typeof cache === \"object\") {\n this.cache = cache;\n } else if (cache) {\n this.cache = InMemoryCache.global();\n } else {\n this.cache = undefined;\n }\n this.caller = new AsyncCaller(params ?? {});\n }\n\n abstract generatePrompt(\n promptValues: BasePromptValueInterface[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<LLMResult>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(\n text: string,\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<string>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(\n messages: BaseMessage[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<BaseMessage>;\n\n abstract _modelType(): string;\n\n abstract _llmType(): string;\n\n private _encoding?: Tiktoken;\n\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 async getNumTokens(content: MessageContent) {\n // Extract text content from MessageContent\n let textContent: string;\n if (typeof content === \"string\") {\n textContent = content;\n } else {\n /**\n * Content is an array of ContentBlock\n *\n * ToDo(@christian-bromann): This is a temporary fix to get the number of tokens for the content.\n * We need to find a better way to do this.\n * @see https://github.com/langchain-ai/langchainjs/pull/8341#pullrequestreview-2933713116\n */\n textContent = content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item.type === \"text\" && \"text\" in item) return item.text;\n return \"\";\n })\n .join(\"\");\n }\n\n // fallback to approximate calculation if tiktoken is not available\n let numTokens = Math.ceil(textContent.length / 4);\n\n if (!this._encoding) {\n try {\n this._encoding = await encodingForModel(\n \"modelName\" in this\n ? getModelNameForTiktoken(this.modelName as string)\n : \"gpt2\"\n );\n } catch (error) {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\",\n error\n );\n }\n }\n\n if (this._encoding) {\n try {\n numTokens = this._encoding.encode(textContent).length;\n } catch (error) {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\",\n error\n );\n }\n }\n\n return numTokens;\n }\n\n protected static _convertInputToPromptValue(\n input: BaseLanguageModelInput\n ): BasePromptValueInterface {\n if (typeof input === \"string\") {\n return new StringPromptValue(input);\n } else if (Array.isArray(input)) {\n return new ChatPromptValue(input.map(coerceMessageLikeToMessage));\n } else {\n return input;\n }\n }\n\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _identifyingParams(): Record<string, any> {\n return {};\n }\n\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { config, ...callOptions }: CallOptions & { config?: RunnableConfig }\n ): string {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const params: Record<string, any> = {\n ...this._identifyingParams(),\n ...callOptions,\n _type: this._llmType(),\n _model: this._modelType(),\n };\n const filteredEntries = Object.entries(params).filter(\n ([_, value]) => value !== undefined\n );\n const serializedEntries = filteredEntries\n .map(([key, value]) => `${key}:${JSON.stringify(value)}`)\n .sort()\n .join(\",\");\n return serializedEntries;\n }\n\n /**\n * @deprecated\n * Return a json-like object representing this LLM.\n */\n serialize(): SerializedLLM {\n return {\n ...this._identifyingParams(),\n _type: this._llmType(),\n _model: this._modelType(),\n };\n }\n\n /**\n * @deprecated\n * Load an LLM from a json-like object describing it.\n */\n static async deserialize(_data: SerializedLLM): Promise<BaseLanguageModel> {\n throw new Error(\"Use .toJSON() instead\");\n }\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<false>\n ): Runnable<BaseLanguageModelInput, RunOutput>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<true>\n ): Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<false>\n ): Runnable<BaseLanguageModelInput, RunOutput>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<true>\n ): Runnable<BaseLanguageModelInput, { raw: BaseMessage; 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<\n BaseLanguageModelInput,\n {\n raw: BaseMessage;\n parsed: RunOutput;\n }\n >;\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}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,MAAa,0BAA0B,CAACA,cAAqC;AAC3E,KAAI,UAAU,WAAW,oBAAoB,CAC3C,QAAO;AAGT,KAAI,UAAU,WAAW,iBAAiB,CACxC,QAAO;AAGT,KAAI,UAAU,WAAW,YAAY,CACnC,QAAO;AAGT,KAAI,UAAU,WAAW,SAAS,CAChC,QAAO;AAGT,KAAI,UAAU,WAAW,SAAS,CAChC,QAAO;AAGT,QAAO;AACR;AAED,MAAa,0BAA0B,CAACC,cAA+B;AACrE,SAAQ,WAAR;EACE,KAAK,yBACH,QAAO;EACT,QACE,QAAO;CACV;AACF;AAED,MAAa,sBAAsB,CAACD,cAA8B;AAChE,SAAQ,wBAAwB,UAAU,EAA1C;EACE,KAAK,oBACH,QAAO;EACT,KAAK,gBACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,iBACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,eACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,QACE,QAAO;CACV;AACF;;;;;;AAOD,SAAgB,aAAaE,MAAuC;AAClE,KAAI,OAAO,SAAS,YAAY,CAAC,KAAM,QAAO;AAC9C,KACE,UAAU,QACV,KAAK,SAAS,cACd,cAAc,QACd,OAAO,KAAK,aAAa,YACzB,KAAK,YACL,UAAU,KAAK,YACf,gBAAgB,KAAK,SAErB,QAAO;AAET,QAAO;AACR;AAOD,MAAa,qBAAqB,OAAO,EACvC,QACA,WACuB,KAAK;CAC5B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
1
|
+
{"version":3,"file":"base.cjs","names":["modelName: string","modelName?: string","tool: unknown","encodingForModel","Runnable","params: BaseLangChainParams","InMemoryCache","AsyncCaller","content: MessageContent","textContent: string","input: BaseLanguageModelInput","StringPromptValue","ChatPromptValue","coerceMessageLikeToMessage","params: Record<string, any>","_data: SerializedLLM"],"sources":["../../src/language_models/base.ts"],"sourcesContent":["import type { Tiktoken, TiktokenModel } from \"js-tiktoken/lite\";\nimport type { ZodType as ZodTypeV3 } from \"zod/v3\";\nimport type { $ZodType as ZodTypeV4 } from \"zod/v4/core\";\n\nimport { type BaseCache, InMemoryCache } from \"../caches/base.js\";\nimport {\n type BasePromptValueInterface,\n StringPromptValue,\n ChatPromptValue,\n} from \"../prompt_values.js\";\nimport {\n type BaseMessage,\n type BaseMessageLike,\n type MessageContent,\n} from \"../messages/base.js\";\nimport { coerceMessageLikeToMessage } from \"../messages/utils.js\";\nimport { type LLMResult } from \"../outputs.js\";\nimport { CallbackManager, Callbacks } from \"../callbacks/manager.js\";\nimport { AsyncCaller, AsyncCallerParams } from \"../utils/async_caller.js\";\nimport { encodingForModel } from \"../utils/tiktoken.js\";\nimport { Runnable, type RunnableInterface } from \"../runnables/base.js\";\nimport { RunnableConfig } from \"../runnables/config.js\";\nimport { JSONSchema } from \"../utils/json_schema.js\";\nimport {\n InferInteropZodOutput,\n InteropZodObject,\n InteropZodType,\n} from \"../utils/types/zod.js\";\n\n// https://www.npmjs.com/package/js-tiktoken\n\nexport const getModelNameForTiktoken = (modelName: string): TiktokenModel => {\n if (modelName.startsWith(\"gpt-3.5-turbo-16k\")) {\n return \"gpt-3.5-turbo-16k\";\n }\n\n if (modelName.startsWith(\"gpt-3.5-turbo-\")) {\n return \"gpt-3.5-turbo\";\n }\n\n if (modelName.startsWith(\"gpt-4-32k\")) {\n return \"gpt-4-32k\";\n }\n\n if (modelName.startsWith(\"gpt-4-\")) {\n return \"gpt-4\";\n }\n\n if (modelName.startsWith(\"gpt-4o\")) {\n return \"gpt-4o\";\n }\n\n return modelName as TiktokenModel;\n};\n\nexport const getEmbeddingContextSize = (modelName?: string): number => {\n switch (modelName) {\n case \"text-embedding-ada-002\":\n return 8191;\n default:\n return 2046;\n }\n};\n\nexport const getModelContextSize = (modelName: string): number => {\n switch (getModelNameForTiktoken(modelName)) {\n case \"gpt-3.5-turbo-16k\":\n return 16384;\n case \"gpt-3.5-turbo\":\n return 4096;\n case \"gpt-4-32k\":\n return 32768;\n case \"gpt-4\":\n return 8192;\n case \"text-davinci-003\":\n return 4097;\n case \"text-curie-001\":\n return 2048;\n case \"text-babbage-001\":\n return 2048;\n case \"text-ada-001\":\n return 2048;\n case \"code-davinci-002\":\n return 8000;\n case \"code-cushman-001\":\n return 2048;\n default:\n return 4097;\n }\n};\n\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 function isOpenAITool(tool: unknown): tool is ToolDefinition {\n if (typeof tool !== \"object\" || !tool) return false;\n if (\n \"type\" in tool &&\n tool.type === \"function\" &&\n \"function\" in tool &&\n typeof tool.function === \"object\" &&\n tool.function &&\n \"name\" in tool.function &&\n \"parameters\" in tool.function\n ) {\n return true;\n }\n return false;\n}\n\ninterface CalculateMaxTokenProps {\n prompt: string;\n modelName: TiktokenModel;\n}\n\nexport const calculateMaxTokens = async ({\n prompt,\n modelName,\n}: CalculateMaxTokenProps) => {\n let numTokens;\n\n try {\n numTokens = (\n await encodingForModel(getModelNameForTiktoken(modelName))\n ).encode(prompt).length;\n } catch {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\"\n );\n\n // fallback to approximate calculation if tiktoken is not available\n // each token is ~4 characters: https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them#\n numTokens = Math.ceil(prompt.length / 4);\n }\n\n const maxTokens = getModelContextSize(modelName);\n return maxTokens - numTokens;\n};\n\nconst getVerbosity = () => false;\n\nexport type SerializedLLM = {\n _model: string;\n _type: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport interface BaseLangChainParams {\n verbose?: boolean;\n callbacks?: Callbacks;\n tags?: string[];\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Base class for language models, chains, tools.\n */\nexport abstract class BaseLangChain<\n RunInput,\n RunOutput,\n CallOptions extends RunnableConfig = RunnableConfig\n >\n extends Runnable<RunInput, RunOutput, CallOptions>\n implements BaseLangChainParams\n{\n /**\n * Whether to print out response text.\n */\n verbose: boolean;\n\n callbacks?: Callbacks;\n\n tags?: string[];\n\n metadata?: Record<string, unknown>;\n\n get lc_attributes(): { [key: string]: undefined } | undefined {\n return {\n callbacks: undefined,\n verbose: undefined,\n };\n }\n\n constructor(params: BaseLangChainParams) {\n super(params);\n this.verbose = params.verbose ?? getVerbosity();\n this.callbacks = params.callbacks;\n this.tags = params.tags ?? [];\n this.metadata = params.metadata ?? {};\n }\n}\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\n extends AsyncCallerParams,\n BaseLangChainParams {\n /**\n * @deprecated Use `callbacks` instead\n */\n callbackManager?: CallbackManager;\n\n cache?: BaseCache | boolean;\n}\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: { method: string };\n /**\n * The JSON schema describing the expected output structure.\n */\n schema?: JSONSchema;\n };\n}\n\nexport interface BaseLanguageModelCallOptions\n extends RunnableConfig,\n 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}\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 /**\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 /**\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}\n\nexport interface ToolDefinition {\n type: \"function\";\n function: FunctionDefinition;\n}\n\nexport type FunctionCallOption = {\n name: string;\n};\n\nexport interface BaseFunctionCallOptions extends BaseLanguageModelCallOptions {\n function_call?: FunctionCallOption;\n functions?: FunctionDefinition[];\n}\n\nexport type BaseLanguageModelInput =\n | BasePromptValueInterface\n | string\n | BaseMessageLike[];\n\nexport type StructuredOutputType = InferInteropZodOutput<InteropZodObject>;\n\nexport type StructuredOutputMethodOptions<IncludeRaw extends boolean = false> =\n {\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\n/** @deprecated Use StructuredOutputMethodOptions instead */\nexport type StructuredOutputMethodParams<\n RunOutput,\n IncludeRaw extends boolean = false\n> = {\n /** @deprecated Pass schema in as the first argument */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\n\nexport interface BaseLanguageModelInterface<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions\n> extends RunnableInterface<BaseLanguageModelInput, RunOutput, CallOptions> {\n get callKeys(): string[];\n\n generatePrompt(\n promptValues: BasePromptValueInterface[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<LLMResult>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(\n text: string,\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<string>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(\n messages: BaseMessage[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<BaseMessage>;\n\n _modelType(): string;\n\n _llmType(): string;\n\n getNumTokens(content: MessageContent): Promise<number>;\n\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _identifyingParams(): Record<string, any>;\n\n serialize(): SerializedLLM;\n}\n\nexport type LanguageModelOutput = BaseMessage | string;\n\nexport type LanguageModelLike = Runnable<\n BaseLanguageModelInput,\n LanguageModelOutput\n>;\n\n/**\n * Base class for language models.\n */\nexport abstract class BaseLanguageModel<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions\n >\n extends BaseLangChain<BaseLanguageModelInput, RunOutput, CallOptions>\n implements\n BaseLanguageModelParams,\n BaseLanguageModelInterface<RunOutput, CallOptions>\n{\n /**\n * Keys that the language model accepts as call options.\n */\n get callKeys(): string[] {\n return [\"stop\", \"timeout\", \"signal\", \"tags\", \"metadata\", \"callbacks\"];\n }\n\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\n cache?: BaseCache;\n\n constructor({\n callbacks,\n callbackManager,\n ...params\n }: BaseLanguageModelParams) {\n const { cache, ...rest } = params;\n super({\n callbacks: callbacks ?? callbackManager,\n ...rest,\n });\n if (typeof cache === \"object\") {\n this.cache = cache;\n } else if (cache) {\n this.cache = InMemoryCache.global();\n } else {\n this.cache = undefined;\n }\n this.caller = new AsyncCaller(params ?? {});\n }\n\n abstract generatePrompt(\n promptValues: BasePromptValueInterface[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<LLMResult>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(\n text: string,\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<string>;\n\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(\n messages: BaseMessage[],\n options?: string[] | CallOptions,\n callbacks?: Callbacks\n ): Promise<BaseMessage>;\n\n abstract _modelType(): string;\n\n abstract _llmType(): string;\n\n private _encoding?: Tiktoken;\n\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 async getNumTokens(content: MessageContent) {\n // Extract text content from MessageContent\n let textContent: string;\n if (typeof content === \"string\") {\n textContent = content;\n } else {\n /**\n * Content is an array of ContentBlock\n *\n * ToDo(@christian-bromann): This is a temporary fix to get the number of tokens for the content.\n * We need to find a better way to do this.\n * @see https://github.com/langchain-ai/langchainjs/pull/8341#pullrequestreview-2933713116\n */\n textContent = content\n .map((item) => {\n if (typeof item === \"string\") return item;\n if (item.type === \"text\" && \"text\" in item) return item.text;\n return \"\";\n })\n .join(\"\");\n }\n\n // fallback to approximate calculation if tiktoken is not available\n let numTokens = Math.ceil(textContent.length / 4);\n\n if (!this._encoding) {\n try {\n this._encoding = await encodingForModel(\n \"modelName\" in this\n ? getModelNameForTiktoken(this.modelName as string)\n : \"gpt2\"\n );\n } catch (error) {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\",\n error\n );\n }\n }\n\n if (this._encoding) {\n try {\n numTokens = this._encoding.encode(textContent).length;\n } catch (error) {\n console.warn(\n \"Failed to calculate number of tokens, falling back to approximate count\",\n error\n );\n }\n }\n\n return numTokens;\n }\n\n protected static _convertInputToPromptValue(\n input: BaseLanguageModelInput\n ): BasePromptValueInterface {\n if (typeof input === \"string\") {\n return new StringPromptValue(input);\n } else if (Array.isArray(input)) {\n return new ChatPromptValue(input.map(coerceMessageLikeToMessage));\n } else {\n return input;\n }\n }\n\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _identifyingParams(): Record<string, any> {\n return {};\n }\n\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { config, ...callOptions }: CallOptions & { config?: RunnableConfig }\n ): string {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const params: Record<string, any> = {\n ...this._identifyingParams(),\n ...callOptions,\n _type: this._llmType(),\n _model: this._modelType(),\n };\n const filteredEntries = Object.entries(params).filter(\n ([_, value]) => value !== undefined\n );\n const serializedEntries = filteredEntries\n .map(([key, value]) => `${key}:${JSON.stringify(value)}`)\n .sort()\n .join(\",\");\n return serializedEntries;\n }\n\n /**\n * @deprecated\n * Return a json-like object representing this LLM.\n */\n serialize(): SerializedLLM {\n return {\n ...this._identifyingParams(),\n _type: this._llmType(),\n _model: this._modelType(),\n };\n }\n\n /**\n * @deprecated\n * Load an LLM from a json-like object describing it.\n */\n static async deserialize(_data: SerializedLLM): Promise<BaseLanguageModel> {\n throw new Error(\"Use .toJSON() instead\");\n }\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<false>\n ): Runnable<BaseLanguageModelInput, RunOutput>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<true>\n ): Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<false>\n ): Runnable<BaseLanguageModelInput, RunOutput>;\n\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<true>\n ): Runnable<BaseLanguageModelInput, { raw: BaseMessage; 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>\n >(\n schema:\n | InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>,\n config?: StructuredOutputMethodOptions<boolean>\n ):\n | Runnable<BaseLanguageModelInput, RunOutput>\n | Runnable<\n BaseLanguageModelInput,\n {\n raw: BaseMessage;\n parsed: RunOutput;\n }\n >;\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}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+BA,MAAa,0BAA0B,CAACA,cAAqC;AAC3E,KAAI,UAAU,WAAW,oBAAoB,CAC3C,QAAO;AAGT,KAAI,UAAU,WAAW,iBAAiB,CACxC,QAAO;AAGT,KAAI,UAAU,WAAW,YAAY,CACnC,QAAO;AAGT,KAAI,UAAU,WAAW,SAAS,CAChC,QAAO;AAGT,KAAI,UAAU,WAAW,SAAS,CAChC,QAAO;AAGT,QAAO;AACR;AAED,MAAa,0BAA0B,CAACC,cAA+B;AACrE,SAAQ,WAAR;EACE,KAAK,yBACH,QAAO;EACT,QACE,QAAO;CACV;AACF;AAED,MAAa,sBAAsB,CAACD,cAA8B;AAChE,SAAQ,wBAAwB,UAAU,EAA1C;EACE,KAAK,oBACH,QAAO;EACT,KAAK,gBACH,QAAO;EACT,KAAK,YACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,iBACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,eACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,KAAK,mBACH,QAAO;EACT,QACE,QAAO;CACV;AACF;;;;;;AAOD,SAAgB,aAAaE,MAAuC;AAClE,KAAI,OAAO,SAAS,YAAY,CAAC,KAAM,QAAO;AAC9C,KACE,UAAU,QACV,KAAK,SAAS,cACd,cAAc,QACd,OAAO,KAAK,aAAa,YACzB,KAAK,YACL,UAAU,KAAK,YACf,gBAAgB,KAAK,SAErB,QAAO;AAET,QAAO;AACR;AAOD,MAAa,qBAAqB,OAAO,EACvC,QACA,WACuB,KAAK;CAC5B,IAAI;AAEJ,KAAI;EACF,aACE,MAAMC,wCAAiB,wBAAwB,UAAU,CAAC,EAC1D,OAAO,OAAO,CAAC;CAClB,QAAO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, BaseMessageLike, MessageContent } from "../messages/base.cjs";
|
|
3
2
|
import { LLMResult } from "../outputs.cjs";
|
|
4
3
|
import { BaseCache } from "../caches/base.cjs";
|
|
4
|
+
import { InferInteropZodOutput, InteropZodObject, InteropZodType } from "../utils/types/zod.cjs";
|
|
5
5
|
import { CallbackManager, Callbacks } from "../callbacks/manager.cjs";
|
|
6
6
|
import { RunnableConfig, RunnableInterface } from "../runnables/types.cjs";
|
|
7
7
|
import { Runnable } from "../runnables/base.cjs";
|
|
8
8
|
import { BasePromptValueInterface } from "../prompt_values.cjs";
|
|
9
9
|
import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.cjs";
|
|
10
|
-
import {
|
|
10
|
+
import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.cjs";
|
|
11
11
|
import { ZodType } from "zod/v3";
|
|
12
12
|
import { $ZodType } from "zod/v4/core";
|
|
13
13
|
import { TiktokenModel } from "js-tiktoken/lite";
|
|
@@ -84,7 +84,7 @@ interface BaseLanguageModelTracingCallOptions {
|
|
|
84
84
|
/**
|
|
85
85
|
* The JSON schema describing the expected output structure.
|
|
86
86
|
*/
|
|
87
|
-
schema?:
|
|
87
|
+
schema?: JsonSchema7Type;
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
interface BaseLanguageModelCallOptions extends RunnableConfig, BaseLanguageModelTracingCallOptions {
|
|
@@ -110,7 +110,7 @@ interface FunctionDefinition {
|
|
|
110
110
|
* To describe a function that accepts no parameters, provide the value
|
|
111
111
|
* `{"type": "object", "properties": {}}`.
|
|
112
112
|
*/
|
|
113
|
-
parameters: Record<string, unknown> |
|
|
113
|
+
parameters: Record<string, unknown> | JsonSchema7Type;
|
|
114
114
|
/**
|
|
115
115
|
* A description of what the function does, used by the model to choose when and
|
|
116
116
|
* how to call the function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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","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/base.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\";\n// https://www.npmjs.com/package/js-tiktoken\nexport declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;\nexport declare const getEmbeddingContextSize: (modelName?: string | undefined) => number;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\nexport interface BaseLanguageModelInterface<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\n _modelType(): string;\n _llmType(): string;\n getNumTokens(content: MessageContent): Promise<number>;\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { 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 withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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"],"mappings":";;;;;;;;;;;;;;;;cAcqBsB,gDAAgDtB;AAAhDsB,cACAC,uBADgDvB,EAAAA,CAAAA,SAAa,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,GAAA,MAAA;AAC7DuB,cACAC,mBADmE,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACxF;AAMA;AAA4E;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A;EAAQ;;;;;EAnGiC,uCAA4DwB;EAAuB;EAA4B;IAAA,MAAA;IAAA,GAAA;GAAA,EA2CtMD,WA3CsM,GAAA;IA4GrNmB,MAAAA,CAAAA,EAhEAxC,cAgEU;;;;;;eA1DVe;;;;;4BAKaA,gBAAgBD,QAAQsB;;;oBAGhCpB,sBAAsBA,6BAA6B/B,QAAUmC;;IAE5EJ,8BAA8Bc,uCAAuChC,SAAS8B,wBAAwBR;;;oBAGvFJ,sBAAsBA,6BAA6B/B,QAAUmC;;IAE5EJ,8BAA8Bc,sCAAsChC,SAAS8B;SACvEtC;YACG8B;;;;oBAIMJ,sBAAsBA,6BAA6B7B,SAAUiC;;IAE5EJ,8BAA8Bc,uCAAuChC,SAAS8B,wBAAwBR;;;oBAGvFJ,sBAAsBA,6BAA6B7B,SAAUiC;;IAE5EJ,8BAA8Bc,sCAAsChC,SAAS8B;SACvEtC;YACG8B;;;;;;;;;;;;;;;;;oBAiBMJ,sBAAsBA,6BAA6BZ,eAAegB;;IAEjFJ,8BAA8Bc,yCAAyChC,SAAS8B,wBAAwBR,aAAatB,SAAS8B;SACxHtC;YACG8B;;;;;;;UAOCoB,UAAAA"}
|
|
1
|
+
{"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","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/base.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\";\n// https://www.npmjs.com/package/js-tiktoken\nexport declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;\nexport declare const getEmbeddingContextSize: (modelName?: string | undefined) => number;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\nexport interface BaseLanguageModelInterface<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\n _modelType(): string;\n _llmType(): string;\n getNumTokens(content: MessageContent): Promise<number>;\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { 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 withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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"],"mappings":";;;;;;;;;;;;;;;;cAcqBsB,gDAAgDtB;AAAhDsB,cACAC,uBADgDvB,EAAAA,CAAAA,SAAa,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,GAAA,MAAA;AAC7DuB,cACAC,mBADmE,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACxF;AAMA;AAA4E;AAK5E;;AAA4CK,iBALpBJ,YAAAA,CAKoBI,IAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA,IALiBH,cAKjBG;UAJlCF,sBAAAA,CAI0CG;EAAS,MAAKH,EAAAA,MAAAA;EAAsB,SAAKI,EAF9E/B,aAE8E+B;AAAO;AACxFC,cADSJ,kBAIX,EAAA,CAAA;EAAA,MAAA;EAAA;AAAA,CAAA,EAJwDD,sBAIxD,EAAA,GAJmFI,OAInF,CAAA,MAAA,CAAA;AACOG,KAJLF,aAAAA,GAIwB;EAAA,MAAA,EAAA,MAAA;EAAA,KAEpBpB,EAAAA,MAAAA;CAAS,GAHrBqB,MA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SAAUiC;;IAE5EJ,8BAA8Bc,uCAAuChC,SAAS8B,wBAAwBR;;;oBAGvFJ,sBAAsBA,6BAA6B7B,SAAUiC;;IAE5EJ,8BAA8Bc,sCAAsChC,SAAS8B;SACvEtC;YACG8B;;;;;;;;;;;;;;;;;oBAiBMJ,sBAAsBA,6BAA6BZ,eAAegB;;IAEjFJ,8BAA8Bc,yCAAyChC,SAAS8B,wBAAwBR,aAAatB,SAAS8B;SACxHtC;YACG8B;;;;;;;UAOCoB,UAAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { InferInteropZodOutput, InteropZodObject, InteropZodType } from "../utils/types/zod.js";
|
|
2
1
|
import { BaseMessage, BaseMessageLike, MessageContent } from "../messages/base.js";
|
|
3
2
|
import { LLMResult } from "../outputs.js";
|
|
4
3
|
import { BaseCache } from "../caches/base.js";
|
|
4
|
+
import { InferInteropZodOutput, InteropZodObject, InteropZodType } from "../utils/types/zod.js";
|
|
5
5
|
import { CallbackManager, Callbacks } from "../callbacks/manager.js";
|
|
6
6
|
import { RunnableConfig, RunnableInterface } from "../runnables/types.js";
|
|
7
7
|
import { Runnable } from "../runnables/base.js";
|
|
8
8
|
import { BasePromptValueInterface } from "../prompt_values.js";
|
|
9
9
|
import { AsyncCaller, AsyncCallerParams } from "../utils/async_caller.js";
|
|
10
|
-
import {
|
|
10
|
+
import { JsonSchema7Type } from "../utils/zod-to-json-schema/parseTypes.js";
|
|
11
11
|
import { ZodType } from "zod/v3";
|
|
12
12
|
import { $ZodType } from "zod/v4/core";
|
|
13
13
|
import { TiktokenModel } from "js-tiktoken/lite";
|
|
@@ -84,7 +84,7 @@ interface BaseLanguageModelTracingCallOptions {
|
|
|
84
84
|
/**
|
|
85
85
|
* The JSON schema describing the expected output structure.
|
|
86
86
|
*/
|
|
87
|
-
schema?:
|
|
87
|
+
schema?: JsonSchema7Type;
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
interface BaseLanguageModelCallOptions extends RunnableConfig, BaseLanguageModelTracingCallOptions {
|
|
@@ -110,7 +110,7 @@ interface FunctionDefinition {
|
|
|
110
110
|
* To describe a function that accepts no parameters, provide the value
|
|
111
111
|
* `{"type": "object", "properties": {}}`.
|
|
112
112
|
*/
|
|
113
|
-
parameters: Record<string, unknown> |
|
|
113
|
+
parameters: Record<string, unknown> | JsonSchema7Type;
|
|
114
114
|
/**
|
|
115
115
|
* A description of what the function does, used by the model to choose when and
|
|
116
116
|
* how to call the function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","names":["TiktokenModel","ZodType","ZodTypeV3","$ZodType","ZodTypeV4","BaseCache","BasePromptValueInterface","BaseMessage","BaseMessageLike","MessageContent","LLMResult","CallbackManager","Callbacks","AsyncCaller","AsyncCallerParams","Runnable","RunnableInterface","RunnableConfig","JSONSchema","InferInteropZodOutput","InteropZodObject","InteropZodType","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/base.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\";\n// https://www.npmjs.com/package/js-tiktoken\nexport declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;\nexport declare const getEmbeddingContextSize: (modelName?: string | undefined) => number;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\nexport interface BaseLanguageModelInterface<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\n _modelType(): string;\n _llmType(): string;\n getNumTokens(content: MessageContent): Promise<number>;\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { 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 withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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"],"mappings":";;;;;;;;;;;;;;;;cAcqBsB,gDAAgDtB;AAAhDsB,cACAC,uBADgDvB,EAAAA,CAAAA,SAAa,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,GAAA,MAAA;AAC7DuB,cACAC,mBADmE,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACxF;AAMA;AAA4E;AAK5E;;AAA4CK,iBALpBJ,YAAAA,CAKoBI,IAAAA,EAAAA,OAAAA,CAAAA,EAAAA,IAAAA,IALiBH,cAKjBG;UAJlCF,sBAAAA,CAI0CG;EAAS,MAAKH,EAAAA,MAAAA;EAAsB,SAAKI,EAF9E/B,aAE8E+B;AAAO;AACxFC,cADSJ,kBAIX,EAAA,CAAA;EAAA,MAAA;EAAA;AAAA,CAAA,EAJwDD,sBAIxD,EAAA,GAJmFI,OAInF,CAAA,MAAA,CAAA;AACOG,KAJLF,aAAAA,GAIwB;EAAA,MAAA,EAAA,MAAA;EAAA,KAEpBpB,EAAAA,MAAAA;CAAS,GAHrBqB,MAKWA,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;AAAM,UAJJC,mBAAAA,CAII;EAKSC,OAAAA,CAAAA,EAAAA,OAAa;EAAA,SAAA,CAAA,EAP3BvB,SAO2B;EAAA,IAA0CK,CAAAA,EAAAA,MAAAA,EAAAA;EAAc,QAAGA,CAAAA,EALvFgB,MAKuFhB,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;;AAOvFgB,uBAPeE,aAOfF,CAAAA,QAAAA,EAAAA,SAAAA,EAAAA,oBAPsEhB,cAOtEgB,GAPuFhB,cAOvFgB,CAAAA,SAP+GlB,QAO/GkB,CAPwHG,QAOxHH,EAPkII,SA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ueInterface","BaseMessage","BaseMessageLike","MessageContent","LLMResult","CallbackManager","Callbacks","AsyncCaller","AsyncCallerParams","Runnable","RunnableInterface","RunnableConfig","JSONSchema","InferInteropZodOutput","InteropZodObject","InteropZodType","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/base.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\";\n// https://www.npmjs.com/package/js-tiktoken\nexport declare const getModelNameForTiktoken: (modelName: string) => TiktokenModel;\nexport declare const getEmbeddingContextSize: (modelName?: string | undefined) => number;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<RunOutput> | Record<string, any>;\n name?: string;\n method?: \"functionCalling\" | \"jsonMode\";\n includeRaw?: IncludeRaw;\n};\nexport interface BaseLanguageModelInterface<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\n _modelType(): string;\n _llmType(): string;\n getNumTokens(content: MessageContent): Promise<number>;\n /**\n * Get the identifying parameters of the LLM.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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<\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nRunOutput = 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 /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predict(text: string, options?: string[] | CallOptions, callbacks?: Callbacks): Promise<string>;\n /**\n * @deprecated Use .invoke() instead. Will be removed in 0.2.0.\n */\n abstract predictMessages(messages: BaseMessage[], options?: string[] | CallOptions, callbacks?: Callbacks): Promise<BaseMessage>;\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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(\n // TODO: Fix when we remove the RunnableLambda backwards compatibility shim.\n { 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 withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV3<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {\n raw: BaseMessage;\n parsed: RunOutput;\n }>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;\n withStructuredOutput?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: ZodTypeV4<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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?<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput extends Record<string, any> = Record<string, any>>(schema: InteropZodType<RunOutput>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | 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"],"mappings":";;;;;;;;;;;;;;;;cAcqBsB,gDAAgDtB;AAAhDsB,cACAC,uBADgDvB,EAAAA,CAAAA,SAAa,CAAA,EAAA,MAAA,GAAA,SAAA,EAAA,GAAA,MAAA;AAC7DuB,cACAC,mBADmE,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,GAAA,MAAA;AACxF;AAMA;AAA4E;AAK5E;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;;;;;EAnGiC,uCAA4DwB;EAAuB;EAA4B;IAAA,MAAA;IAAA,GAAA;GAAA,EA2CtMD,WA3CsM,GAAA;IA4GrNmB,MAAAA,CAAAA,EAhEAxC,cAgEU;;;;;;eA1DVe;;;;;4BAKaA,gBAAgBD,QAAQsB;;;oBAGhCpB,sBAAsBA,6BAA6B/B,QAAUmC;;IAE5EJ,8BAA8Bc,uCAAuChC,SAAS8B,wBAAwBR;;;oBAGvFJ,sBAAsBA,6BAA6B/B,QAAUmC;;IAE5EJ,8BAA8Bc,sCAAsChC,SAAS8B;SACvEtC;YACG8B;;;;oBAIMJ,sBAAsBA,6BAA6B7B,SAAUiC;;IAE5EJ,8BAA8Bc,uCAAuChC,SAAS8B,wBAAwBR;;;oBAGvFJ,sBAAsBA,6BAA6B7B,SAAUiC;;IAE5EJ,8BAA8Bc,sCAAsChC,SAAS8B;SACvEtC;YACG8B;;;;;;;;;;;;;;;;;oBAiBMJ,sBAAsBA,6BAA6BZ,eAAegB;;IAEjFJ,8BAA8Bc,yCAAyChC,SAAS8B,wBAAwBR,aAAatB,SAAS8B;SACxHtC;YACG8B;;;;;;;UAOCoB,UAAAA"}
|
|
@@ -60,7 +60,7 @@ const calculateMaxTokens = async ({ prompt, modelName }) => {
|
|
|
60
60
|
let numTokens;
|
|
61
61
|
try {
|
|
62
62
|
numTokens = (await encodingForModel(getModelNameForTiktoken(modelName))).encode(prompt).length;
|
|
63
|
-
} catch
|
|
63
|
+
} catch {
|
|
64
64
|
console.warn("Failed to calculate number of tokens, falling back to approximate count");
|
|
65
65
|
numTokens = Math.ceil(prompt.length / 4);
|
|
66
66
|
}
|