langchain 0.0.194 → 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 (241) 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/embeddings/hf.cjs +1 -2
  65. package/dist/embeddings/hf.js +1 -2
  66. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  67. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  68. package/dist/evaluation/qa/prompt.d.ts +2 -2
  69. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  70. package/dist/experimental/openai_assistant/index.cjs +2 -1
  71. package/dist/experimental/openai_assistant/index.d.ts +2 -1
  72. package/dist/experimental/openai_assistant/index.js +2 -1
  73. package/dist/experimental/openai_files/index.cjs +88 -0
  74. package/dist/experimental/openai_files/index.d.ts +79 -0
  75. package/dist/experimental/openai_files/index.js +84 -0
  76. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  77. package/dist/llms/base.cjs +15 -278
  78. package/dist/llms/base.d.ts +1 -115
  79. package/dist/llms/base.js +1 -275
  80. package/dist/llms/bedrock/web.d.ts +1 -1
  81. package/dist/llms/fireworks.d.ts +1 -1
  82. package/dist/load/import_constants.cjs +1 -0
  83. package/dist/load/import_constants.js +1 -0
  84. package/dist/load/import_map.cjs +4 -2
  85. package/dist/load/import_map.d.ts +2 -0
  86. package/dist/load/import_map.js +2 -0
  87. package/dist/load/index.cjs +7 -148
  88. package/dist/load/index.js +7 -148
  89. package/dist/load/map_keys.cjs +0 -24
  90. package/dist/load/map_keys.d.ts +0 -6
  91. package/dist/load/map_keys.js +1 -17
  92. package/dist/load/serializable.cjs +15 -178
  93. package/dist/load/serializable.d.ts +1 -66
  94. package/dist/load/serializable.js +1 -175
  95. package/dist/memory/base.cjs +17 -92
  96. package/dist/memory/base.d.ts +2 -68
  97. package/dist/memory/base.js +2 -87
  98. package/dist/output_parsers/openai_functions.cjs +2 -2
  99. package/dist/output_parsers/openai_functions.d.ts +1 -1
  100. package/dist/output_parsers/openai_functions.js +1 -1
  101. package/dist/output_parsers/regex.d.ts +1 -1
  102. package/dist/output_parsers/structured.d.ts +1 -1
  103. package/dist/prompts/base.cjs +8 -183
  104. package/dist/prompts/base.d.ts +3 -132
  105. package/dist/prompts/base.js +3 -178
  106. package/dist/prompts/chat.cjs +15 -477
  107. package/dist/prompts/chat.d.ts +1 -219
  108. package/dist/prompts/chat.js +1 -466
  109. package/dist/prompts/few_shot.cjs +15 -353
  110. package/dist/prompts/few_shot.d.ts +1 -192
  111. package/dist/prompts/few_shot.js +1 -350
  112. package/dist/prompts/index.cjs +3 -2
  113. package/dist/prompts/index.d.ts +2 -1
  114. package/dist/prompts/index.js +2 -1
  115. package/dist/prompts/pipeline.cjs +15 -142
  116. package/dist/prompts/pipeline.d.ts +1 -98
  117. package/dist/prompts/pipeline.js +1 -140
  118. package/dist/prompts/prompt.cjs +15 -146
  119. package/dist/prompts/prompt.d.ts +1 -92
  120. package/dist/prompts/prompt.js +1 -144
  121. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
  122. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  123. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  124. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  125. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  126. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  127. package/dist/prompts/selectors/conditional.cjs +15 -74
  128. package/dist/prompts/selectors/conditional.d.ts +1 -63
  129. package/dist/prompts/selectors/conditional.js +1 -69
  130. package/dist/prompts/serde.cjs +15 -0
  131. package/dist/prompts/serde.d.ts +1 -43
  132. package/dist/prompts/serde.js +1 -1
  133. package/dist/prompts/template.cjs +14 -88
  134. package/dist/prompts/template.d.ts +1 -36
  135. package/dist/prompts/template.js +1 -83
  136. package/dist/retrievers/chaindesk.cjs +9 -1
  137. package/dist/retrievers/chaindesk.d.ts +3 -1
  138. package/dist/retrievers/chaindesk.js +9 -1
  139. package/dist/retrievers/self_query/vectara.cjs +138 -0
  140. package/dist/retrievers/self_query/vectara.d.ts +41 -0
  141. package/dist/retrievers/self_query/vectara.js +134 -0
  142. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  143. package/dist/runnables/index.d.ts +1 -0
  144. package/dist/runnables/index.js +1 -0
  145. package/dist/schema/document.cjs +3 -34
  146. package/dist/schema/document.d.ts +2 -29
  147. package/dist/schema/document.js +2 -32
  148. package/dist/schema/index.cjs +37 -612
  149. package/dist/schema/index.d.ts +11 -311
  150. package/dist/schema/index.js +8 -583
  151. package/dist/schema/output_parser.cjs +15 -309
  152. package/dist/schema/output_parser.d.ts +1 -173
  153. package/dist/schema/output_parser.js +1 -301
  154. package/dist/schema/retriever.cjs +15 -77
  155. package/dist/schema/retriever.d.ts +1 -43
  156. package/dist/schema/retriever.js +1 -75
  157. package/dist/schema/runnable/base.cjs +10 -1072
  158. package/dist/schema/runnable/base.d.ts +1 -356
  159. package/dist/schema/runnable/base.js +1 -1060
  160. package/dist/schema/runnable/branch.cjs +2 -131
  161. package/dist/schema/runnable/branch.d.ts +1 -94
  162. package/dist/schema/runnable/branch.js +1 -130
  163. package/dist/schema/runnable/config.cjs +0 -6
  164. package/dist/schema/runnable/config.d.ts +1 -3
  165. package/dist/schema/runnable/config.js +1 -4
  166. package/dist/schema/runnable/index.cjs +15 -16
  167. package/dist/schema/runnable/index.d.ts +1 -5
  168. package/dist/schema/runnable/index.js +1 -4
  169. package/dist/schema/runnable/passthrough.cjs +3 -113
  170. package/dist/schema/runnable/passthrough.d.ts +1 -72
  171. package/dist/schema/runnable/passthrough.js +1 -111
  172. package/dist/schema/runnable/router.cjs +2 -71
  173. package/dist/schema/runnable/router.d.ts +1 -29
  174. package/dist/schema/runnable/router.js +1 -70
  175. package/dist/schema/storage.cjs +15 -8
  176. package/dist/schema/storage.d.ts +1 -57
  177. package/dist/schema/storage.js +1 -6
  178. package/dist/tools/bingserpapi.d.ts +1 -1
  179. package/dist/tools/searchapi.d.ts +1 -1
  180. package/dist/tools/serpapi.d.ts +1 -1
  181. package/dist/tools/serper.d.ts +1 -1
  182. package/dist/util/async_caller.cjs +14 -128
  183. package/dist/util/async_caller.d.ts +1 -45
  184. package/dist/util/async_caller.js +1 -124
  185. package/dist/vectorstores/vectara.cjs +77 -7
  186. package/dist/vectorstores/vectara.d.ts +9 -3
  187. package/dist/vectorstores/vectara.js +54 -7
  188. package/experimental/openai_files.cjs +1 -0
  189. package/experimental/openai_files.d.ts +1 -0
  190. package/experimental/openai_files.js +1 -0
  191. package/package.json +27 -5
  192. package/retrievers/self_query/vectara.cjs +1 -0
  193. package/retrievers/self_query/vectara.d.ts +1 -0
  194. package/retrievers/self_query/vectara.js +1 -0
  195. package/runnables.cjs +1 -0
  196. package/runnables.d.ts +1 -0
  197. package/runnables.js +1 -0
  198. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  199. package/dist/util/@cfworker/json-schema/index.js +0 -1
  200. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  201. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  202. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  203. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  204. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  205. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  206. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  207. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  208. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  209. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  210. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  211. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  212. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  213. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  214. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  215. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  216. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  217. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  218. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  219. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  220. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  221. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  222. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  223. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  224. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  225. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  226. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  227. package/dist/util/fast-json-patch/index.cjs +0 -49
  228. package/dist/util/fast-json-patch/index.d.ts +0 -22
  229. package/dist/util/fast-json-patch/index.js +0 -16
  230. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  231. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  232. package/dist/util/fast-json-patch/src/core.js +0 -459
  233. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  234. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  235. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  236. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  237. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  238. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  239. package/dist/util/js-sha1/hash.cjs +0 -358
  240. package/dist/util/js-sha1/hash.d.ts +0 -1
  241. package/dist/util/js-sha1/hash.js +0 -355
