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,66 +1 @@
1
- import { SerializedFields } from "./map_keys.js";
2
- export interface BaseSerialized<T extends string> {
3
- lc: number;
4
- type: T;
5
- id: string[];
6
- }
7
- export interface SerializedConstructor extends BaseSerialized<"constructor"> {
8
- kwargs: SerializedFields;
9
- }
10
- export interface SerializedSecret extends BaseSerialized<"secret"> {
11
- }
12
- export interface SerializedNotImplemented extends BaseSerialized<"not_implemented"> {
13
- }
14
- export type Serialized = SerializedConstructor | SerializedSecret | SerializedNotImplemented;
15
- /**
16
- * Get a unique name for the module, rather than parent class implementations.
17
- * Should not be subclassed, subclass lc_name above instead.
18
- */
19
- export declare function get_lc_unique_name(serializableClass: typeof Serializable): string;
20
- export declare abstract class Serializable {
21
- lc_serializable: boolean;
22
- lc_kwargs: SerializedFields;
23
- /**
24
- * A path to the module that contains the class, eg. ["langchain", "llms"]
25
- * Usually should be the same as the entrypoint the class is exported from.
26
- */
27
- abstract lc_namespace: string[];
28
- /**
29
- * The name of the serializable. Override to provide an alias or
30
- * to preserve the serialized module name in minified environments.
31
- *
32
- * Implemented as a static method to support loading logic.
33
- */
34
- static lc_name(): string;
35
- /**
36
- * The final serialized identifier for the module.
37
- */
38
- get lc_id(): string[];
39
- /**
40
- * A map of secrets, which will be omitted from serialization.
41
- * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
42
- * Values are the secret ids, which will be used when deserializing.
43
- */
44
- get lc_secrets(): {
45
- [key: string]: string;
46
- } | undefined;
47
- /**
48
- * A map of additional attributes to merge with constructor args.
49
- * Keys are the attribute names, e.g. "foo".
50
- * Values are the attribute values, which will be serialized.
51
- * These attributes need to be accepted by the constructor as arguments.
52
- */
53
- get lc_attributes(): SerializedFields | undefined;
54
- /**
55
- * A map of aliases for constructor args.
56
- * Keys are the attribute names, e.g. "foo".
57
- * Values are the alias that will replace the key in serialization.
58
- * This is used to eg. make argument names match Python.
59
- */
60
- get lc_aliases(): {
61
- [key: string]: string;
62
- } | undefined;
63
- constructor(kwargs?: SerializedFields, ..._args: never[]);
64
- toJSON(): Serialized;
65
- toJSONNotImplemented(): SerializedNotImplemented;
66
- }
1
+ export * from "langchain-core/load/serializable";
@@ -1,175 +1 @@
1
- import { keyToJson, mapKeys } from "./map_keys.js";
2
- function shallowCopy(obj) {
3
- return Array.isArray(obj) ? [...obj] : { ...obj };
4
- }
5
- function replaceSecrets(root, secretsMap) {
6
- const result = shallowCopy(root);
7
- for (const [path, secretId] of Object.entries(secretsMap)) {
8
- const [last, ...partsReverse] = path.split(".").reverse();
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- let current = result;
11
- for (const part of partsReverse.reverse()) {
12
- if (current[part] === undefined) {
13
- break;
14
- }
15
- current[part] = shallowCopy(current[part]);
16
- current = current[part];
17
- }
18
- if (current[last] !== undefined) {
19
- current[last] = {
20
- lc: 1,
21
- type: "secret",
22
- id: [secretId],
23
- };
24
- }
25
- }
26
- return result;
27
- }
28
- /**
29
- * Get a unique name for the module, rather than parent class implementations.
30
- * Should not be subclassed, subclass lc_name above instead.
31
- */
32
- export function get_lc_unique_name(
33
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
34
- serializableClass) {
35
- // "super" here would refer to the parent class of Serializable,
36
- // when we want the parent class of the module actually calling this method.
37
- const parentClass = Object.getPrototypeOf(serializableClass);
38
- const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
39
- (typeof parentClass.lc_name !== "function" ||
40
- serializableClass.lc_name() !== parentClass.lc_name());
41
- if (lcNameIsSubclassed) {
42
- return serializableClass.lc_name();
43
- }
44
- else {
45
- return serializableClass.name;
46
- }
47
- }
48
- export class Serializable {
49
- /**
50
- * The name of the serializable. Override to provide an alias or
51
- * to preserve the serialized module name in minified environments.
52
- *
53
- * Implemented as a static method to support loading logic.
54
- */
55
- static lc_name() {
56
- return this.name;
57
- }
58
- /**
59
- * The final serialized identifier for the module.
60
- */
61
- get lc_id() {
62
- return [
63
- ...this.lc_namespace,
64
- get_lc_unique_name(this.constructor),
65
- ];
66
- }
67
- /**
68
- * A map of secrets, which will be omitted from serialization.
69
- * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
70
- * Values are the secret ids, which will be used when deserializing.
71
- */
72
- get lc_secrets() {
73
- return undefined;
74
- }
75
- /**
76
- * A map of additional attributes to merge with constructor args.
77
- * Keys are the attribute names, e.g. "foo".
78
- * Values are the attribute values, which will be serialized.
79
- * These attributes need to be accepted by the constructor as arguments.
80
- */
81
- get lc_attributes() {
82
- return undefined;
83
- }
84
- /**
85
- * A map of aliases for constructor args.
86
- * Keys are the attribute names, e.g. "foo".
87
- * Values are the alias that will replace the key in serialization.
88
- * This is used to eg. make argument names match Python.
89
- */
90
- get lc_aliases() {
91
- return undefined;
92
- }
93
- constructor(kwargs, ..._args) {
94
- Object.defineProperty(this, "lc_serializable", {
95
- enumerable: true,
96
- configurable: true,
97
- writable: true,
98
- value: false
99
- });
100
- Object.defineProperty(this, "lc_kwargs", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- this.lc_kwargs = kwargs || {};
107
- }
108
- toJSON() {
109
- if (!this.lc_serializable) {
110
- return this.toJSONNotImplemented();
111
- }
112
- if (
113
- // eslint-disable-next-line no-instanceof/no-instanceof
114
- this.lc_kwargs instanceof Serializable ||
115
- typeof this.lc_kwargs !== "object" ||
116
- Array.isArray(this.lc_kwargs)) {
117
- // We do not support serialization of classes with arg not a POJO
118
- // I'm aware the check above isn't as strict as it could be
119
- return this.toJSONNotImplemented();
120
- }
121
- const aliases = {};
122
- const secrets = {};
123
- const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
124
- acc[key] = key in this ? this[key] : this.lc_kwargs[key];
125
- return acc;
126
- }, {});
127
- // get secrets, attributes and aliases from all superclasses
128
- for (
129
- // eslint-disable-next-line @typescript-eslint/no-this-alias
130
- let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
131
- Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
132
- Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
133
- Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
134
- }
135
- // include all secrets used, even if not in kwargs,
136
- // will be replaced with sentinel value in replaceSecrets
137
- Object.keys(secrets).forEach((keyPath) => {
138
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
139
- let read = this;
140
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
- let write = kwargs;
142
- const [last, ...partsReverse] = keyPath.split(".").reverse();
143
- for (const key of partsReverse.reverse()) {
144
- if (!(key in read) || read[key] === undefined)
145
- return;
146
- if (!(key in write) || write[key] === undefined) {
147
- if (typeof read[key] === "object" && read[key] != null) {
148
- write[key] = {};
149
- }
150
- else if (Array.isArray(read[key])) {
151
- write[key] = [];
152
- }
153
- }
154
- read = read[key];
155
- write = write[key];
156
- }
157
- if (last in read && read[last] !== undefined) {
158
- write[last] = write[last] || read[last];
159
- }
160
- });
161
- return {
162
- lc: 1,
163
- type: "constructor",
164
- id: this.lc_id,
165
- kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
166
- };
167
- }
168
- toJSONNotImplemented() {
169
- return {
170
- lc: 1,
171
- type: "not_implemented",
172
- id: this.lc_id,
173
- };
174
- }
175
- }
1
+ export * from "langchain-core/load/serializable";
@@ -1,95 +1,20 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPromptInputKey = exports.getBufferString = exports.getOutputValue = exports.getInputValue = exports.BaseMemory = void 0;
4
- /**
5
- * Abstract base class for memory in LangChain's Chains. Memory refers to
6
- * the state in Chains. It can be used to store information about past
7
- * executions of a Chain and inject that information into the inputs of
8
- * future executions of the Chain.
9
- */
10
- class BaseMemory {
11
- }
12
- exports.BaseMemory = BaseMemory;
13
- const getValue = (values, key) => {
14
- if (key !== undefined) {
15
- return values[key];
16
- }
17
- const keys = Object.keys(values);
18
- if (keys.length === 1) {
19
- return values[keys[0]];
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]; } };
20
7
  }
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);
21
15
  };
