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,292 +1 @@
1
- import { AIMessage, HumanMessage, RUN_KEY, coerceMessageLikeToMessage, } from "../schema/index.js";
2
- import { BaseLanguageModel, } from "../base_language/index.js";
3
- import { CallbackManager, } from "../callbacks/manager.js";
4
- /**
5
- * Creates a transform stream for encoding chat message chunks.
6
- * @deprecated Use {@link BytesOutputParser} instead
7
- * @returns A TransformStream instance that encodes chat message chunks.
8
- */
9
- export function createChatMessageChunkEncoderStream() {
10
- const textEncoder = new TextEncoder();
11
- return new TransformStream({
12
- transform(chunk, controller) {
13
- controller.enqueue(textEncoder.encode(typeof chunk.content === "string"
14
- ? chunk.content
15
- : JSON.stringify(chunk.content)));
16
- },
17
- });
18
- }
19
- /**
20
- * Base class for chat models. It extends the BaseLanguageModel class and
21
- * provides methods for generating chat based on input messages.
22
- */
23
- export class BaseChatModel extends BaseLanguageModel {
24
- constructor(fields) {
25
- super(fields);
26
- Object.defineProperty(this, "lc_namespace", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: ["langchain", "chat_models", this._llmType()]
31
- });
32
- }
33
- _separateRunnableConfigFromCallOptions(options) {
34
- const [runnableConfig, callOptions] = super._separateRunnableConfigFromCallOptions(options);
35
- if (callOptions?.timeout && !callOptions.signal) {
36
- callOptions.signal = AbortSignal.timeout(callOptions.timeout);
37
- }
38
- return [runnableConfig, callOptions];
39
- }
40
- /**
41
- * Invokes the chat model with a single input.
42
- * @param input The input for the language model.
43
- * @param options The call options.
44
- * @returns A Promise that resolves to a BaseMessageChunk.
45
- */
46
- async invoke(input, options) {
47
- const promptValue = BaseChatModel._convertInputToPromptValue(input);
48
- const result = await this.generatePrompt([promptValue], options, options?.callbacks);
49
- const chatGeneration = result.generations[0][0];
50
- // TODO: Remove cast after figuring out inheritance
51
- return chatGeneration.message;
52
- }
53
- // eslint-disable-next-line require-yield
54
- async *_streamResponseChunks(_messages, _options, _runManager) {
55
- throw new Error("Not implemented.");
56
- }
57
- async *_streamIterator(input, options) {
58
- // Subclass check required to avoid double callbacks with default implementation
59
- if (this._streamResponseChunks ===
60
- BaseChatModel.prototype._streamResponseChunks) {
61
- yield this.invoke(input, options);
62
- }
63
- else {
64
- const prompt = BaseChatModel._convertInputToPromptValue(input);
65
- const messages = prompt.toChatMessages();
66
- const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptions(options);
67
- const callbackManager_ = await CallbackManager.configure(runnableConfig.callbacks, this.callbacks, runnableConfig.tags, this.tags, runnableConfig.metadata, this.metadata, { verbose: this.verbose });
68
- const extra = {
69
- options: callOptions,
70
- invocation_params: this?.invocationParams(callOptions),
71
- batch_size: 1,
72
- };
73
- const runManagers = await callbackManager_?.handleChatModelStart(this.toJSON(), [messages], undefined, undefined, extra, undefined, undefined, runnableConfig.runName);
74
- let generationChunk;
75
- try {
76
- for await (const chunk of this._streamResponseChunks(messages, callOptions, runManagers?.[0])) {
77
- yield chunk.message;
78
- if (!generationChunk) {
79
- generationChunk = chunk;
80
- }
81
- else {
82
- generationChunk = generationChunk.concat(chunk);
83
- }
84
- }
85
- }
86
- catch (err) {
87
- await Promise.all((runManagers ?? []).map((runManager) => runManager?.handleLLMError(err)));
88
- throw err;
89
- }
90
- await Promise.all((runManagers ?? []).map((runManager) => runManager?.handleLLMEnd({
91
- // TODO: Remove cast after figuring out inheritance
92
- generations: [[generationChunk]],
93
- })));
94
- }
95
- }
96
- /** @ignore */
97
- async _generateUncached(messages, parsedOptions, handledOptions) {
98
- const baseMessages = messages.map((messageList) => messageList.map(coerceMessageLikeToMessage));
99
- // create callback manager and start run
100
- const callbackManager_ = await CallbackManager.configure(handledOptions.callbacks, this.callbacks, handledOptions.tags, this.tags, handledOptions.metadata, this.metadata, { verbose: this.verbose });
101
- const extra = {
102
- options: parsedOptions,
103
- invocation_params: this?.invocationParams(parsedOptions),
104
- batch_size: 1,
105
- };
106
- const runManagers = await callbackManager_?.handleChatModelStart(this.toJSON(), baseMessages, undefined, undefined, extra, undefined, undefined, handledOptions.runName);
107
- // generate results
108
- const results = await Promise.allSettled(baseMessages.map((messageList, i) => this._generate(messageList, { ...parsedOptions, promptIndex: i }, runManagers?.[i])));
109
- // handle results
110
- const generations = [];
111
- const llmOutputs = [];
112
- await Promise.all(results.map(async (pResult, i) => {
113
- if (pResult.status === "fulfilled") {
114
- const result = pResult.value;
115
- generations[i] = result.generations;
116
- llmOutputs[i] = result.llmOutput;
117
- return runManagers?.[i]?.handleLLMEnd({
118
- generations: [result.generations],
119
- llmOutput: result.llmOutput,
120
- });
121
- }
122
- else {
123
- // status === "rejected"
124
- await runManagers?.[i]?.handleLLMError(pResult.reason);
125
- return Promise.reject(pResult.reason);
126
- }
127
- }));
128
- // create combined output
129
- const output = {
130
- generations,
131
- llmOutput: llmOutputs.length
132
- ? this._combineLLMOutput?.(...llmOutputs)
133
- : undefined,
134
- };
135
- Object.defineProperty(output, RUN_KEY, {
136
- value: runManagers
137
- ? { runIds: runManagers?.map((manager) => manager.runId) }
138
- : undefined,
139
- configurable: true,
140
- });
141
- return output;
142
- }
143
- /**
144
- * Generates chat based on the input messages.
145
- * @param messages An array of arrays of BaseMessage instances.
146
- * @param options The call options or an array of stop sequences.
147
- * @param callbacks The callbacks for the language model.
148
- * @returns A Promise that resolves to an LLMResult.
149
- */
150
- async generate(messages, options, callbacks) {
151
- // parse call options
152
- let parsedOptions;
153
- if (Array.isArray(options)) {
154
- parsedOptions = { stop: options };
155
- }
156
- else {
157
- parsedOptions = options;
158
- }
159
- const baseMessages = messages.map((messageList) => messageList.map(coerceMessageLikeToMessage));
160
- const [runnableConfig, callOptions] = this._separateRunnableConfigFromCallOptions(parsedOptions);
161
- runnableConfig.callbacks = runnableConfig.callbacks ?? callbacks;
162
- if (!this.cache) {
163
- return this._generateUncached(baseMessages, callOptions, runnableConfig);
164
- }
165
- const { cache } = this;
166
- const llmStringKey = this._getSerializedCacheKeyParametersForCall(callOptions);
167
- const missingPromptIndices = [];
168
- const generations = await Promise.all(baseMessages.map(async (baseMessage, index) => {
169
- // Join all content into one string for the prompt index
170
- const prompt = BaseChatModel._convertInputToPromptValue(baseMessage).toString();
171
- const result = await cache.lookup(prompt, llmStringKey);
172
- if (!result) {
173
- missingPromptIndices.push(index);
174
- }
175
- return result;
176
- }));
177
- let llmOutput = {};
178
- if (missingPromptIndices.length > 0) {
179
- const results = await this._generateUncached(missingPromptIndices.map((i) => baseMessages[i]), callOptions, runnableConfig);
180
- await Promise.all(results.generations.map(async (generation, index) => {
181
- const promptIndex = missingPromptIndices[index];
182
- generations[promptIndex] = generation;
183
- // Join all content into one string for the prompt index
184
- const prompt = BaseChatModel._convertInputToPromptValue(baseMessages[promptIndex]).toString();
185
- return cache.update(prompt, llmStringKey, generation);
186
- }));
187
- llmOutput = results.llmOutput ?? {};
188
- }
189
- return { generations, llmOutput };
190
- }
191
- /**
192
- * Get the parameters used to invoke the model
193
- */
194
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
195
- invocationParams(_options) {
196
- return {};
197
- }
198
- _modelType() {
199
- return "base_chat_model";
200
- }
201
- /**
202
- * @deprecated
203
- * Return a json-like object representing this LLM.
204
- */
205
- serialize() {
206
- return {
207
- ...this.invocationParams(),
208
- _type: this._llmType(),
209
- _model: this._modelType(),
210
- };
211
- }
212
- /**
213
- * Generates a prompt based on the input prompt values.
214
- * @param promptValues An array of BasePromptValue instances.
215
- * @param options The call options or an array of stop sequences.
216
- * @param callbacks The callbacks for the language model.
217
- * @returns A Promise that resolves to an LLMResult.
218
- */
219
- async generatePrompt(promptValues, options, callbacks) {
220
- const promptMessages = promptValues.map((promptValue) => promptValue.toChatMessages());
221
- return this.generate(promptMessages, options, callbacks);
222
- }
223
- /**
224
- * Makes a single call to the chat model.
225
- * @param messages An array of BaseMessage instances.
226
- * @param options The call options or an array of stop sequences.
227
- * @param callbacks The callbacks for the language model.
228
- * @returns A Promise that resolves to a BaseMessage.
229
- */
230
- async call(messages, options, callbacks) {
231
- const result = await this.generate([messages.map(coerceMessageLikeToMessage)], options, callbacks);
232
- const generations = result.generations;
233
- return generations[0][0].message;
234
- }
235
- /**
236
- * Makes a single call to the chat model with a prompt value.
237
- * @param promptValue The value of the prompt.
238
- * @param options The call options or an array of stop sequences.
239
- * @param callbacks The callbacks for the language model.
240
- * @returns A Promise that resolves to a BaseMessage.
241
- */
242
- async callPrompt(promptValue, options, callbacks) {
243
- const promptMessages = promptValue.toChatMessages();
244
- return this.call(promptMessages, options, callbacks);
245
- }
246
- /**
247
- * Predicts the next message based on the input messages.
248
- * @param messages An array of BaseMessage instances.
249
- * @param options The call options or an array of stop sequences.
250
- * @param callbacks The callbacks for the language model.
251
- * @returns A Promise that resolves to a BaseMessage.
252
- */
253
- async predictMessages(messages, options, callbacks) {
254
- return this.call(messages, options, callbacks);
255
- }
256
- /**
257
- * Predicts the next message based on a text input.
258
- * @param text The text input.
259
- * @param options The call options or an array of stop sequences.
260
- * @param callbacks The callbacks for the language model.
261
- * @returns A Promise that resolves to a string.
262
- */
263
- async predict(text, options, callbacks) {
264
- const message = new HumanMessage(text);
265
- const result = await this.call([message], options, callbacks);
266
- if (typeof result.content !== "string") {
267
- throw new Error("Cannot use predict when output is not a string.");
268
- }
269
- return result.content;
270
- }
271
- }
272
- /**
273
- * An abstract class that extends BaseChatModel and provides a simple
274
- * implementation of _generate.
275
- */
276
- export class SimpleChatModel extends BaseChatModel {
277
- async _generate(messages, options, runManager) {
278
- const text = await this._call(messages, options, runManager);
279
- const message = new AIMessage(text);
280
- if (typeof message.content !== "string") {
281
- throw new Error("Cannot generate with a simple chat model when output is not a string.");
282
- }
283
- return {
284
- generations: [
285
- {
286
- text: message.content,
287
- message,
288
- },
289
- ],
290
- };
291
- }
292
- }
1
+ export * from "langchain-core/chat_model";
@@ -3,7 +3,7 @@ import { BaseBedrockInput, type CredentialType } from "../../util/bedrock.js";
3
3
  import { SimpleChatModel, BaseChatModelParams } from "../base.js";