@@ -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.
@@ -1,185 +1,10 @@
1
1
  "use strict";
2
- // Default generic "any" values are for backwards compatibility.
3
- // Replace with "string" when we are comfortable with a breaking change.
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.BaseExampleSelector = exports.BaseStringPromptTemplate = exports.BasePromptTemplate = exports.StringPromptValue = void 0;
6
- const index_js_1 = require("../schema/index.cjs");
7
- const serializable_js_1 = require("../load/serializable.cjs");
8
- const index_js_2 = require("../schema/runnable/index.cjs");
9
- /**
10
- * Represents a prompt value as a string. It extends the BasePromptValue
11
- * class and overrides the toString and toChatMessages methods.
12
- */
13
- class StringPromptValue extends index_js_1.BasePromptValue {
14
- constructor(value) {
15
- super({ value });
16
- Object.defineProperty(this, "lc_namespace", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: ["langchain", "prompts", "base"]
21
- });
22
- Object.defineProperty(this, "value", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: void 0
27
- });
28
- this.value = value;
29
- }
30
- toString() {
31
- return this.value;
32
- }
33
- toChatMessages() {
34
- return [new index_js_1.HumanMessage(this.value)];
35
- }
36
- }
37
- exports.StringPromptValue = StringPromptValue;
38
- /**
39
- * Base class for prompt templates. Exposes a format method that returns a
40
- * string prompt given a set of input values.
41
- */
42
- class BasePromptTemplate extends index_js_2.Runnable {
43
- get lc_attributes() {
44
- return {
45
- partialVariables: undefined, // python doesn't support this yet
46
- };
47
- }
48
- constructor(input) {
49
- super(input);
50
- Object.defineProperty(this, "lc_serializable", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: true
55
- });
56
- Object.defineProperty(this, "lc_namespace", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: ["langchain", "prompts", this._getPromptType()]
61
- });
62
- Object.defineProperty(this, "inputVariables", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- Object.defineProperty(this, "outputParser", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: void 0
73
- });
74
- Object.defineProperty(this, "partialVariables", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: void 0
79
- });
80
- const { inputVariables } = input;
81
- if (inputVariables.includes("stop")) {
82
- throw new Error("Cannot have an input variable named 'stop', as it is used internally, please rename.");
83
- }
84
- Object.assign(this, input);
85
- }
86
- /**
87
- * Merges partial variables and user variables.
88
- * @param userVariables The user variables to merge with the partial variables.
89
- * @returns A Promise that resolves to an object containing the merged variables.
90
- */
91
- async mergePartialAndUserVariables(userVariables) {
92
- const partialVariables = this.partialVariables ?? {};
93
- const partialValues = {};
94
- for (const [key, value] of Object.entries(partialVariables)) {
95
- if (typeof value === "string") {
96
- partialValues[key] = value;
97
- }
98
- else {
99
- partialValues[key] = await value();
100
- }
101
- }
102
- const allKwargs = {
103
- ...partialValues,
104
- ...userVariables,
105
- };
106
- return allKwargs;
107
- }
108
- /**
109
- * Invokes the prompt template with the given input and options.
110
- * @param input The input to invoke the prompt template with.
111
- * @param options Optional configuration for the callback.
112
- * @returns A Promise that resolves to the output of the prompt template.
113
- */
114
- async invoke(input, options) {
115
- return this._callWithConfig((input) => this.formatPromptValue(input), input, { ...options, runType: "prompt" });
116
- }
117
- /**
118
- * Return a json-like object representing this prompt template.
119
- * @deprecated
120
- */
121
- serialize() {
122
- throw new Error("Use .toJSON() instead");
123
- }
124
- /**
125
- * @deprecated
126
- * Load a prompt template from a json-like object describing it.
127
- *
128
- * @remarks
129
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
130
- * reference remote resources that we read asynchronously with a web
131
- * request.
132
- */
133
- static async deserialize(data) {
134
- switch (data._type) {
135
- case "prompt": {
136
- const { PromptTemplate } = await import("./prompt.js");
137
- return PromptTemplate.deserialize(data);
138
- }
139
- case undefined: {
140
- const { PromptTemplate } = await import("./prompt.js");
141
- return PromptTemplate.deserialize({ ...data, _type: "prompt" });
142
- }
143
- case "few_shot": {
144
- const { FewShotPromptTemplate } = await import("./few_shot.js");
145
- return FewShotPromptTemplate.deserialize(data);
146
- }
147
- default:
148
- throw new Error(`Invalid prompt type in config: ${data._type}`);
149
- }
150
- }
151
- }
152
- exports.BasePromptTemplate = BasePromptTemplate;
153
- /**
154
- * Base class for string prompt templates. It extends the
155
- * BasePromptTemplate class and overrides the formatPromptValue method to
156
- * return a StringPromptValue.
157
- */
158
- class BaseStringPromptTemplate extends BasePromptTemplate {
159
- /**
160
- * Formats the prompt given the input values and returns a formatted
161
- * prompt value.
162
- * @param values The input values to format the prompt.
163
- * @returns A Promise that resolves to a formatted prompt value.
164
- */
165
- async formatPromptValue(values) {
166
- const formattedPrompt = await this.format(values);
167
- return new StringPromptValue(formattedPrompt);
168
- }
169
- }
170
- exports.BaseStringPromptTemplate = BaseStringPromptTemplate;
171
- /**
172
- * Base class for example selectors.
173
- */
174
- class BaseExampleSelector extends serializable_js_1.Serializable {
175
- constructor() {
176
- super(...arguments);
177
- Object.defineProperty(this, "lc_namespace", {
178
- enumerable: true,
179
- configurable: true,
180
- writable: true,
181
- value: ["langchain", "prompts", "selectors"]
182
- });
183
- }
184
- }
185
- exports.BaseExampleSelector = BaseExampleSelector;
3
+ exports.BaseExampleSelector = exports.BasePromptTemplate = exports.BaseStringPromptTemplate = exports.StringPromptValue = void 0;
4
+ var base_1 = require("langchain-core/prompts/base");
5
+ Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: function () { return base_1.StringPromptValue; } });
6
+ Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return base_1.BaseStringPromptTemplate; } });
7
+ var prompt_template_1 = require("langchain-core/schema/prompt_template");
8
+ Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return prompt_template_1.BasePromptTemplate; } });
9
+ var base_2 = require("langchain-core/prompts/example_selector/base");
10
+ Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_2.BaseExampleSelector; } });
@@ -1,132 +1,3 @@
1
- import { BasePromptValue, Example, HumanMessage, InputValues, PartialValues } from "../schema/index.js";
2
- import { BaseOutputParser } from "../schema/output_parser.js";
3
- import { Serializable } from "../load/serializable.js";
4
- import { SerializedBasePromptTemplate } from "./serde.js";
5
- import { SerializedFields } from "../load/map_keys.js";
6
- import { Runnable } from "../schema/runnable/index.js";
7
- import { BaseCallbackConfig } from "../callbacks/manager.js";
8
- import type { StringWithAutocomplete } from "../util/types.js";
9
- export type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;
10
- /**
11
- * Represents a prompt value as a string. It extends the BasePromptValue
12
- * class and overrides the toString and toChatMessages methods.
13
- */
14
- export declare class StringPromptValue extends BasePromptValue {
15
- lc_namespace: string[];
16
- value: string;
17
- constructor(value: string);
18
- toString(): string;
19
- toChatMessages(): HumanMessage[];
20
- }
21
- /**
22
- * Input common to all prompt templates.
23
- */
24
- export interface BasePromptTemplateInput<InputVariables extends InputValues = any, PartialVariableName extends string = any> {
25
- /**
26
- * A list of variable names the prompt template expects
27
- */
28
- inputVariables: Array<Extract<keyof InputVariables, string>>;
29
- /**
30
- * How to parse the output of calling an LLM on this formatted prompt
31
- */
32
- outputParser?: BaseOutputParser;
33
- /** Partial variables */
34
- partialVariables?: PartialValues<PartialVariableName>;
35
- }
36
- /**
37
- * Base class for prompt templates. Exposes a format method that returns a
38
- * string prompt given a set of input values.
39
- */
40
- export declare abstract class BasePromptTemplate<RunInput extends InputValues = any, RunOutput extends BasePromptValue = BasePromptValue, PartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {
41
- PromptValueReturnType: RunOutput;
42
- lc_serializable: boolean;
43
- lc_namespace: string[];
44
- get lc_attributes(): SerializedFields | undefined;
45
- inputVariables: Array<Extract<keyof RunInput, string>>;
46
- outputParser?: BaseOutputParser;
47
- partialVariables: PartialValues<PartialVariableName>;
48
- constructor(input: BasePromptTemplateInput);
49
- abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;
50
- /**
51
- * Merges partial variables and user variables.
52
- * @param userVariables The user variables to merge with the partial variables.
53
- * @returns A Promise that resolves to an object containing the merged variables.
54
- */
55
- mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;
56
- /**
57
- * Invokes the prompt template with the given input and options.
58
- * @param input The input to invoke the prompt template with.
59
- * @param options Optional configuration for the callback.
60
- * @returns A Promise that resolves to the output of the prompt template.
61
- */
62
- invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;
63
- /**
64
- * Format the prompt given the input values.
65
- *
66
- * @param values - A dictionary of arguments to be passed to the prompt template.
67
- * @returns A formatted prompt string.
68
- *
69
- * @example
70
- * ```ts
71
- * prompt.format({ foo: "bar" });
72
- * ```
73
- */
74
- abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;
75
- /**
76
- * Format the prompt given the input values and return a formatted prompt value.
77
- * @param values
78
- * @returns A formatted PromptValue.
79
- */
80
- abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;
81
- /**
82
- * Return the string type key uniquely identifying this class of prompt template.
83
- */
84
- abstract _getPromptType(): string;
85
- /**
86
- * Return a json-like object representing this prompt template.
87
- * @deprecated
88
- */
89
- serialize(): SerializedBasePromptTemplate;
90
- /**
91
- * @deprecated
92
- * Load a prompt template from a json-like object describing it.
93
- *
94
- * @remarks
95
- * Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
96
- * reference remote resources that we read asynchronously with a web
97
- * request.
98
- */
99
- static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValue, string>>;
100
- }
101
- /**
102
- * Base class for string prompt templates. It extends the
103
- * BasePromptTemplate class and overrides the formatPromptValue method to
104
- * return a StringPromptValue.
105
- */
106
- export declare abstract class BaseStringPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplate<RunInput, StringPromptValue, PartialVariableName> {
107
- /**
108
- * Formats the prompt given the input values and returns a formatted
109
- * prompt value.
110
- * @param values The input values to format the prompt.
111
- * @returns A Promise that resolves to a formatted prompt value.
112
- */
113
- formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<StringPromptValue>;
114
- }
115
- /**
116
- * Base class for example selectors.
117
- */
118
- export declare abstract class BaseExampleSelector extends Serializable {
119
- lc_namespace: string[];
120
- /**
121
- * Adds an example to the example selector.
122
- * @param example The example to add to the example selector.
123
- * @returns A Promise that resolves to void or a string.
124
- */
125
- abstract addExample(example: Example): Promise<void | string>;
126
- /**
127
- * Selects examples from the example selector given the input variables.
128
- * @param input_variables The input variables to select examples with.
129
- * @returns A Promise that resolves to an array of selected examples.
130
- */
131
- abstract selectExamples(input_variables: Example): Promise<Example[]>;
132
- }
1
+ export { type TypedPromptInputValues, StringPromptValue, BaseStringPromptTemplate, } from "langchain-core/prompts/base";
2
+ export { type BasePromptTemplateInput, BasePromptTemplate, } from "langchain-core/schema/prompt_template";
3
+ export { BaseExampleSelector } from "langchain-core/prompts/example_selector/base";