22
- /**
23
- * This function is used by memory classes to select the input value
24
- * to use for the memory. If there is only one input value, it is used.
25
- * If there are multiple input values, the inputKey must be specified.
26
- */
27
- const getInputValue = (inputValues, inputKey) => {
28
- const value = getValue(inputValues, inputKey);
29
- if (!value) {
30
- const keys = Object.keys(inputValues);
31
- throw new Error(`input values have ${keys.length} keys, you must specify an input key or pass only 1 key as input`);
32
- }
33
- return value;
34
- };
35
- exports.getInputValue = getInputValue;
36
- /**
37
- * This function is used by memory classes to select the output value
38
- * to use for the memory. If there is only one output value, it is used.
39
- * If there are multiple output values, the outputKey must be specified.
40
- * If no outputKey is specified, an error is thrown.
41
- */
42
- const getOutputValue = (outputValues, outputKey) => {
43
- const value = getValue(outputValues, outputKey);
44
- if (!value) {
45
- const keys = Object.keys(outputValues);
46
- throw new Error(`output values have ${keys.length} keys, you must specify an output key or pass only 1 key as output`);
47
- }
48
- return value;
49
- };
50
- exports.getOutputValue = getOutputValue;
51
- /**
52
- * This function is used by memory classes to get a string representation
53
- * of the chat message history, based on the message content and role.
54
- */
55
- function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
56
- const string_messages = [];
57
- for (const m of messages) {
58
- let role;
59
- if (m._getType() === "human") {
60
- role = humanPrefix;
61
- }
62
- else if (m._getType() === "ai") {
63
- role = aiPrefix;
64
- }
65
- else if (m._getType() === "system") {
66
- role = "System";
67
- }
68
- else if (m._getType() === "function") {
69
- role = "Function";
70
- }
71
- else if (m._getType() === "generic") {
72
- role = m.role;
73
- }
74
- else {
75
- throw new Error(`Got unsupported message type: ${m}`);
76
- }
77
- const nameStr = m.name ? `${m.name}, ` : "";
78
- string_messages.push(`${role}: ${nameStr}${m.content}`);
79
- }
80
- return string_messages.join("\n");
81
- }
82
- exports.getBufferString = getBufferString;
83
- /**
84
- * Function used by memory classes to get the key of the prompt input,
85
- * excluding any keys that are memory variables or the "stop" key. If
86
- * there is not exactly one prompt input key, an error is thrown.
87
- */
88
- function getPromptInputKey(inputs, memoryVariables) {
89
- const promptInputKeys = Object.keys(inputs).filter((key) => !memoryVariables.includes(key) && key !== "stop");
90
- if (promptInputKeys.length !== 1) {
91
- throw new Error(`One input key expected, but got ${promptInputKeys.length}`);
92
- }
93
- return promptInputKeys[0];
94
- }
95
- exports.getPromptInputKey = getPromptInputKey;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getBufferString = void 0;
18
+ __exportStar(require("langchain-core/schema/memory"), exports);
19
+ var messages_1 = require("langchain-core/schema/messages");
20
+ Object.defineProperty(exports, "getBufferString", { enumerable: true, get: function () { return messages_1.getBufferString; } });
@@ -1,68 +1,2 @@
1
- import { BaseMessage } from "../schema/index.js";
2
- /**
3
- * Type alias for a record where the keys are strings and the values can
4
- * be any type. This is used to represent the input values for a Chain.
5
- */
6
- export type InputValues = Record<string, any>;
7
- /**
8
- * Type alias for a record where the keys are strings and the values can
9
- * be any type. This is used to represent the output values from a Chain.
10
- */
11
- export type OutputValues = Record<string, any>;
12
- /**
13
- * Type alias for a record where the keys are strings and the values can
14
- * be any type. This is used to represent the memory variables in a Chain.
15
- */
16
- export type MemoryVariables = Record<string, any>;
17
- /**
18
- * Abstract base class for memory in LangChain's Chains. Memory refers to
19
- * the state in Chains. It can be used to store information about past
20
- * executions of a Chain and inject that information into the inputs of
21
- * future executions of the Chain.
22
- */
23
- export declare abstract class BaseMemory {
24
- abstract get memoryKeys(): string[];
25
- /**
26
- * Abstract method that should take an object of input values and return a
27
- * Promise that resolves with an object of memory variables. The
28
- * implementation of this method should load the memory variables from the
29
- * provided input values.
30
- * @param values An object of input values.
31
- * @returns Promise that resolves with an object of memory variables.
32
- */
33
- abstract loadMemoryVariables(values: InputValues): Promise<MemoryVariables>;
34
- /**
35
- * Abstract method that should take two objects, one of input values and
36
- * one of output values, and return a Promise that resolves when the
37
- * context has been saved. The implementation of this method should save
38
- * the context based on the provided input and output values.
39
- * @param inputValues An object of input values.
40
- * @param outputValues An object of output values.
41
- * @returns Promise that resolves when the context has been saved.
42
- */
43
- abstract saveContext(inputValues: InputValues, outputValues: OutputValues): Promise<void>;
44
- }
45
- /**
46
- * This function is used by memory classes to select the input value
47
- * to use for the memory. If there is only one input value, it is used.
48
- * If there are multiple input values, the inputKey must be specified.
49
- */
50
- export declare const getInputValue: (inputValues: InputValues, inputKey?: string) => any;
51
- /**
52
- * This function is used by memory classes to select the output value
53
- * to use for the memory. If there is only one output value, it is used.
54
- * If there are multiple output values, the outputKey must be specified.
55
- * If no outputKey is specified, an error is thrown.
56
- */
57
- export declare const getOutputValue: (outputValues: OutputValues, outputKey?: string) => any;
58
- /**
59
- * This function is used by memory classes to get a string representation
60
- * of the chat message history, based on the message content and role.
61
- */
62
- export declare function getBufferString(messages: BaseMessage[], humanPrefix?: string, aiPrefix?: string): string;
63
- /**
64
- * Function used by memory classes to get the key of the prompt input,
65
- * excluding any keys that are memory variables or the "stop" key. If
66
- * there is not exactly one prompt input key, an error is thrown.
67
- */
68
- export declare function getPromptInputKey(inputs: Record<string, unknown>, memoryVariables: string[]): string;
1
+ export * from "langchain-core/schema/memory";
2
+ export { getBufferString } from "langchain-core/schema/messages";
@@ -1,87 +1,2 @@
1
- /**
2
- * Abstract base class for memory in LangChain's Chains. Memory refers to
3
- * the state in Chains. It can be used to store information about past
4
- * executions of a Chain and inject that information into the inputs of
5
- * future executions of the Chain.
6
- */
7
- export class BaseMemory {
8
- }
9
- const getValue = (values, key) => {
10
- if (key !== undefined) {
11
- return values[key];
12
- }
13
- const keys = Object.keys(values);
14
- if (keys.length === 1) {
15
- return values[keys[0]];
16
- }
17
- };
18
- /**
19
- * This function is used by memory classes to select the input value
20
- * to use for the memory. If there is only one input value, it is used.
21
- * If there are multiple input values, the inputKey must be specified.
22
- */
23
- export const getInputValue = (inputValues, inputKey) => {
24
- const value = getValue(inputValues, inputKey);
25
- if (!value) {
26
- const keys = Object.keys(inputValues);
27
- throw new Error(`input values have ${keys.length} keys, you must specify an input key or pass only 1 key as input`);
28
- }
29
- return value;
30
- };
31
- /**
32
- * This function is used by memory classes to select the output value
33
- * to use for the memory. If there is only one output value, it is used.
34
- * If there are multiple output values, the outputKey must be specified.
35
- * If no outputKey is specified, an error is thrown.
36
- */
37
- export const getOutputValue = (outputValues, outputKey) => {
38
- const value = getValue(outputValues, outputKey);
39
- if (!value) {
40
- const keys = Object.keys(outputValues);
41
- throw new Error(`output values have ${keys.length} keys, you must specify an output key or pass only 1 key as output`);
42
- }
43
- return value;
44
- };
45
- /**
46
- * This function is used by memory classes to get a string representation
47
- * of the chat message history, based on the message content and role.
48
- */
49
- export function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
50
- const string_messages = [];
51
- for (const m of messages) {
52
- let role;
53
- if (m._getType() === "human") {
54
- role = humanPrefix;
55
- }
56
- else if (m._getType() === "ai") {
57
- role = aiPrefix;
58
- }
59
- else if (m._getType() === "system") {
60
- role = "System";
61
- }
62
- else if (m._getType() === "function") {
63
- role = "Function";
64
- }
65
- else if (m._getType() === "generic") {
66
- role = m.role;
67
- }
68
- else {
69
- throw new Error(`Got unsupported message type: ${m}`);
70
- }
71
- const nameStr = m.name ? `${m.name}, ` : "";
72
- string_messages.push(`${role}: ${nameStr}${m.content}`);
73
- }
74
- return string_messages.join("\n");
75
- }
76
- /**
77
- * Function used by memory classes to get the key of the prompt input,
78
- * excluding any keys that are memory variables or the "stop" key. If
79
- * there is not exactly one prompt input key, an error is thrown.
80
- */
81
- export function getPromptInputKey(inputs, memoryVariables) {
82
- const promptInputKeys = Object.keys(inputs).filter((key) => !memoryVariables.includes(key) && key !== "stop");
83
- if (promptInputKeys.length !== 1) {
84
- throw new Error(`One input key expected, but got ${promptInputKeys.length}`);
85
- }
86
- return promptInputKeys[0];
87
- }
1
+ export * from "langchain-core/schema/memory";
2
+ export { getBufferString } from "langchain-core/schema/messages";
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = void 0;
4
+ const json_patch_1 = require("langchain-core/util/json_patch");
4
5
  const output_parser_js_1 = require("../schema/output_parser.cjs");