4
4
  import { CallbackManagerForLLMRun } from "../../callbacks/manager.js";
5
5
  import { BaseMessage, ChatGenerationChunk } from "../../schema/index.js";
6
- import { SerializedFields } from "../../load/map_keys.js";
6
+ import type { SerializedFields } from "../../load/map_keys.js";
7
7
  export declare function convertMessagesToPromptAnthropic(messages: BaseMessage[], humanPrompt?: string, aiPrompt?: string): string;
8
8
  /**
9
9
  * Function that converts an array of messages into a single string prompt
@@ -36,7 +36,7 @@ export declare class ChatFireworks extends ChatOpenAI<ChatFireworksCallOptions>
36
36
  constructor(fields?: Partial<Omit<OpenAIChatInput, "openAIApiKey" | FireworksUnsupportedArgs>> & BaseChatModelParams & {
37
37
  fireworksApiKey?: string;
38
38
  });
39
- toJSON(): import("../load/serializable.js").Serialized;
39
+ toJSON(): import("langchain-core/load/serializable").Serialized;
40
40
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsStreaming, options?: OpenAICoreRequestOptions): Promise<AsyncIterable<OpenAIClient.Chat.Completions.ChatCompletionChunk>>;
41
41
  completionWithRetry(request: OpenAIClient.Chat.ChatCompletionCreateParamsNonStreaming, options?: OpenAICoreRequestOptions): Promise<OpenAIClient.Chat.Completions.ChatCompletion>;
42
42
  }
package/dist/document.cjs CHANGED
@@ -1,27 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Document = void 0;
4
- /**
5
- * Interface for interacting with a document.
6
- */
7
- class Document {
8
- constructor(fields) {
9
- Object.defineProperty(this, "pageContent", {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value: void 0
14
- });
15
- Object.defineProperty(this, "metadata", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.pageContent = fields.pageContent
22
- ? fields.pageContent.toString()
23
- : this.pageContent;
24
- this.metadata = fields.metadata ?? {};
25
- }
26
- }
27
- exports.Document = Document;
4
+ var document_1 = require("langchain-core/schema/document");
5
+ Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
@@ -1,12 +1 @@
1
- export interface DocumentInput<Metadata extends Record<string, any> = Record<string, any>> {
2
- pageContent: string;
3
- metadata?: Metadata;
4
- }
5
- /**
6
- * Interface for interacting with a document.
7
- */
8
- export declare class Document<Metadata extends Record<string, any> = Record<string, any>> implements DocumentInput {
9
- pageContent: string;
10
- metadata: Metadata;
11
- constructor(fields: DocumentInput<Metadata>);
12
- }
1
+ export { type DocumentInput, Document } from "langchain-core/schema/document";
package/dist/document.js CHANGED
@@ -1,23 +1 @@
1
- /**
2
- * Interface for interacting with a document.
3
- */
4
- export class Document {
5
- constructor(fields) {
6
- Object.defineProperty(this, "pageContent", {
7
- enumerable: true,
8
- configurable: true,
9
- writable: true,
10
- value: void 0
11
- });
12
- Object.defineProperty(this, "metadata", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: void 0
17
- });
18
- this.pageContent = fields.pageContent
19
- ? fields.pageContent.toString()
20
- : this.pageContent;
21
- this.metadata = fields.metadata ?? {};
22
- }
23
- }
1
+ export { Document } from "langchain-core/schema/document";
@@ -47,6 +47,6 @@ export declare class AzureBlobStorageFileLoader extends BaseDocumentLoader {
47
47
  * are returned, and the temporary directory is deleted.
48
48
  * @returns An array of documents loaded from the file in Azure Blob Storage.
49
49
  */
50
- load(): Promise<import("../../document.js").Document<Record<string, any>>[]>;
50
+ load(): Promise<import("langchain-core/schema/document").Document<Record<string, any>>[]>;
51
51
  }
