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,194 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { AsyncCaller } from "../util/async_caller.js";
|
|
3
|
-
import { getModelNameForTiktoken } from "./count_tokens.js";
|
|
4
|
-
import { encodingForModel } from "../util/tiktoken.js";
|
|
5
|
-
import { Runnable } from "../schema/runnable/index.js";
|
|
6
|
-
import { StringPromptValue } from "../prompts/base.js";
|
|
7
|
-
import { ChatPromptValue } from "../prompts/chat.js";
|
|
8
|
-
import { InMemoryCache } from "../cache/index.js";
|
|
9
|
-
const getVerbosity = () => false;
|
|
10
|
-
/**
|
|
11
|
-
* Base class for language models, chains, tools.
|
|
12
|
-
*/
|
|
13
|
-
export class BaseLangChain extends Runnable {
|
|
14
|
-
get lc_attributes() {
|
|
15
|
-
return {
|
|
16
|
-
callbacks: undefined,
|
|
17
|
-
verbose: undefined,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
constructor(params) {
|
|
21
|
-
super(params);
|
|
22
|
-
/**
|
|
23
|
-
* Whether to print out response text.
|
|
24
|
-
*/
|
|
25
|
-
Object.defineProperty(this, "verbose", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: void 0
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "callbacks", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, "tags", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
value: void 0
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, "metadata", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
this.verbose = params.verbose ?? getVerbosity();
|
|
50
|
-
this.callbacks = params.callbacks;
|
|
51
|
-
this.tags = params.tags ?? [];
|
|
52
|
-
this.metadata = params.metadata ?? {};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Base class for language models.
|
|
57
|
-
*/
|
|
58
|
-
export class BaseLanguageModel extends BaseLangChain {
|
|
59
|
-
/**
|
|
60
|
-
* Keys that the language model accepts as call options.
|
|
61
|
-
*/
|
|
62
|
-
get callKeys() {
|
|
63
|
-
return ["stop", "timeout", "signal", "tags", "metadata", "callbacks"];
|
|
64
|
-
}
|
|
65
|
-
constructor({ callbacks, callbackManager, ...params }) {
|
|
66
|
-
super({
|
|
67
|
-
callbacks: callbacks ?? callbackManager,
|
|
68
|
-
...params,
|
|
69
|
-
});
|
|
70
|
-
/**
|
|
71
|
-
* The async caller should be used by subclasses to make any async calls,
|
|
72
|
-
* which will thus benefit from the concurrency and retry logic.
|
|
73
|
-
*/
|
|
74
|
-
Object.defineProperty(this, "caller", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: void 0
|
|
79
|
-
});
|
|
80
|
-
Object.defineProperty(this, "cache", {
|
|
81
|
-
enumerable: true,
|
|
82
|
-
configurable: true,
|
|
83
|
-
writable: true,
|
|
84
|
-
value: void 0
|
|
85
|
-
});
|
|
86
|
-
Object.defineProperty(this, "_encoding", {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: void 0
|
|
91
|
-
});
|
|
92
|
-
if (typeof params.cache === "object") {
|
|
93
|
-
this.cache = params.cache;
|
|
94
|
-
}
|
|
95
|
-
else if (params.cache) {
|
|
96
|
-
this.cache = InMemoryCache.global();
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.cache = undefined;
|
|
100
|
-
}
|
|
101
|
-
this.caller = new AsyncCaller(params ?? {});
|
|
102
|
-
}
|
|
103
|
-
async getNumTokens(content) {
|
|
104
|
-
// TODO: Figure out correct value.
|
|
105
|
-
if (typeof content !== "string") {
|
|
106
|
-
return 0;
|
|
107
|
-
}
|
|
108
|
-
// fallback to approximate calculation if tiktoken is not available
|
|
109
|
-
let numTokens = Math.ceil(content.length / 4);
|
|
110
|
-
if (!this._encoding) {
|
|
111
|
-
try {
|
|
112
|
-
this._encoding = await encodingForModel("modelName" in this
|
|
113
|
-
? getModelNameForTiktoken(this.modelName)
|
|
114
|
-
: "gpt2");
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
console.warn("Failed to calculate number of tokens, falling back to approximate count", error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (this._encoding) {
|
|
121
|
-
numTokens = this._encoding.encode(content).length;
|
|
122
|
-
}
|
|
123
|
-
return numTokens;
|
|
124
|
-
}
|
|
125
|
-
static _convertInputToPromptValue(input) {
|
|
126
|
-
if (typeof input === "string") {
|
|
127
|
-
return new StringPromptValue(input);
|
|
128
|
-
}
|
|
129
|
-
else if (Array.isArray(input)) {
|
|
130
|
-
return new ChatPromptValue(input.map(coerceMessageLikeToMessage));
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
return input;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get the identifying parameters of the LLM.
|
|
138
|
-
*/
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
-
_identifyingParams() {
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Create a unique cache key for a specific call to a specific language model.
|
|
145
|
-
* @param callOptions Call options for the model
|
|
146
|
-
* @returns A unique cache key.
|
|
147
|
-
*/
|
|
148
|
-
_getSerializedCacheKeyParametersForCall(callOptions) {
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
-
const params = {
|
|
151
|
-
...this._identifyingParams(),
|
|
152
|
-
...callOptions,
|
|
153
|
-
_type: this._llmType(),
|
|
154
|
-
_model: this._modelType(),
|
|
155
|
-
};
|
|
156
|
-
const filteredEntries = Object.entries(params).filter(([_, value]) => value !== undefined);
|
|
157
|
-
const serializedEntries = filteredEntries
|
|
158
|
-
.map(([key, value]) => `${key}:${JSON.stringify(value)}`)
|
|
159
|
-
.sort()
|
|
160
|
-
.join(",");
|
|
161
|
-
return serializedEntries;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated
|
|
165
|
-
* Return a json-like object representing this LLM.
|
|
166
|
-
*/
|
|
167
|
-
serialize() {
|
|
168
|
-
return {
|
|
169
|
-
...this._identifyingParams(),
|
|
170
|
-
_type: this._llmType(),
|
|
171
|
-
_model: this._modelType(),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* @deprecated
|
|
176
|
-
* Load an LLM from a json-like object describing it.
|
|
177
|
-
*/
|
|
178
|
-
static async deserialize(data) {
|
|
179
|
-
const { _type, _model, ...rest } = data;
|
|
180
|
-
if (_model && _model !== "base_chat_model") {
|
|
181
|
-
throw new Error(`Cannot load LLM with model ${_model}`);
|
|
182
|
-
}
|
|
183
|
-
const Cls = {
|
|
184
|
-
openai: (await import("../chat_models/openai.js")).ChatOpenAI,
|
|
185
|
-
}[_type];
|
|
186
|
-
if (Cls === undefined) {
|
|
187
|
-
throw new Error(`Cannot load LLM with type ${_type}`);
|
|
188
|
-
}
|
|
189
|
-
return new Cls(rest);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
1
|
+
export { BaseLangChain, BaseLanguageModel, } from "langchain-core/language_models/base";
|
|
192
2
|
/*
|
|
193
3
|
* Export utility functions for token calculations:
|
|
194
4
|
* - calculateMaxTokens: Calculate max tokens for a given model and prompt (the model context size - tokens in prompt).
|
package/dist/cache/base.cjs
CHANGED
|
@@ -1,39 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* This cache key should be consistent across all versions of langchain.
|
|
8
|
-
* It is currently NOT consistent across versions of langchain.
|
|
9
|
-
*
|
|
10
|
-
* A huge benefit of having a remote cache (like redis) is that you can
|
|
11
|
-
* access the cache from different processes/machines. The allows you to
|
|
12
|
-
* seperate concerns and scale horizontally.
|
|
13
|
-
*
|
|
14
|
-
* TODO: Make cache key consistent across versions of langchain.
|
|
15
|
-
*/
|
|
16
|
-
const getCacheKey = (...strings) => (0, hash_js_1.insecureHash)(strings.join("_"));
|
|
17
|
-
exports.getCacheKey = getCacheKey;
|
|
18
|
-
function deserializeStoredGeneration(storedGeneration) {
|
|
19
|
-
if (storedGeneration.message !== undefined) {
|
|
20
|
-
return {
|
|
21
|
-
text: storedGeneration.text,
|
|
22
|
-
message: (0, index_js_1.mapStoredMessageToChatMessage)(storedGeneration.message),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return { text: storedGeneration.text };
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
7
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
exports.serializeGeneration = serializeGeneration;
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("langchain-core/caches"), exports);
|
package/dist/cache/base.d.ts
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* This cache key should be consistent across all versions of langchain.
|
|
4
|
-
* It is currently NOT consistent across versions of langchain.
|
|
5
|
-
*
|
|
6
|
-
* A huge benefit of having a remote cache (like redis) is that you can
|
|
7
|
-
* access the cache from different processes/machines. The allows you to
|
|
8
|
-
* seperate concerns and scale horizontally.
|
|
9
|
-
*
|
|
10
|
-
* TODO: Make cache key consistent across versions of langchain.
|
|
11
|
-
*/
|
|
12
|
-
export declare const getCacheKey: (...strings: string[]) => string;
|
|
13
|
-
export declare function deserializeStoredGeneration(storedGeneration: StoredGeneration): {
|
|
14
|
-
text: string;
|
|
15
|
-
message: import("../schema/index.js").ChatMessage | import("../schema/index.js").HumanMessage | import("../schema/index.js").AIMessage | import("../schema/index.js").SystemMessage | import("../schema/index.js").FunctionMessage | import("../schema/index.js").ToolMessage;
|
|
16
|
-
} | {
|
|
17
|
-
text: string;
|
|
18
|
-
message?: undefined;
|
|
19
|
-
};
|
|
20
|
-
export declare function serializeGeneration(generation: Generation): StoredGeneration;
|
|
1
|
+
export * from "langchain-core/caches";
|
package/dist/cache/base.js
CHANGED
|
@@ -1,33 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { mapStoredMessageToChatMessage, } from "../schema/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* This cache key should be consistent across all versions of langchain.
|
|
5
|
-
* It is currently NOT consistent across versions of langchain.
|
|
6
|
-
*
|
|
7
|
-
* A huge benefit of having a remote cache (like redis) is that you can
|
|
8
|
-
* access the cache from different processes/machines. The allows you to
|
|
9
|
-
* seperate concerns and scale horizontally.
|
|
10
|
-
*
|
|
11
|
-
* TODO: Make cache key consistent across versions of langchain.
|
|
12
|
-
*/
|
|
13
|
-
export const getCacheKey = (...strings) => insecureHash(strings.join("_"));
|
|
14
|
-
export function deserializeStoredGeneration(storedGeneration) {
|
|
15
|
-
if (storedGeneration.message !== undefined) {
|
|
16
|
-
return {
|
|
17
|
-
text: storedGeneration.text,
|
|
18
|
-
message: mapStoredMessageToChatMessage(storedGeneration.message),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return { text: storedGeneration.text };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function serializeGeneration(generation) {
|
|
26
|
-
const serializedValue = {
|
|
27
|
-
text: generation.text,
|
|
28
|
-
};
|
|
29
|
-
if (generation.message !== undefined) {
|
|
30
|
-
serializedValue.message = generation.message.toDict();
|
|
31
|
-
}
|
|
32
|
-
return serializedValue;
|
|
33
|
-
}
|
|
1
|
+
export * from "langchain-core/caches";
|
package/dist/cache/index.cjs
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryCache = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const GLOBAL_MAP = new Map();
|
|
7
|
-
/**
|
|
8
|
-
* A cache for storing LLM generations that stores data in memory.
|
|
9
|
-
*/
|
|
10
|
-
class InMemoryCache extends index_js_1.BaseCache {
|
|
11
|
-
constructor(map) {
|
|
12
|
-
super();
|
|
13
|
-
Object.defineProperty(this, "cache", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: void 0
|
|
18
|
-
});
|
|
19
|
-
this.cache = map ?? new Map();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Retrieves data from the cache using a prompt and an LLM key. If the
|
|
23
|
-
* data is not found, it returns null.
|
|
24
|
-
* @param prompt The prompt used to find the data.
|
|
25
|
-
* @param llmKey The LLM key used to find the data.
|
|
26
|
-
* @returns The data corresponding to the prompt and LLM key, or null if not found.
|
|
27
|
-
*/
|
|
28
|
-
lookup(prompt, llmKey) {
|
|
29
|
-
return Promise.resolve(this.cache.get((0, base_js_1.getCacheKey)(prompt, llmKey)) ?? null);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Updates the cache with new data using a prompt and an LLM key.
|
|
33
|
-
* @param prompt The prompt used to store the data.
|
|
34
|
-
* @param llmKey The LLM key used to store the data.
|
|
35
|
-
* @param value The data to be stored.
|
|
36
|
-
*/
|
|
37
|
-
async update(prompt, llmKey, value) {
|
|
38
|
-
this.cache.set((0, base_js_1.getCacheKey)(prompt, llmKey), value);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Returns a global instance of InMemoryCache using a predefined global
|
|
42
|
-
* map as the initial cache.
|
|
43
|
-
* @returns A global instance of InMemoryCache.
|
|
44
|
-
*/
|
|
45
|
-
static global() {
|
|
46
|
-
return new InMemoryCache(GLOBAL_MAP);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.InMemoryCache = InMemoryCache;
|
|
4
|
+
var caches_1 = require("langchain-core/caches");
|
|
5
|
+
Object.defineProperty(exports, "InMemoryCache", { enumerable: true, get: function () { return caches_1.InMemoryCache; } });
|
package/dist/cache/index.d.ts
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A cache for storing LLM generations that stores data in memory.
|
|
4
|
-
*/
|
|
5
|
-
export declare class InMemoryCache<T = Generation[]> extends BaseCache<T> {
|
|
6
|
-
private cache;
|
|
7
|
-
constructor(map?: Map<string, T>);
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves data from the cache using a prompt and an LLM key. If the
|
|
10
|
-
* data is not found, it returns null.
|
|
11
|
-
* @param prompt The prompt used to find the data.
|
|
12
|
-
* @param llmKey The LLM key used to find the data.
|
|
13
|
-
* @returns The data corresponding to the prompt and LLM key, or null if not found.
|
|
14
|
-
*/
|
|
15
|
-
lookup(prompt: string, llmKey: string): Promise<T | null>;
|
|
16
|
-
/**
|
|
17
|
-
* Updates the cache with new data using a prompt and an LLM key.
|
|
18
|
-
* @param prompt The prompt used to store the data.
|
|
19
|
-
* @param llmKey The LLM key used to store the data.
|
|
20
|
-
* @param value The data to be stored.
|
|
21
|
-
*/
|
|
22
|
-
update(prompt: string, llmKey: string, value: T): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Returns a global instance of InMemoryCache using a predefined global
|
|
25
|
-
* map as the initial cache.
|
|
26
|
-
* @returns A global instance of InMemoryCache.
|
|
27
|
-
*/
|
|
28
|
-
static global(): InMemoryCache;
|
|
29
|
-
}
|
|
1
|
+
export { InMemoryCache } from "langchain-core/caches";
|
package/dist/cache/index.js
CHANGED
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseCache } from "../schema/index.js";
|
|
3
|
-
const GLOBAL_MAP = new Map();
|
|
4
|
-
/**
|
|
5
|
-
* A cache for storing LLM generations that stores data in memory.
|
|
6
|
-
*/
|
|
7
|
-
export class InMemoryCache extends BaseCache {
|
|
8
|
-
constructor(map) {
|
|
9
|
-
super();
|
|
10
|
-
Object.defineProperty(this, "cache", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: void 0
|
|
15
|
-
});
|
|
16
|
-
this.cache = map ?? new Map();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves data from the cache using a prompt and an LLM key. If the
|
|
20
|
-
* data is not found, it returns null.
|
|
21
|
-
* @param prompt The prompt used to find the data.
|
|
22
|
-
* @param llmKey The LLM key used to find the data.
|
|
23
|
-
* @returns The data corresponding to the prompt and LLM key, or null if not found.
|
|
24
|
-
*/
|
|
25
|
-
lookup(prompt, llmKey) {
|
|
26
|
-
return Promise.resolve(this.cache.get(getCacheKey(prompt, llmKey)) ?? null);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Updates the cache with new data using a prompt and an LLM key.
|
|
30
|
-
* @param prompt The prompt used to store the data.
|
|
31
|
-
* @param llmKey The LLM key used to store the data.
|
|
32
|
-
* @param value The data to be stored.
|
|
33
|
-
*/
|
|
34
|
-
async update(prompt, llmKey, value) {
|
|
35
|
-
this.cache.set(getCacheKey(prompt, llmKey), value);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Returns a global instance of InMemoryCache using a predefined global
|
|
39
|
-
* map as the initial cache.
|
|
40
|
-
* @returns A global instance of InMemoryCache.
|
|
41
|
-
*/
|
|
42
|
-
static global() {
|
|
43
|
-
return new InMemoryCache(GLOBAL_MAP);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
export { InMemoryCache } from "langchain-core/caches";
|
package/dist/callbacks/base.cjs
CHANGED
|
@@ -10,144 +10,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
15
|
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports
|
|
27
|
-
const uuid = __importStar(require("uuid"));
|
|
28
|
-
const serializable_js_1 = require("../load/serializable.cjs");
|
|
29
|
-
/**
|
|
30
|
-
* Abstract class that provides a set of optional methods that can be
|
|
31
|
-
* overridden in derived classes to handle various events during the
|
|
32
|
-
* execution of a LangChain application.
|
|
33
|
-
*/
|
|
34
|
-
class BaseCallbackHandlerMethodsClass {
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Abstract base class for creating callback handlers in the LangChain
|
|
38
|
-
* framework. It provides a set of optional methods that can be overridden
|
|
39
|
-
* in derived classes to handle various events during the execution of a
|
|
40
|
-
* LangChain application.
|
|
41
|
-
*/
|
|
42
|
-
class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
|
|
43
|
-
get lc_namespace() {
|
|
44
|
-
return ["langchain", "callbacks", this.name];
|
|
45
|
-
}
|
|
46
|
-
get lc_secrets() {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
get lc_attributes() {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
get lc_aliases() {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* The name of the serializable. Override to provide an alias or
|
|
57
|
-
* to preserve the serialized module name in minified environments.
|
|
58
|
-
*
|
|
59
|
-
* Implemented as a static method to support loading logic.
|
|
60
|
-
*/
|
|
61
|
-
static lc_name() {
|
|
62
|
-
return this.name;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* The final serialized identifier for the module.
|
|
66
|
-
*/
|
|
67
|
-
get lc_id() {
|
|
68
|
-
return [
|
|
69
|
-
...this.lc_namespace,
|
|
70
|
-
(0, serializable_js_1.get_lc_unique_name)(this.constructor),
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
constructor(input) {
|
|
74
|
-
super();
|
|
75
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: false
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(this, "lc_kwargs", {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
value: void 0
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(this, "ignoreLLM", {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: true,
|
|
91
|
-
value: false
|
|
92
|
-
});
|
|
93
|
-
Object.defineProperty(this, "ignoreChain", {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
configurable: true,
|
|
96
|
-
writable: true,
|
|
97
|
-
value: false
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, "ignoreAgent", {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
configurable: true,
|
|
102
|
-
writable: true,
|
|
103
|
-
value: false
|
|
104
|
-
});
|
|
105
|
-
Object.defineProperty(this, "ignoreRetriever", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: false
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(this, "awaitHandlers", {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true,
|
|
115
|
-
value: typeof process !== "undefined"
|
|
116
|
-
? // eslint-disable-next-line no-process-env
|
|
117
|
-
process.env?.LANGCHAIN_CALLBACKS_BACKGROUND !== "true"
|
|
118
|
-
: true
|
|
119
|
-
});
|
|
120
|
-
this.lc_kwargs = input || {};
|
|
121
|
-
if (input) {
|
|
122
|
-
this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
|
|
123
|
-
this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
|
|
124
|
-
this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
|
|
125
|
-
this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
copy() {
|
|
129
|
-
return new this.constructor(this);
|
|
130
|
-
}
|
|
131
|
-
toJSON() {
|
|
132
|
-
return serializable_js_1.Serializable.prototype.toJSON.call(this);
|
|
133
|
-
}
|
|
134
|
-
toJSONNotImplemented() {
|
|
135
|
-
return serializable_js_1.Serializable.prototype.toJSONNotImplemented.call(this);
|
|
136
|
-
}
|
|
137
|
-
static fromMethods(methods) {
|
|
138
|
-
class Handler extends BaseCallbackHandler {
|
|
139
|
-
constructor() {
|
|
140
|
-
super();
|
|
141
|
-
Object.defineProperty(this, "name", {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
configurable: true,
|
|
144
|
-
writable: true,
|
|
145
|
-
value: uuid.v4()
|
|
146
|
-
});
|
|
147
|
-
Object.assign(this, methods);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return new Handler();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.BaseCallbackHandler = BaseCallbackHandler;
|
|
17
|
+
__exportStar(require("langchain-core/callbacks/base"), exports);
|