langchain 0.0.195 → 0.0.196

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.
Files changed (216) hide show
  1. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  2. package/dist/base_language/count_tokens.cjs +5 -70
  3. package/dist/base_language/count_tokens.d.ts +1 -10
  4. package/dist/base_language/count_tokens.js +1 -65
  5. package/dist/base_language/index.cjs +6 -196
  6. package/dist/base_language/index.d.ts +1 -111
  7. package/dist/base_language/index.js +1 -191
  8. package/dist/cache/base.cjs +15 -37
  9. package/dist/cache/base.d.ts +1 -20
  10. package/dist/cache/base.js +1 -33
  11. package/dist/cache/index.cjs +2 -46
  12. package/dist/cache/index.d.ts +1 -29
  13. package/dist/cache/index.js +1 -45
  14. package/dist/callbacks/base.cjs +3 -139
  15. package/dist/callbacks/base.d.ts +1 -266
  16. package/dist/callbacks/base.js +1 -126
  17. package/dist/callbacks/handlers/console.cjs +14 -221
  18. package/dist/callbacks/handlers/console.d.ts +1 -117
  19. package/dist/callbacks/handlers/console.js +1 -217
  20. package/dist/callbacks/handlers/initialize.cjs +15 -30
  21. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  22. package/dist/callbacks/handlers/initialize.js +1 -27
  23. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  24. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  25. package/dist/callbacks/handlers/log_stream.js +1 -289
  26. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  27. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  28. package/dist/callbacks/handlers/run_collector.js +1 -46
  29. package/dist/callbacks/handlers/tracer.cjs +15 -375
  30. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  31. package/dist/callbacks/handlers/tracer.js +1 -373
  32. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  33. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  34. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  35. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  36. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  37. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  38. package/dist/callbacks/manager.cjs +15 -676
  39. package/dist/callbacks/manager.d.ts +1 -180
  40. package/dist/callbacks/manager.js +1 -666
  41. package/dist/callbacks/promises.cjs +14 -42
  42. package/dist/callbacks/promises.d.ts +1 -11
  43. package/dist/callbacks/promises.js +1 -37
  44. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  45. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  46. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  47. package/dist/chains/openai_functions/structured_output.js +1 -1
  48. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  49. package/dist/chat_models/base.cjs +15 -296
  50. package/dist/chat_models/base.d.ts +1 -122
  51. package/dist/chat_models/base.js +1 -292
  52. package/dist/chat_models/bedrock/web.d.ts +1 -1
  53. package/dist/chat_models/fireworks.d.ts +1 -1
  54. package/dist/document.cjs +2 -24
  55. package/dist/document.d.ts +1 -12
  56. package/dist/document.js +1 -23
  57. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  58. package/dist/document_loaders/web/s3.d.ts +1 -1
  59. package/dist/embeddings/base.cjs +15 -22
  60. package/dist/embeddings/base.d.ts +1 -33
  61. package/dist/embeddings/base.js +1 -20
  62. package/dist/embeddings/cache_backed.cjs +2 -2
  63. package/dist/embeddings/cache_backed.js +1 -1
  64. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  65. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  66. package/dist/evaluation/qa/prompt.d.ts +2 -2
  67. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  68. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  69. package/dist/llms/base.cjs +15 -278
  70. package/dist/llms/base.d.ts +1 -115
  71. package/dist/llms/base.js +1 -275
  72. package/dist/llms/bedrock/web.d.ts +1 -1
  73. package/dist/llms/fireworks.d.ts +1 -1
  74. package/dist/load/import_map.cjs +2 -1
  75. package/dist/load/import_map.d.ts +1 -0
  76. package/dist/load/import_map.js +1 -0
  77. package/dist/load/index.cjs +7 -148
  78. package/dist/load/index.js +7 -148
  79. package/dist/load/map_keys.cjs +0 -24
  80. package/dist/load/map_keys.d.ts +0 -6
  81. package/dist/load/map_keys.js +1 -17
  82. package/dist/load/serializable.cjs +15 -178
  83. package/dist/load/serializable.d.ts +1 -66
  84. package/dist/load/serializable.js +1 -175
  85. package/dist/memory/base.cjs +17 -92
  86. package/dist/memory/base.d.ts +2 -68
  87. package/dist/memory/base.js +2 -87
  88. package/dist/output_parsers/openai_functions.cjs +2 -2
  89. package/dist/output_parsers/openai_functions.d.ts +1 -1
  90. package/dist/output_parsers/openai_functions.js +1 -1
  91. package/dist/output_parsers/regex.d.ts +1 -1
  92. package/dist/output_parsers/structured.d.ts +1 -1
  93. package/dist/prompts/base.cjs +8 -183
  94. package/dist/prompts/base.d.ts +3 -132
  95. package/dist/prompts/base.js +3 -178
  96. package/dist/prompts/chat.cjs +15 -477
  97. package/dist/prompts/chat.d.ts +1 -219
  98. package/dist/prompts/chat.js +1 -466
  99. package/dist/prompts/few_shot.cjs +15 -353
  100. package/dist/prompts/few_shot.d.ts +1 -192
  101. package/dist/prompts/few_shot.js +1 -350
  102. package/dist/prompts/index.cjs +3 -2
  103. package/dist/prompts/index.d.ts +2 -1
  104. package/dist/prompts/index.js +2 -1
  105. package/dist/prompts/pipeline.cjs +15 -142
  106. package/dist/prompts/pipeline.d.ts +1 -98
  107. package/dist/prompts/pipeline.js +1 -140
  108. package/dist/prompts/prompt.cjs +15 -146
  109. package/dist/prompts/prompt.d.ts +1 -92
  110. package/dist/prompts/prompt.js +1 -144
  111. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
  112. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  113. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  114. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  115. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  116. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  117. package/dist/prompts/selectors/conditional.cjs +15 -74
  118. package/dist/prompts/selectors/conditional.d.ts +1 -63
  119. package/dist/prompts/selectors/conditional.js +1 -69
  120. package/dist/prompts/serde.cjs +15 -0
  121. package/dist/prompts/serde.d.ts +1 -43
  122. package/dist/prompts/serde.js +1 -1
  123. package/dist/prompts/template.cjs +14 -88
  124. package/dist/prompts/template.d.ts +1 -36
  125. package/dist/prompts/template.js +1 -83
  126. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  127. package/dist/runnables/index.d.ts +1 -0
  128. package/dist/runnables/index.js +1 -0
  129. package/dist/schema/document.cjs +3 -34
  130. package/dist/schema/document.d.ts +2 -29
  131. package/dist/schema/document.js +2 -32
  132. package/dist/schema/index.cjs +37 -612
  133. package/dist/schema/index.d.ts +11 -311
  134. package/dist/schema/index.js +8 -583
  135. package/dist/schema/output_parser.cjs +15 -309
  136. package/dist/schema/output_parser.d.ts +1 -173
  137. package/dist/schema/output_parser.js +1 -301
  138. package/dist/schema/retriever.cjs +15 -77
  139. package/dist/schema/retriever.d.ts +1 -43
  140. package/dist/schema/retriever.js +1 -75
  141. package/dist/schema/runnable/base.cjs +10 -1072
  142. package/dist/schema/runnable/base.d.ts +1 -356
  143. package/dist/schema/runnable/base.js +1 -1060
  144. package/dist/schema/runnable/branch.cjs +2 -131
  145. package/dist/schema/runnable/branch.d.ts +1 -94
  146. package/dist/schema/runnable/branch.js +1 -130
  147. package/dist/schema/runnable/config.cjs +0 -6
  148. package/dist/schema/runnable/config.d.ts +1 -3
  149. package/dist/schema/runnable/config.js +1 -4
  150. package/dist/schema/runnable/index.cjs +15 -16
  151. package/dist/schema/runnable/index.d.ts +1 -5
  152. package/dist/schema/runnable/index.js +1 -4
  153. package/dist/schema/runnable/passthrough.cjs +3 -113
  154. package/dist/schema/runnable/passthrough.d.ts +1 -72
  155. package/dist/schema/runnable/passthrough.js +1 -111
  156. package/dist/schema/runnable/router.cjs +2 -71
  157. package/dist/schema/runnable/router.d.ts +1 -29
  158. package/dist/schema/runnable/router.js +1 -70
  159. package/dist/schema/storage.cjs +15 -8
  160. package/dist/schema/storage.d.ts +1 -57
  161. package/dist/schema/storage.js +1 -6
  162. package/dist/tools/bingserpapi.d.ts +1 -1
  163. package/dist/tools/searchapi.d.ts +1 -1
  164. package/dist/tools/serpapi.d.ts +1 -1
  165. package/dist/tools/serper.d.ts +1 -1
  166. package/dist/util/async_caller.cjs +14 -128
  167. package/dist/util/async_caller.d.ts +1 -45
  168. package/dist/util/async_caller.js +1 -124
  169. package/package.json +11 -5
  170. package/runnables.cjs +1 -0
  171. package/runnables.d.ts +1 -0
  172. package/runnables.js +1 -0
  173. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  174. package/dist/util/@cfworker/json-schema/index.js +0 -1
  175. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  176. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  177. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  178. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  179. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  180. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  181. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  182. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  183. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  184. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  185. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  186. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  187. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  188. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  189. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  190. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  191. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  192. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  193. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  194. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  195. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  196. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  197. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  198. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  199. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  200. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  201. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  202. package/dist/util/fast-json-patch/index.cjs +0 -49
  203. package/dist/util/fast-json-patch/index.d.ts +0 -22
  204. package/dist/util/fast-json-patch/index.js +0 -16
  205. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  206. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  207. package/dist/util/fast-json-patch/src/core.js +0 -459
  208. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  209. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  210. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  211. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  212. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  213. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  214. package/dist/util/js-sha1/hash.cjs +0 -358
  215. package/dist/util/js-sha1/hash.d.ts +0 -1
  216. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,39 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeGeneration = exports.deserializeStoredGeneration = exports.getCacheKey = void 0;