52
52
  export {};
@@ -70,5 +70,5 @@ export declare class S3Loader extends BaseDocumentLoader {
70
70
  * and then uses the UnstructuredLoader to load the file as a document.
71
71
  * @returns An array of Document objects representing the loaded documents.
72
72
  */
73
- load(): Promise<import("../../document.js").Document<Record<string, any>>[]>;
73
+ load(): Promise<import("langchain-core/schema/document").Document<Record<string, any>>[]>;
74
74
  }
@@ -1,24 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Embeddings = void 0;
4
- const async_caller_js_1 = require("../util/async_caller.cjs");
5
- /**
6
- * An abstract class that provides methods for embedding documents and
7
- * queries using LangChain.
8
- */
9
- class Embeddings {
10
- constructor(params) {
11
- /**
12
- * The async caller should be used by subclasses to make any async calls,
13
- * which will thus benefit from the concurrency and retry logic.
14
- */
15
- Object.defineProperty(this, "caller", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.caller = new async_caller_js_1.AsyncCaller(params ?? {});
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]; } };
22
7
  }
23
- }
24
- exports.Embeddings = Embeddings;
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/embeddings"), exports);
@@ -1,33 +1 @@
1
- import { AsyncCaller, AsyncCallerParams } from "../util/async_caller.js";
2
- /**
3
- * The parameters required to initialize an instance of the Embeddings
4
- * class.
5
- */
6
- export type EmbeddingsParams = AsyncCallerParams;
7
- /**
8
- * An abstract class that provides methods for embedding documents and
9
- * queries using LangChain.
10
- */
11
- export declare abstract class Embeddings {
12
- /**
13
- * The async caller should be used by subclasses to make any async calls,
14
- * which will thus benefit from the concurrency and retry logic.
15
- */
16
- caller: AsyncCaller;
17
- constructor(params: EmbeddingsParams);
18
- /**
19
- * An abstract method that takes an array of documents as input and
20
- * returns a promise that resolves to an array of vectors for each
21
- * document.
22
- * @param documents An array of documents to be embedded.
23
- * @returns A promise that resolves to an array of vectors for each document.
24
- */
25
- abstract embedDocuments(documents: string[]): Promise<number[][]>;
26
- /**
27
- * An abstract method that takes a single document as input and returns a
28
- * promise that resolves to a vector for the query document.
29
- * @param document A single document to be embedded.
30
- * @returns A promise that resolves to a vector for the query document.
31
- */
32
- abstract embedQuery(document: string): Promise<number[]>;
33
- }
1
+ export * from "langchain-core/schema/embeddings";
@@ -1,20 +1 @@
1
- import { AsyncCaller } from "../util/async_caller.js";
2
- /**
3
- * An abstract class that provides methods for embedding documents and
4
- * queries using LangChain.
5
- */
6
- export class Embeddings {
7
- constructor(params) {
8
- /**
9
- * The async caller should be used by subclasses to make any async calls,
10
- * which will thus benefit from the concurrency and retry logic.
11
- */
12
- Object.defineProperty(this, "caller", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: void 0
17
- });
18
- this.caller = new AsyncCaller(params ?? {});
19
- }
20
- }
1
+ export * from "langchain-core/schema/embeddings";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CacheBackedEmbeddings = void 0;
4
- const hash_js_1 = require("../util/js-sha1/hash.cjs");
4
+ const hash_1 = require("langchain-core/util/hash");
5
5
  const encoder_backed_js_1 = require("../storage/encoder_backed.cjs");
