langchain 0.0.195 → 0.0.197-rc.0
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/LICENSE +21 -0
- package/dist/agents/openai/index.cjs +6 -2
- package/dist/agents/openai/index.js +6 -2
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/anthropic.cjs +15 -348
- package/dist/chat_models/anthropic.d.ts +1 -156
- package/dist/chat_models/anthropic.js +1 -346
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.cjs +21 -1
- package/dist/chat_models/bedrock/web.d.ts +2 -2
- package/dist/chat_models/bedrock/web.js +21 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/github.cjs +105 -0
- package/dist/document_loaders/web/github.d.ts +26 -0
- package/dist/document_loaders/web/github.js +105 -0
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.cjs +21 -1
- package/dist/llms/bedrock/web.d.ts +2 -2
- package/dist/llms/bedrock/web.js +21 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/list.cjs +4 -122
- package/dist/output_parsers/list.d.ts +1 -57
- package/dist/output_parsers/list.js +1 -119
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +13 -477
- package/dist/prompts/chat.d.ts +2 -219
- package/dist/prompts/chat.js +2 -466
- package/dist/prompts/few_shot.cjs +3 -352
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +2 -141
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +2 -145
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +2 -147
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +5 -73
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/template.cjs +8 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/momento_vector_index.cjs +39 -0
- package/dist/vectorstores/momento_vector_index.d.ts +17 -1
- package/dist/vectorstores/momento_vector_index.js +40 -1
- package/dist/vectorstores/mongodb_atlas.cjs +22 -2
- package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
- package/dist/vectorstores/mongodb_atlas.js +22 -2
- package/package.json +18 -11
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,76 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isChatModel = exports.isLLM = exports.ConditionalPromptSelector = exports.BasePromptSelector = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Asynchronous version of `getPrompt` that also accepts an options object
|
|
11
|
-
* for partial variables.
|
|
12
|
-
* @param llm The language model for which to get a prompt.
|
|
13
|
-
* @param options Optional object for partial variables.
|
|
14
|
-
* @returns A Promise that resolves to a prompt template.
|
|
15
|
-
*/
|
|
16
|
-
async getPromptAsync(llm, options) {
|
|
17
|
-
const prompt = this.getPrompt(llm);
|
|
18
|
-
return prompt.partial(options?.partialVariables ?? {});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.BasePromptSelector = BasePromptSelector;
|
|
22
|
-
/**
|
|
23
|
-
* Concrete implementation of `BasePromptSelector` that selects a prompt
|
|
24
|
-
* based on a set of conditions. It has a default prompt that it returns
|
|
25
|
-
* if none of the conditions are met.
|
|
26
|
-
*/
|
|
27
|
-
class ConditionalPromptSelector extends BasePromptSelector {
|
|
28
|
-
constructor(default_prompt, conditionals = []) {
|
|
29
|
-
super();
|
|
30
|
-
Object.defineProperty(this, "defaultPrompt", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "conditionals", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
this.defaultPrompt = default_prompt;
|
|
43
|
-
this.conditionals = conditionals;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Method that selects a prompt based on a set of conditions. If none of
|
|
47
|
-
* the conditions are met, it returns the default prompt.
|
|
48
|
-
* @param llm The language model for which to get a prompt.
|
|
49
|
-
* @returns A prompt template.
|
|
50
|
-
*/
|
|
51
|
-
getPrompt(llm) {
|
|
52
|
-
for (const [condition, prompt] of this.conditionals) {
|
|
53
|
-
if (condition(llm)) {
|
|
54
|
-
return prompt;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return this.defaultPrompt;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.ConditionalPromptSelector = ConditionalPromptSelector;
|
|
61
|
-
/**
|
|
62
|
-
* Type guard function that checks if a given language model is of type
|
|
63
|
-
* `BaseLLM`.
|
|
64
|
-
*/
|
|
65
|
-
function isLLM(llm) {
|
|
66
|
-
return llm._modelType() === "base_llm";
|
|
67
|
-
}
|
|
68
|
-
exports.isLLM = isLLM;
|
|
69
|
-
/**
|
|
70
|
-
* Type guard function that checks if a given language model is of type
|
|
71
|
-
* `BaseChatModel`.
|
|
72
|
-
*/
|
|
73
|
-
function isChatModel(llm) {
|
|
74
|
-
return llm._modelType() === "base_chat_model";
|
|
75
|
-
}
|
|
76
|
-
exports.isChatModel = isChatModel;
|
|
4
|
+
var example_selectors_1 = require("langchain-core/example_selectors");
|
|
5
|
+
Object.defineProperty(exports, "BasePromptSelector", { enumerable: true, get: function () { return example_selectors_1.BasePromptSelector; } });
|
|
6
|
+
Object.defineProperty(exports, "ConditionalPromptSelector", { enumerable: true, get: function () { return example_selectors_1.ConditionalPromptSelector; } });
|
|
7
|
+
Object.defineProperty(exports, "isLLM", { enumerable: true, get: function () { return example_selectors_1.isLLM; } });
|
|
8
|
+
Object.defineProperty(exports, "isChatModel", { enumerable: true, get: function () { return example_selectors_1.isChatModel; } });
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BasePromptTemplate } from "../base.js";
|
|
3
|
-
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
4
|
-
import { BaseLLM } from "../../llms/base.js";
|
|
5
|
-
import { PartialValues } from "../../schema/index.js";
|
|
6
|
-
export type BaseGetPromptAsyncOptions = {
|
|
7
|
-
partialVariables?: PartialValues;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Abstract class that defines the interface for selecting a prompt for a
|
|
11
|
-
* given language model.
|
|
12
|
-
*/
|
|
13
|
-
export declare abstract class BasePromptSelector {
|
|
14
|
-
/**
|
|
15
|
-
* Abstract method that must be implemented by any class that extends
|
|
16
|
-
* `BasePromptSelector`. It takes a language model as an argument and
|
|
17
|
-
* returns a prompt template.
|
|
18
|
-
* @param llm The language model for which to get a prompt.
|
|
19
|
-
* @returns A prompt template.
|
|
20
|
-
*/
|
|
21
|
-
abstract getPrompt(llm: BaseLanguageModel): BasePromptTemplate;
|
|
22
|
-
/**
|
|
23
|
-
* Asynchronous version of `getPrompt` that also accepts an options object
|
|
24
|
-
* for partial variables.
|
|
25
|
-
* @param llm The language model for which to get a prompt.
|
|
26
|
-
* @param options Optional object for partial variables.
|
|
27
|
-
* @returns A Promise that resolves to a prompt template.
|
|
28
|
-
*/
|
|
29
|
-
getPromptAsync(llm: BaseLanguageModel, options?: BaseGetPromptAsyncOptions): Promise<BasePromptTemplate>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Concrete implementation of `BasePromptSelector` that selects a prompt
|
|
33
|
-
* based on a set of conditions. It has a default prompt that it returns
|
|
34
|
-
* if none of the conditions are met.
|
|
35
|
-
*/
|
|
36
|
-
export declare class ConditionalPromptSelector extends BasePromptSelector {
|
|
37
|
-
defaultPrompt: BasePromptTemplate;
|
|
38
|
-
conditionals: Array<[
|
|
39
|
-
condition: (llm: BaseLanguageModel) => boolean,
|
|
40
|
-
prompt: BasePromptTemplate
|
|
41
|
-
]>;
|
|
42
|
-
constructor(default_prompt: BasePromptTemplate, conditionals?: Array<[
|
|
43
|
-
condition: (llm: BaseLanguageModel) => boolean,
|
|
44
|
-
prompt: BasePromptTemplate
|
|
45
|
-
]>);
|
|
46
|
-
/**
|
|
47
|
-
* Method that selects a prompt based on a set of conditions. If none of
|
|
48
|
-
* the conditions are met, it returns the default prompt.
|
|
49
|
-
* @param llm The language model for which to get a prompt.
|
|
50
|
-
* @returns A prompt template.
|
|
51
|
-
*/
|
|
52
|
-
getPrompt(llm: BaseLanguageModel): BasePromptTemplate;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Type guard function that checks if a given language model is of type
|
|
56
|
-
* `BaseLLM`.
|
|
57
|
-
*/
|
|
58
|
-
export declare function isLLM(llm: BaseLanguageModel): llm is BaseLLM;
|
|
59
|
-
/**
|
|
60
|
-
* Type guard function that checks if a given language model is of type
|
|
61
|
-
* `BaseChatModel`.
|
|
62
|
-
*/
|
|
63
|
-
export declare function isChatModel(llm: BaseLanguageModel): llm is BaseChatModel;
|
|
1
|
+
export { type BaseGetPromptAsyncOptions, BasePromptSelector, ConditionalPromptSelector, isLLM, isChatModel, } from "langchain-core/example_selectors";
|
|
@@ -1,69 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Abstract class that defines the interface for selecting a prompt for a
|
|
3
|
-
* given language model.
|
|
4
|
-
*/
|
|
5
|
-
export class BasePromptSelector {
|
|
6
|
-
/**
|
|
7
|
-
* Asynchronous version of `getPrompt` that also accepts an options object
|
|
8
|
-
* for partial variables.
|
|
9
|
-
* @param llm The language model for which to get a prompt.
|
|
10
|
-
* @param options Optional object for partial variables.
|
|
11
|
-
* @returns A Promise that resolves to a prompt template.
|
|
12
|
-
*/
|
|
13
|
-
async getPromptAsync(llm, options) {
|
|
14
|
-
const prompt = this.getPrompt(llm);
|
|
15
|
-
return prompt.partial(options?.partialVariables ?? {});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Concrete implementation of `BasePromptSelector` that selects a prompt
|
|
20
|
-
* based on a set of conditions. It has a default prompt that it returns
|
|
21
|
-
* if none of the conditions are met.
|
|
22
|
-
*/
|
|
23
|
-
export class ConditionalPromptSelector extends BasePromptSelector {
|
|
24
|
-
constructor(default_prompt, conditionals = []) {
|
|
25
|
-
super();
|
|
26
|
-
Object.defineProperty(this, "defaultPrompt", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: void 0
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(this, "conditionals", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: void 0
|
|
37
|
-
});
|
|
38
|
-
this.defaultPrompt = default_prompt;
|
|
39
|
-
this.conditionals = conditionals;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Method that selects a prompt based on a set of conditions. If none of
|
|
43
|
-
* the conditions are met, it returns the default prompt.
|
|
44
|
-
* @param llm The language model for which to get a prompt.
|
|
45
|
-
* @returns A prompt template.
|
|
46
|
-
*/
|
|
47
|
-
getPrompt(llm) {
|
|
48
|
-
for (const [condition, prompt] of this.conditionals) {
|
|
49
|
-
if (condition(llm)) {
|
|
50
|
-
return prompt;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return this.defaultPrompt;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Type guard function that checks if a given language model is of type
|
|
58
|
-
* `BaseLLM`.
|
|
59
|
-
*/
|
|
60
|
-
export function isLLM(llm) {
|
|
61
|
-
return llm._modelType() === "base_llm";
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Type guard function that checks if a given language model is of type
|
|
65
|
-
* `BaseChatModel`.
|
|
66
|
-
*/
|
|
67
|
-
export function isChatModel(llm) {
|
|
68
|
-
return llm._modelType() === "base_chat_model";
|
|
69
|
-
}
|
|
1
|
+
export { BasePromptSelector, ConditionalPromptSelector, isLLM, isChatModel, } from "langchain-core/example_selectors";
|
package/dist/prompts/serde.d.ts
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { TemplateFormat } from "./template.js";
|
|
3
|
-
/**
|
|
4
|
-
* Represents a serialized version of a prompt template. This type is used
|
|
5
|
-
* to create dynamic prompts for language models. It contains an optional
|
|
6
|
-
* `_type` field which, if present, is set to 'prompt'. It also includes
|
|
7
|
-
* `input_variables`, an array of strings representing the variables to be
|
|
8
|
-
* used in the prompt, an optional `template_format` specifying the format
|
|
9
|
-
* of the template, and an optional `template` which is the actual
|
|
10
|
-
* template string.
|
|
11
|
-
*/
|
|
12
|
-
export type SerializedPromptTemplate = {
|
|
13
|
-
_type?: "prompt";
|
|
14
|
-
input_variables: string[];
|
|
15
|
-
template_format?: TemplateFormat;
|
|
16
|
-
template?: string;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Represents a serialized version of a few-shot template. This type
|
|
20
|
-
* includes an `_type` field set to 'few_shot', `input_variables` which
|
|
21
|
-
* are an array of strings representing the variables to be used in the
|
|
22
|
-
* template, `examples` which can be a string or an array of Example
|
|
23
|
-
* objects, an optional `example_prompt` which is a
|
|
24
|
-
* SerializedPromptTemplate, `example_separator` which is a string,
|
|
25
|
-
* optional `prefix` and `suffix` strings, and `template_format` which
|
|
26
|
-
* specifies the format of the template.
|
|
27
|
-
*/
|
|
28
|
-
export type SerializedFewShotTemplate = {
|
|
29
|
-
_type: "few_shot";
|
|
30
|
-
input_variables: string[];
|
|
31
|
-
examples: string | Example[];
|
|
32
|
-
example_prompt?: SerializedPromptTemplate;
|
|
33
|
-
example_separator: string;
|
|
34
|
-
prefix?: string;
|
|
35
|
-
suffix?: string;
|
|
36
|
-
template_format: TemplateFormat;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Represents a serialized version of a base prompt template. This type
|
|
40
|
-
* can be either a SerializedFewShotTemplate or a
|
|
41
|
-
* SerializedPromptTemplate.
|
|
42
|
-
*/
|
|
43
|
-
export type SerializedBasePromptTemplate = SerializedFewShotTemplate | SerializedPromptTemplate;
|
|
1
|
+
export { type SerializedPromptTemplate, type SerializedFewShotTemplate, type SerializedBasePromptTemplate, } from "langchain-core/prompts";
|
|
@@ -1,91 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkValidTemplate = exports.parseTemplate = exports.renderTemplate = exports.DEFAULT_PARSER_MAPPING = exports.DEFAULT_FORMATTER_MAPPING = exports.interpolateFString = exports.parseFString = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return i;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return -1;
|
|
16
|
-
};
|
|
17
|
-
let i = 0;
|
|
18
|
-
while (i < chars.length) {
|
|
19
|
-
if (chars[i] === "{" && i + 1 < chars.length && chars[i + 1] === "{") {
|
|
20
|
-
nodes.push({ type: "literal", text: "{" });
|
|
21
|
-
i += 2;
|
|
22
|
-
}
|
|
23
|
-
else if (chars[i] === "}" &&
|
|
24
|
-
i + 1 < chars.length &&
|
|
25
|
-
chars[i + 1] === "}") {
|
|
26
|
-
nodes.push({ type: "literal", text: "}" });
|
|
27
|
-
i += 2;
|
|
28
|
-
}
|
|
29
|
-
else if (chars[i] === "{") {
|
|
30
|
-
const j = nextBracket("}", i);
|
|
31
|
-
if (j < 0) {
|
|
32
|
-
throw new Error("Unclosed '{' in template.");
|
|
33
|
-
}
|
|
34
|
-
nodes.push({
|
|
35
|
-
type: "variable",
|
|
36
|
-
name: chars.slice(i + 1, j).join(""),
|
|
37
|
-
});
|
|
38
|
-
i = j + 1;
|
|
39
|
-
}
|
|
40
|
-
else if (chars[i] === "}") {
|
|
41
|
-
throw new Error("Single '}' in template.");
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const next = nextBracket("{}", i);
|
|
45
|
-
const text = (next < 0 ? chars.slice(i) : chars.slice(i, next)).join("");
|
|
46
|
-
nodes.push({ type: "literal", text });
|
|
47
|
-
i = next < 0 ? chars.length : next;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return nodes;
|
|
51
|
-
};
|
|
52
|
-
exports.parseFString = parseFString;
|
|
53
|
-
const interpolateFString = (template, values) => (0, exports.parseFString)(template).reduce((res, node) => {
|
|
54
|
-
if (node.type === "variable") {
|
|
55
|
-
if (node.name in values) {
|
|
56
|
-
return res + values[node.name];
|
|
57
|
-
}
|
|
58
|
-
throw new Error(`Missing value for input ${node.name}`);
|
|
59
|
-
}
|
|
60
|
-
return res + node.text;
|
|
61
|
-
}, "");
|
|
62
|
-
exports.interpolateFString = interpolateFString;
|
|
63
|
-
exports.DEFAULT_FORMATTER_MAPPING = {
|
|
64
|
-
"f-string": exports.interpolateFString,
|
|
65
|
-
};
|
|
66
|
-
exports.DEFAULT_PARSER_MAPPING = {
|
|
67
|
-
"f-string": exports.parseFString,
|
|
68
|
-
};
|
|
69
|
-
const renderTemplate = (template, templateFormat, inputValues) => exports.DEFAULT_FORMATTER_MAPPING[templateFormat](template, inputValues);
|
|
70
|
-
exports.renderTemplate = renderTemplate;
|
|
71
|
-
const parseTemplate = (template, templateFormat) => exports.DEFAULT_PARSER_MAPPING[templateFormat](template);
|
|
72
|
-
exports.parseTemplate = parseTemplate;
|
|
73
|
-
const checkValidTemplate = (template, templateFormat, inputVariables) => {
|
|
74
|
-
if (!(templateFormat in exports.DEFAULT_FORMATTER_MAPPING)) {
|
|
75
|
-
const validFormats = Object.keys(exports.DEFAULT_FORMATTER_MAPPING);
|
|
76
|
-
throw new Error(`Invalid template format. Got \`${templateFormat}\`;
|
|
77
|
-
should be one of ${validFormats}`);
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const dummyInputs = inputVariables.reduce((acc, v) => {
|
|
81
|
-
acc[v] = "foo";
|
|
82
|
-
return acc;
|
|
83
|
-
}, {});
|
|
84
|
-
(0, exports.renderTemplate)(template, templateFormat, dummyInputs);
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
throw new Error(`Invalid prompt schema: ${e.message}`);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
exports.checkValidTemplate = checkValidTemplate;
|
|
4
|
+
var prompts_1 = require("langchain-core/prompts");
|
|
5
|
+
Object.defineProperty(exports, "parseFString", { enumerable: true, get: function () { return prompts_1.parseFString; } });
|
|
6
|
+
Object.defineProperty(exports, "interpolateFString", { enumerable: true, get: function () { return prompts_1.interpolateFString; } });
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_FORMATTER_MAPPING", { enumerable: true, get: function () { return prompts_1.DEFAULT_FORMATTER_MAPPING; } });
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_PARSER_MAPPING", { enumerable: true, get: function () { return prompts_1.DEFAULT_PARSER_MAPPING; } });
|
|
9
|
+
Object.defineProperty(exports, "renderTemplate", { enumerable: true, get: function () { return prompts_1.renderTemplate; } });
|
|
10
|
+
Object.defineProperty(exports, "parseTemplate", { enumerable: true, get: function () { return prompts_1.parseTemplate; } });
|
|
11
|
+
Object.defineProperty(exports, "checkValidTemplate", { enumerable: true, get: function () { return prompts_1.checkValidTemplate; } });
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Type that specifies the format of a template. Only
|
|
4
|
-
* "f-string" is supported currently.
|
|
5
|
-
*/
|
|
6
|
-
export type TemplateFormat = "f-string";
|
|
7
|
-
/**
|
|
8
|
-
* Type that represents a node in a parsed format string. It can be either
|
|
9
|
-
* a literal text or a variable name.
|
|
10
|
-
*/
|
|
11
|
-
type ParsedFStringNode = {
|
|
12
|
-
type: "literal";
|
|
13
|
-
text: string;
|
|
14
|
-
} | {
|
|
15
|
-
type: "variable";
|
|
16
|
-
name: string;
|
|
17
|
-
};
|
|
18
|
-
export declare const parseFString: (template: string) => ParsedFStringNode[];
|
|
19
|
-
export declare const interpolateFString: (template: string, values: InputValues) => string;
|
|
20
|
-
/**
|
|
21
|
-
* Type that represents a function that takes a template string and a set
|
|
22
|
-
* of input values, and returns a string where all variables in the
|
|
23
|
-
* template have been replaced with their corresponding values.
|
|
24
|
-
*/
|
|
25
|
-
type Interpolator = (template: string, values: InputValues) => string;
|
|
26
|
-
/**
|
|
27
|
-
* Type that represents a function that takes a template string and
|
|
28
|
-
* returns an array of `ParsedFStringNode`.
|
|
29
|
-
*/
|
|
30
|
-
type Parser = (template: string) => ParsedFStringNode[];
|
|
31
|
-
export declare const DEFAULT_FORMATTER_MAPPING: Record<TemplateFormat, Interpolator>;
|
|
32
|
-
export declare const DEFAULT_PARSER_MAPPING: Record<TemplateFormat, Parser>;
|
|
33
|
-
export declare const renderTemplate: (template: string, templateFormat: TemplateFormat, inputValues: InputValues) => string;
|
|
34
|
-
export declare const parseTemplate: (template: string, templateFormat: TemplateFormat) => ParsedFStringNode[];
|
|
35
|
-
export declare const checkValidTemplate: (template: string, templateFormat: TemplateFormat, inputVariables: string[]) => void;
|
|
36
|
-
export {};
|
|
1
|
+
export { type TemplateFormat, parseFString, interpolateFString, DEFAULT_FORMATTER_MAPPING, DEFAULT_PARSER_MAPPING, renderTemplate, parseTemplate, checkValidTemplate, } from "langchain-core/prompts";
|
package/dist/prompts/template.js
CHANGED
|
@@ -1,83 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
// Core logic replicated from internals of pythons built in Formatter class.
|
|
3
|
-
// https://github.com/python/cpython/blob/135ec7cefbaffd516b77362ad2b2ad1025af462e/Objects/stringlib/unicode_format.h#L700-L706
|
|
4
|
-
const chars = template.split("");
|
|
5
|
-
const nodes = [];
|
|
6
|
-
const nextBracket = (bracket, start) => {
|
|
7
|
-
for (let i = start; i < chars.length; i += 1) {
|
|
8
|
-
if (bracket.includes(chars[i])) {
|
|
9
|
-
return i;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return -1;
|
|
13
|
-
};
|
|
14
|
-
let i = 0;
|
|
15
|
-
while (i < chars.length) {
|
|
16
|
-
if (chars[i] === "{" && i + 1 < chars.length && chars[i + 1] === "{") {
|
|
17
|
-
nodes.push({ type: "literal", text: "{" });
|
|
18
|
-
i += 2;
|
|
19
|
-
}
|
|
20
|
-
else if (chars[i] === "}" &&
|
|
21
|
-
i + 1 < chars.length &&
|
|
22
|
-
chars[i + 1] === "}") {
|
|
23
|
-
nodes.push({ type: "literal", text: "}" });
|
|
24
|
-
i += 2;
|
|
25
|
-
}
|
|
26
|
-
else if (chars[i] === "{") {
|
|
27
|
-
const j = nextBracket("}", i);
|
|
28
|
-
if (j < 0) {
|
|
29
|
-
throw new Error("Unclosed '{' in template.");
|
|
30
|
-
}
|
|
31
|
-
nodes.push({
|
|
32
|
-
type: "variable",
|
|
33
|
-
name: chars.slice(i + 1, j).join(""),
|
|
34
|
-
});
|
|
35
|
-
i = j + 1;
|
|
36
|
-
}
|
|
37
|
-
else if (chars[i] === "}") {
|
|
38
|
-
throw new Error("Single '}' in template.");
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const next = nextBracket("{}", i);
|
|
42
|
-
const text = (next < 0 ? chars.slice(i) : chars.slice(i, next)).join("");
|
|
43
|
-
nodes.push({ type: "literal", text });
|
|
44
|
-
i = next < 0 ? chars.length : next;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return nodes;
|
|
48
|
-
};
|
|
49
|
-
export const interpolateFString = (template, values) => parseFString(template).reduce((res, node) => {
|
|
50
|
-
if (node.type === "variable") {
|
|
51
|
-
if (node.name in values) {
|
|
52
|
-
return res + values[node.name];
|
|
53
|
-
}
|
|
54
|
-
throw new Error(`Missing value for input ${node.name}`);
|
|
55
|
-
}
|
|
56
|
-
return res + node.text;
|
|
57
|
-
}, "");
|
|
58
|
-
export const DEFAULT_FORMATTER_MAPPING = {
|
|
59
|
-
"f-string": interpolateFString,
|
|
60
|
-
};
|
|
61
|
-
export const DEFAULT_PARSER_MAPPING = {
|
|
62
|
-
"f-string": parseFString,
|
|
63
|
-
};
|
|
64
|
-
export const renderTemplate = (template, templateFormat, inputValues) => DEFAULT_FORMATTER_MAPPING[templateFormat](template, inputValues);
|
|
65
|
-
export const parseTemplate = (template, templateFormat) => DEFAULT_PARSER_MAPPING[templateFormat](template);
|
|
66
|
-
export const checkValidTemplate = (template, templateFormat, inputVariables) => {
|
|
67
|
-
if (!(templateFormat in DEFAULT_FORMATTER_MAPPING)) {
|
|
68
|
-
const validFormats = Object.keys(DEFAULT_FORMATTER_MAPPING);
|
|
69
|
-
throw new Error(`Invalid template format. Got \`${templateFormat}\`;
|
|
70
|
-
should be one of ${validFormats}`);
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
const dummyInputs = inputVariables.reduce((acc, v) => {
|
|
74
|
-
acc[v] = "foo";
|
|
75
|
-
return acc;
|
|
76
|
-
}, {});
|
|
77
|
-
renderTemplate(template, templateFormat, dummyInputs);
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
throw new Error(`Invalid prompt schema: ${e.message}`);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
1
|
+
export { parseFString, interpolateFString, DEFAULT_FORMATTER_MAPPING, DEFAULT_PARSER_MAPPING, renderTemplate, parseTemplate, checkValidTemplate, } from "langchain-core/prompts";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("
|
|
17
|
+
__exportStar(require("langchain-core/runnables"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "langchain-core/runnables";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "langchain-core/runnables";
|
package/dist/schema/document.cjs
CHANGED
|
@@ -1,44 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MappingDocumentTransformer = exports.BaseDocumentTransformer = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
* Abstract base class for document transformation systems.
|
|
7
|
-
*
|
|
8
|
-
* A document transformation system takes an array of Documents and returns an
|
|
9
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
10
|
-
* the same length.
|
|
11
|
-
*
|
|
12
|
-
* One example of this is a text splitter that splits a large document into
|
|
13
|
-
* many smaller documents.
|
|
14
|
-
*/
|
|
15
|
-
class BaseDocumentTransformer extends index_js_1.Runnable {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: ["langchain", "document_transformers"]
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Method to invoke the document transformation. This method calls the
|
|
27
|
-
* transformDocuments method with the provided input.
|
|
28
|
-
* @param input The input documents to be transformed.
|
|
29
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
30
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
31
|
-
*/
|
|
32
|
-
invoke(input, _options) {
|
|
33
|
-
return this.transformDocuments(input);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.BaseDocumentTransformer = BaseDocumentTransformer;
|
|
4
|
+
const documents_1 = require("langchain-core/documents");
|
|
5
|
+
Object.defineProperty(exports, "BaseDocumentTransformer", { enumerable: true, get: function () { return documents_1.BaseDocumentTransformer; } });
|
|
37
6
|
/**
|
|
38
7
|
* Class for document transformers that return exactly one transformed document
|
|
39
8
|
* for each input document.
|
|
40
9
|
*/
|
|
41
|
-
class MappingDocumentTransformer extends BaseDocumentTransformer {
|
|
10
|
+
class MappingDocumentTransformer extends documents_1.BaseDocumentTransformer {
|
|
42
11
|
async transformDocuments(documents) {
|
|
43
12
|
const newDocuments = [];
|
|
44
13
|
for (const document of documents) {
|
|
@@ -1,33 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseDocumentTransformer } from "langchain-core/documents";
|
|
2
2
|
import { Document } from "../document.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for document transformation systems.
|
|
6
|
-
*
|
|
7
|
-
* A document transformation system takes an array of Documents and returns an
|
|
8
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
9
|
-
* the same length.
|
|
10
|
-
*
|
|
11
|
-
* One example of this is a text splitter that splits a large document into
|
|
12
|
-
* many smaller documents.
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class BaseDocumentTransformer<RunInput extends Document[] = Document[], RunOutput extends Document[] = Document[]> extends Runnable<RunInput, RunOutput> {
|
|
15
|
-
lc_namespace: string[];
|
|
16
|
-
/**
|
|
17
|
-
* Transform a list of documents.
|
|
18
|
-
* @param documents A sequence of documents to be transformed.
|
|
19
|
-
* @returns A list of transformed documents.
|
|
20
|
-
*/
|
|
21
|
-
abstract transformDocuments(documents: RunInput): Promise<RunOutput>;
|
|
22
|
-
/**
|
|
23
|
-
* Method to invoke the document transformation. This method calls the
|
|
24
|
-
* transformDocuments method with the provided input.
|
|
25
|
-
* @param input The input documents to be transformed.
|
|
26
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
27
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
28
|
-
*/
|
|
29
|
-
invoke(input: RunInput, _options?: Partial<BaseCallbackConfig>): Promise<RunOutput>;
|
|
30
|
-
}
|
|
3
|
+
export { BaseDocumentTransformer };
|
|
31
4
|
/**
|
|
32
5
|
* Class for document transformers that return exactly one transformed document
|
|
33
6
|
* for each input document.
|
package/dist/schema/document.js
CHANGED
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
* Abstract base class for document transformation systems.
|
|
4
|
-
*
|
|
5
|
-
* A document transformation system takes an array of Documents and returns an
|
|
6
|
-
* array of transformed Documents. These arrays do not necessarily have to have
|
|
7
|
-
* the same length.
|
|
8
|
-
*
|
|
9
|
-
* One example of this is a text splitter that splits a large document into
|
|
10
|
-
* many smaller documents.
|
|
11
|
-
*/
|
|
12
|
-
export class BaseDocumentTransformer extends Runnable {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: ["langchain", "document_transformers"]
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Method to invoke the document transformation. This method calls the
|
|
24
|
-
* transformDocuments method with the provided input.
|
|
25
|
-
* @param input The input documents to be transformed.
|
|
26
|
-
* @param _options Optional configuration object to customize the behavior of callbacks.
|
|
27
|
-
* @returns A Promise that resolves to the transformed documents.
|
|
28
|
-
*/
|
|
29
|
-
invoke(input, _options) {
|
|
30
|
-
return this.transformDocuments(input);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { BaseDocumentTransformer } from "langchain-core/documents";
|
|
2
|
+
export { BaseDocumentTransformer };
|
|
33
3
|
/**
|
|
34
4
|
* Class for document transformers that return exactly one transformed document
|
|
35
5
|
* for each input document.
|