5
- const index_js_1 = require("../util/fast-json-patch/index.cjs");
6
6
  const json_js_1 = require("./json.cjs");
7
7
  /**
8
8
  * Class for parsing the output of an LLM. Can be configured to return
@@ -102,7 +102,7 @@ class JsonOutputFunctionsParser extends output_parser_js_1.BaseCumulativeTransfo
102
102
  if (!next) {
103
103
  return undefined;
104
104
  }
105
- const ops = (0, index_js_1.compare)(prev ?? {}, next);
105
+ const ops = (0, json_patch_1.compare)(prev ?? {}, next);
106
106
  return ops;
107
107
  }
108
108
  async parsePartialResult(generations) {
@@ -1,8 +1,8 @@
1
1
  import { JsonSchema7ObjectType } from "zod-to-json-schema/src/parsers/object.js";
2
+ import { type Operation as JSONPatchOperation } from "langchain-core/util/json_patch";
2
3
  import { ChatGeneration, Generation } from "../schema/index.js";
3
4
  import { Optional } from "../types/type-utils.js";
4
5
  import { BaseCumulativeTransformOutputParser, type BaseCumulativeTransformOutputParserInput, BaseLLMOutputParser } from "../schema/output_parser.js";
5
- import { type Operation as JSONPatchOperation } from "../util/fast-json-patch/index.js";
6
6
  /**
7
7
  * Represents optional parameters for a function in a JSON Schema.
8
8
  */
@@ -1,5 +1,5 @@
1
+ import { compare, } from "langchain-core/util/json_patch";
1
2
  import { BaseCumulativeTransformOutputParser, BaseLLMOutputParser, } from "../schema/output_parser.js";
2
- import { compare, } from "../util/fast-json-patch/index.js";
3
3
  import { parsePartialJson } from "./json.js";
4
4
  /**
5
5
  * Class for parsing the output of an LLM. Can be configured to return
@@ -1,4 +1,4 @@
1
- import { SerializedFields } from "../load/map_keys.js";
1
+ import type { SerializedFields } from "../load/map_keys.js";
2
2
  import { BaseOutputParser } from "../schema/output_parser.js";
3
3
  export interface RegExpFields {
4
4
  pattern: string;
@@ -10,7 +10,7 @@ export declare class StructuredOutputParser<T extends z.ZodTypeAny> extends Base
10
10
  schema: T;
11
11
  static lc_name(): string;
12
12
  lc_namespace: string[];
13
- toJSON(): import("../load/serializable.js").SerializedNotImplemented;
13
+ toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
14
14
  constructor(schema: T);
15
15
  /**
16
16
  * Creates a new StructuredOutputParser from a Zod schema.