6
6
  const base_js_1 = require("./base.cjs");
7
7
  /**
@@ -130,7 +130,7 @@ class CacheBackedEmbeddings extends base_js_1.Embeddings {
130
130
  const decoder = new TextDecoder();
131
131
  const encoderBackedStore = new encoder_backed_js_1.EncoderBackedStore({
132
132
  store: documentEmbeddingStore,
133
- keyEncoder: (key) => (options?.namespace ?? "") + (0, hash_js_1.insecureHash)(key),
133
+ keyEncoder: (key) => (options?.namespace ?? "") + (0, hash_1.insecureHash)(key),
134
134
  valueSerializer: (value) => encoder.encode(JSON.stringify(value)),
135
135
  valueDeserializer: (serializedValue) => JSON.parse(decoder.decode(serializedValue)),
136
136
  });
@@ -1,4 +1,4 @@
1
- import { insecureHash } from "../util/js-sha1/hash.js";
1
+ import { insecureHash } from "langchain-core/util/hash";
2
2
  import { EncoderBackedStore } from "../storage/encoder_backed.js";
3
3
  import { Embeddings } from "./base.js";
4
4
  /**
@@ -27,7 +27,7 @@ export declare class TrajectoryEvalChain extends AgentTrajectoryEvaluator {
27
27
  requiresInput: boolean;
28
28
  requiresReference: boolean;
29
29
  outputParser: TrajectoryOutputParser;
30
- static resolveTrajectoryPrompt(prompt?: BasePromptTemplate | undefined, agentTools?: StructuredTool[]): import("../../prompts/chat.js").ChatPromptTemplate<any, any> | BasePromptTemplate<any, import("../../schema/index.js").BasePromptValue, any>;
30
+ static resolveTrajectoryPrompt(prompt?: BasePromptTemplate | undefined, agentTools?: StructuredTool[]): BasePromptTemplate<any, import("../../schema/index.js").BasePromptValue, any> | import("../../prompts/index.js").ChatPromptTemplate<any, any>;
31
31
  /**
32
32
  * Get the description of the agent tools.
33
33
  *
@@ -1,12 +1,12 @@
1
1
  import { PromptTemplate } from "../../prompts/index.js";
2
2
  export declare const CRITERIA_PROMPT: PromptTemplate<{
3
- output: any;
4
3
  input: any;
4
+ output: any;
5
5
  criteria: any;
6
6
  }, any>;
7
7
  export declare const PROMPT_WITH_REFERENCES: PromptTemplate<{
8
- output: any;
9
8
  input: any;
9
+ output: any;
10
10
  criteria: any;
11
11
  reference: any;
12
12
  }, any>;
@@ -1,11 +1,11 @@
1
1
  import { PromptTemplate } from "../../prompts/prompt.js";
2
2
  export declare const QA_PROMPT: PromptTemplate<{
3
- query: any;
4
3
  answer: any;
4
+ query: any;
5
5
  result: any;
6
6
  }, any>;
7
7
  export declare const SQL_PROMPT: PromptTemplate<{
8
- query: any;
9
8
  answer: any;
9
+ query: any;
10
10
  result: any;
11
11
  }, any>;
@@ -118,7 +118,7 @@ export declare class MakerSuitePrompt {
118
118
  * will have the parameters (model name, temperature, etc) from those in
119
119
  * MakerSuite.
120
120
  */
121
- toChain(): import("../../../schema/runnable/base.js").RunnableSequence<any, any>;
121
+ toChain(): import("../../../schema/runnable/index.js").RunnableSequence<any, any>;
122
122
  }
123
123
  interface DriveFileReadParams extends GoogleVertexAIConnectionParams<GoogleAuthOptions> {
124
124
  fileId: string;
@@ -10,4 +10,4 @@ export declare const DEFAULT_STEP_EXECUTOR_HUMAN_CHAT_MESSAGE_TEMPLATE = "Previo
10
10
  * @param tools the tools available to the `planner`
11
11
  * @returns
12
12
  */
13
- export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("../../schema/index.js").InputValues<string>, any>>;
13
+ export declare const getPlannerChatPrompt: (tools: Tool[] | DynamicStructuredTool[]) => Promise<ChatPromptTemplate<import("langchain-core/schema").InputValues<string>, any>>;