4
- const hash_js_1 = require("../util/js-sha1/hash.cjs");
5
- const index_js_1 = require("../schema/index.cjs");
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
- exports.deserializeStoredGeneration = deserializeStoredGeneration;
30
- function serializeGeneration(generation) {
31
- const serializedValue = {
32
- text: generation.text,
33
- };
34
- if (generation.message !== undefined) {
35
- serializedValue.message = generation.message.toDict();
36
- }
37
- return serializedValue;
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/schema/cache"), exports);
@@ -1,20 +1 @@
1
- import { Generation, StoredGeneration } from "../schema/index.js";
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/schema/cache";
@@ -1,33 +1 @@
1
- import { insecureHash } from "../util/js-sha1/hash.js";
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/schema/cache";
@@ -1,49 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryCache = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- const index_js_1 = require("../schema/index.cjs");
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 cache_1 = require("langchain-core/schema/cache");
5
+ Object.defineProperty(exports, "InMemoryCache", { enumerable: true, get: function () { return cache_1.InMemoryCache; } });
@@ -1,29 +1 @@
1
- import { Generation, BaseCache } from "../schema/index.js";
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/schema/cache";
@@ -1,45 +1 @@
1
- import { getCacheKey } from "./base.js";
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/schema/cache";
@@ -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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
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.BaseCallbackHandler = void 0;
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);
@@ -1,266 +1 @@
1
- import { AgentAction, AgentFinish, BaseMessage, ChainValues, ChatGenerationChunk, GenerationChunk, LLMResult } from "../schema/index.js";
2
- import { Serializable, Serialized, SerializedNotImplemented } from "../load/serializable.js";
3
- import { SerializedFields } from "../load/map_keys.js";
4
- import { Document } from "../document.js";
5
- type Error = any;
6
- /**
7
- * Interface for the input parameters of the BaseCallbackHandler class. It
8
- * allows to specify which types of events should be ignored by the
9
- * callback handler.
10
- */
11
- export interface BaseCallbackHandlerInput {
12
- ignoreLLM?: boolean;
13
- ignoreChain?: boolean;
14
- ignoreAgent?: boolean;
15
- ignoreRetriever?: boolean;
16
- }
17
- /**
18
- * Interface for the indices of a new token produced by an LLM or Chat
19
- * Model in streaming mode.
20
- */
21
- export interface NewTokenIndices {
22
- prompt: number;
23
- completion: number;
24
- }
25
- export type HandleLLMNewTokenCallbackFields = {
26
- chunk?: GenerationChunk | ChatGenerationChunk;
27
- };
28
- /**
29
- * Abstract class that provides a set of optional methods that can be
30
- * overridden in derived classes to handle various events during the
31
- * execution of a LangChain application.
32
- */
33
- declare abstract class BaseCallbackHandlerMethodsClass {
34
- /**
35
- * Called at the start of an LLM or Chat Model run, with the prompt(s)
36
- * and the run ID.
37
- */
38
- handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- Promise<any> | any;
40
- /**
41
- * Called when an LLM/ChatModel in `streaming` mode produces a new token
42
- */
43
- handleLLMNewToken?(token: string,
44
- /**
45
- * idx.prompt is the index of the prompt that produced the token
46
- * (if there are multiple prompts)
47
- * idx.completion is the index of the completion that produced the token
48
- * (if multiple completions per prompt are requested)
49
- */
50
- idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- Promise<any> | any;
52
- /**
53
- * Called if an LLM/ChatModel run encounters an error
54
- */
55
- handleLLMError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- Promise<any> | any;
57
- /**
58
- * Called at the end of an LLM/ChatModel run, with the output and the run ID.
59
- */
60
- handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- Promise<any> | any;
62
- /**
63
- * Called at the start of a Chat Model run, with the prompt(s)
64
- * and the run ID.
65
- */
66
- handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- Promise<any> | any;
68
- /**
69
- * Called at the start of a Chain run, with the chain name and inputs
70
- * and the run ID.
71
- */
72
- handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- Promise<any> | any;
74
- /**
75
- * Called if a Chain run encounters an error
76
- */
77
- handleChainError?(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
78
- inputs?: Record<string, unknown>;
79
- }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
- Promise<any> | any;
81
- /**
82
- * Called at the end of a Chain run, with the outputs and the run ID.
83
- */
84
- handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
85
- inputs?: Record<string, unknown>;
86
- }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- Promise<any> | any;
88
- /**
89
- * Called at the start of a Tool run, with the tool name and input
90
- * and the run ID.
91
- */
92
- handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- Promise<any> | any;
94
- /**
95
- * Called if a Tool run encounters an error
96
- */
97
- handleToolError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- Promise<any> | any;
99
- /**
100
- * Called at the end of a Tool run, with the tool output and the run ID.
101
- */
102
- handleToolEnd?(output: string, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- Promise<any> | any;
104
- handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
105
- /**
106
- * Called when an agent is about to execute an action,
107
- * with the action and the run ID.
108
- */
109
- handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
110
- /**
111
- * Called when an agent finishes execution, before it exits.
112
- * with the final output and the run ID.
113
- */
114
- handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
115
- handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- Promise<any> | any;
117
- handleRetrieverEnd?(documents: Document[], runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- Promise<any> | any;
119
- handleRetrieverError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- Promise<any> | any;
121
- }
122
- /**
123
- * Base interface for callbacks. All methods are optional. If a method is not
124
- * implemented, it will be ignored. If a method is implemented, it will be
125
- * called at the appropriate time. All methods are called with the run ID of
126
- * the LLM/ChatModel/Chain that is running, which is generated by the
127
- * CallbackManager.
128
- *
129
- * @interface
130
- */
131
- export type CallbackHandlerMethods = BaseCallbackHandlerMethodsClass;
132
- /**
133
- * Abstract base class for creating callback handlers in the LangChain
134
- * framework. It provides a set of optional methods that can be overridden
135
- * in derived classes to handle various events during the execution of a
136
- * LangChain application.
137
- */
138
- export declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass implements BaseCallbackHandlerInput, Serializable {
139
- lc_serializable: boolean;
140
- get lc_namespace(): ["langchain", "callbacks", string];
141
- get lc_secrets(): {
142
- [key: string]: string;
143
- } | undefined;
144
- get lc_attributes(): {
145
- [key: string]: string;
146
- } | undefined;
147
- get lc_aliases(): {
148
- [key: string]: string;
149
- } | undefined;
150
- /**
151
- * The name of the serializable. Override to provide an alias or
152
- * to preserve the serialized module name in minified environments.
153
- *
154
- * Implemented as a static method to support loading logic.
155
- */
156
- static lc_name(): string;
157
- /**
158
- * The final serialized identifier for the module.
159
- */
160
- get lc_id(): string[];
161
- lc_kwargs: SerializedFields;
162
- abstract name: string;
163
- ignoreLLM: boolean;
164
- ignoreChain: boolean;
165
- ignoreAgent: boolean;
166
- ignoreRetriever: boolean;
167
- awaitHandlers: boolean;
168
- constructor(input?: BaseCallbackHandlerInput);
169
- copy(): BaseCallbackHandler;
170
- toJSON(): Serialized;
171
- toJSONNotImplemented(): SerializedNotImplemented;
172
- static fromMethods(methods: CallbackHandlerMethods): {
173
- name: string;
174
- lc_serializable: boolean;
175
- readonly lc_namespace: ["langchain", "callbacks", string];
176
- readonly lc_secrets: {
177
- [key: string]: string;
178
- } | undefined;
179
- readonly lc_attributes: {
180
- [key: string]: string;
181
- } | undefined;
182
- readonly lc_aliases: {
183
- [key: string]: string;
184
- } | undefined;
185
- /**
186
- * The final serialized identifier for the module.
187
- */
188
- readonly lc_id: string[];
189
- lc_kwargs: SerializedFields;
190
- ignoreLLM: boolean;
191
- ignoreChain: boolean;
192
- ignoreAgent: boolean;
193
- ignoreRetriever: boolean;
194
- awaitHandlers: boolean;
195
- copy(): BaseCallbackHandler;
196
- toJSON(): Serialized;
197
- toJSONNotImplemented(): SerializedNotImplemented;
198
- /**
199
- * Called at the start of an LLM or Chat Model run, with the prompt(s)
200
- * and the run ID.
201
- */
202
- handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
203
- /**
204
- * Called when an LLM/ChatModel in `streaming` mode produces a new token
205
- */
206
- handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, fields?: HandleLLMNewTokenCallbackFields | undefined): any;
207
- /**
208
- * Called if an LLM/ChatModel run encounters an error
209
- */
210
- handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
211
- /**
212
- * Called at the end of an LLM/ChatModel run, with the output and the run ID.
213
- */
214
- handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
215
- /**
216
- * Called at the start of a Chat Model run, with the prompt(s)
217
- * and the run ID.
218
- */
219
- handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
220
- /**
221
- * Called at the start of a Chain run, with the chain name and inputs
222
- * and the run ID.
223
- */
224
- handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runType?: string | undefined, name?: string | undefined): any;
225
- /**
226
- * Called if a Chain run encounters an error
227
- */
228
- handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
229
- inputs?: Record<string, unknown> | undefined;
230
- } | undefined): any;
231
- /**
232
- * Called at the end of a Chain run, with the outputs and the run ID.
233
- */
234
- handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
235
- inputs?: Record<string, unknown> | undefined;
236
- } | undefined): any;
237
- /**
238
- * Called at the start of a Tool run, with the tool name and input
239
- * and the run ID.
240
- */
241
- handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
242
- /**
243
- * Called if a Tool run encounters an error
244
- */
245
- handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
246
- /**
247
- * Called at the end of a Tool run, with the tool output and the run ID.
248
- */
249
- handleToolEnd?(output: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
250
- handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
251
- /**
252
- * Called when an agent is about to execute an action,
253
- * with the action and the run ID.
254
- */
255
- handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
256
- /**
257
- * Called when an agent finishes execution, before it exits.
258
- * with the final output and the run ID.
259
- */
260
- handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
261
- handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
262
- handleRetrieverEnd?(documents: Document<Record<string, any>>[], runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
263
- handleRetrieverError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
264
- };
265
- }
266
- export {};
1
+ export * from "langchain-core/callbacks/base";