@langchain/core 0.1.20 → 0.1.22

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 (70) hide show
  1. package/agents.d.cts +1 -0
  2. package/caches.d.cts +1 -0
  3. package/callbacks/base.d.cts +1 -0
  4. package/callbacks/manager.d.cts +1 -0
  5. package/callbacks/promises.d.cts +1 -0
  6. package/chat_history.d.cts +1 -0
  7. package/dist/load/import_type.cjs +3 -0
  8. package/dist/load/import_type.d.ts +4 -0
  9. package/dist/load/import_type.js +2 -0
  10. package/dist/messages/index.cjs +3 -0
  11. package/dist/messages/index.d.ts +5 -2
  12. package/dist/messages/index.js +3 -0
  13. package/dist/prompt_values.cjs +62 -1
  14. package/dist/prompt_values.d.ts +25 -0
  15. package/dist/prompt_values.js +60 -0
  16. package/dist/prompts/chat.cjs +235 -27
  17. package/dist/prompts/chat.d.ts +35 -10
  18. package/dist/prompts/chat.js +235 -27
  19. package/dist/prompts/image.cjs +115 -0
  20. package/dist/prompts/image.d.ts +56 -0
  21. package/dist/prompts/image.js +111 -0
  22. package/dist/prompts/prompt.d.ts +3 -2
  23. package/dist/prompts/serde.d.ts +2 -1
  24. package/dist/prompts/template.cjs +22 -1
  25. package/dist/prompts/template.d.ts +2 -1
  26. package/dist/prompts/template.js +22 -1
  27. package/dist/runnables/base.cjs +6 -5
  28. package/dist/runnables/base.d.ts +3 -3
  29. package/dist/runnables/base.js +6 -5
  30. package/dist/utils/stream.cjs +3 -0
  31. package/dist/utils/stream.js +3 -0
  32. package/documents.d.cts +1 -0
  33. package/embeddings.d.cts +1 -0
  34. package/example_selectors.d.cts +1 -0
  35. package/language_models/base.d.cts +1 -0
  36. package/language_models/chat_models.d.cts +1 -0
  37. package/language_models/llms.d.cts +1 -0
  38. package/load/serializable.d.cts +1 -0
  39. package/load.d.cts +1 -0
  40. package/memory.d.cts +1 -0
  41. package/messages.d.cts +1 -0
  42. package/output_parsers.d.cts +1 -0
  43. package/outputs.d.cts +1 -0
  44. package/package.json +268 -47
  45. package/prompt_values.d.cts +1 -0
  46. package/prompts.d.cts +1 -0
  47. package/retrievers.d.cts +1 -0
  48. package/runnables.d.cts +1 -0
  49. package/stores.d.cts +1 -0
  50. package/tools.d.cts +1 -0
  51. package/tracers/base.d.cts +1 -0
  52. package/tracers/console.d.cts +1 -0
  53. package/tracers/initialize.d.cts +1 -0
  54. package/tracers/log_stream.d.cts +1 -0
  55. package/tracers/run_collector.d.cts +1 -0
  56. package/tracers/tracer_langchain.d.cts +1 -0
  57. package/tracers/tracer_langchain_v1.d.cts +1 -0
  58. package/utils/async_caller.d.cts +1 -0
  59. package/utils/chunk_array.d.cts +1 -0
  60. package/utils/env.d.cts +1 -0
  61. package/utils/function_calling.d.cts +1 -0
  62. package/utils/hash.d.cts +1 -0
  63. package/utils/json_patch.d.cts +1 -0
  64. package/utils/json_schema.d.cts +1 -0
  65. package/utils/math.d.cts +1 -0
  66. package/utils/stream.d.cts +1 -0
  67. package/utils/testing.d.cts +1 -0
  68. package/utils/tiktoken.d.cts +1 -0
  69. package/utils/types.d.cts +1 -0
  70. package/vectorstores.d.cts +1 -0
@@ -74,7 +74,28 @@ export const checkValidTemplate = (template, templateFormat, inputVariables) =>
74
74
  acc[v] = "foo";
75
75
  return acc;
76
76
  }, {});
77
- renderTemplate(template, templateFormat, dummyInputs);
77
+ if (Array.isArray(template)) {
78
+ template.forEach((message) => {
79
+ if (message.type === "text") {
80
+ renderTemplate(message.text, templateFormat, dummyInputs);
81
+ }
82
+ else if (message.type === "image_url") {
83
+ if (typeof message.image_url === "string") {
84
+ renderTemplate(message.image_url, templateFormat, dummyInputs);
85
+ }
86
+ else {
87
+ const imageUrl = message.image_url.url;
88
+ renderTemplate(imageUrl, templateFormat, dummyInputs);
89
+ }
90
+ }
91
+ else {
92
+ throw new Error(`Invalid message template received. ${JSON.stringify(message, null, 2)}`);
93
+ }
94
+ });
95
+ }
96
+ else {
97
+ renderTemplate(template, templateFormat, dummyInputs);
98
+ }
78
99
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
100
  }
80
101
  catch (e) {
@@ -370,9 +370,10 @@ class Runnable extends serializable_js_1.Serializable {
370
370
  copiedCallbacks.inheritableHandlers.push(stream);
371
371
  config.callbacks = copiedCallbacks;
372
372
  }
373
- const runnableStream = await this.stream(input, config);
373
+ const runnableStreamPromise = this.stream(input, config);
374
374
  async function consumeRunnableStream() {
375
375
  try {
376
+ const runnableStream = await runnableStreamPromise;
376
377
  for await (const chunk of runnableStream) {
377
378
  const patch = new log_stream_js_1.RunLogPatch({
378
379
  ops: [
@@ -390,14 +391,14 @@ class Runnable extends serializable_js_1.Serializable {
390
391
  await stream.writer.close();
391
392
  }
392
393
  }
393
- const runnableStreamPromise = consumeRunnableStream();
394
+ const runnableStreamConsumePromise = consumeRunnableStream();
394
395
  try {
395
396
  for await (const log of stream) {
396
397
  yield log;
397
398
  }
398
399
  }
399
400
  finally {
400
- await runnableStreamPromise;
401
+ await runnableStreamConsumePromise;
401
402
  }
402
403
  }
403
404
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1083,7 +1084,7 @@ class RunnableLambda extends Runnable {
1083
1084
  });
1084
1085
  }
1085
1086
  async _invoke(input, config, runManager) {
1086
- let output = await this.func(input, { config });
1087
+ let output = await this.func(input, { ...config, config });
1087
1088
  if (output && Runnable.isRunnable(output)) {
1088
1089
  if (config?.recursionLimit === 0) {
1089
1090
  throw new Error("Recursion limit reached.");
@@ -1115,7 +1116,7 @@ class RunnableLambda extends Runnable {
1115
1116
  }
1116
1117
  }
1117
1118
  }
1118
- const output = await this.func(finalChunk, { config });
1119
+ const output = await this.func(finalChunk, { ...config, config });
1119
1120
  if (output && Runnable.isRunnable(output)) {
1120
1121
  if (config?.recursionLimit === 0) {
1121
1122
  throw new Error("Recursion limit reached.");
@@ -23,11 +23,11 @@ export interface RunnableInterface<RunInput = any, RunOutput = any, CallOptions
23
23
  stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStreamInterface<RunOutput>>;
24
24
  transform(generator: AsyncGenerator<RunInput>, options: Partial<CallOptions>): AsyncGenerator<RunOutput>;
25
25
  }
26
- export type RunnableFunc<RunInput, RunOutput> = (input: RunInput, options?: {
26
+ export type RunnableFunc<RunInput, RunOutput> = (input: RunInput, options?: ({
27
27
  config?: RunnableConfig;
28
- } | Record<string, any> | (Record<string, any> & {
28
+ } & RunnableConfig) | Record<string, any> | (Record<string, any> & {
29
29
  config: RunnableConfig;
30
- })) => RunOutput | Promise<RunOutput>;
30
+ } & RunnableConfig)) => RunOutput | Promise<RunOutput>;
31
31
  export type RunnableMapLike<RunInput, RunOutput> = {
32
32
  [K in keyof RunOutput]: RunnableLike<RunInput, RunOutput[K]>;
33
33
  };
@@ -363,9 +363,10 @@ export class Runnable extends Serializable {
363
363
  copiedCallbacks.inheritableHandlers.push(stream);
364
364
  config.callbacks = copiedCallbacks;
365
365
  }
366
- const runnableStream = await this.stream(input, config);
366
+ const runnableStreamPromise = this.stream(input, config);
367
367
  async function consumeRunnableStream() {
368
368
  try {
369
+ const runnableStream = await runnableStreamPromise;
369
370
  for await (const chunk of runnableStream) {
370
371
  const patch = new RunLogPatch({
371
372
  ops: [
@@ -383,14 +384,14 @@ export class Runnable extends Serializable {
383
384
  await stream.writer.close();
384
385
  }
385
386
  }
386
- const runnableStreamPromise = consumeRunnableStream();
387
+ const runnableStreamConsumePromise = consumeRunnableStream();
387
388
  try {
388
389
  for await (const log of stream) {
389
390
  yield log;
390
391
  }
391
392
  }
392
393
  finally {
393
- await runnableStreamPromise;
394
+ await runnableStreamConsumePromise;
394
395
  }
395
396
  }
396
397
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1070,7 +1071,7 @@ export class RunnableLambda extends Runnable {
1070
1071
  });
1071
1072
  }
1072
1073
  async _invoke(input, config, runManager) {
1073
- let output = await this.func(input, { config });
1074
+ let output = await this.func(input, { ...config, config });
1074
1075
  if (output && Runnable.isRunnable(output)) {
1075
1076
  if (config?.recursionLimit === 0) {
1076
1077
  throw new Error("Recursion limit reached.");
@@ -1102,7 +1103,7 @@ export class RunnableLambda extends Runnable {
1102
1103
  }
1103
1104
  }
1104
1105
  }
1105
- const output = await this.func(finalChunk, { config });
1106
+ const output = await this.func(finalChunk, { ...config, config });
1106
1107
  if (output && Runnable.isRunnable(output)) {
1107
1108
  if (config?.recursionLimit === 0) {
1108
1109
  throw new Error("Recursion limit reached.");
@@ -101,6 +101,9 @@ class IterableReadableStream extends ReadableStream {
101
101
  // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
102
102
  controller.enqueue(value);
103
103
  },
104
+ async cancel(reason) {
105
+ await generator.return(reason);
106
+ },
104
107
  });
105
108
  }
106
109
  }
@@ -98,6 +98,9 @@ export class IterableReadableStream extends ReadableStream {
98
98
  // Fix: `else if (value)` will hang the streaming when nullish value (e.g. empty string) is pulled
99
99
  controller.enqueue(value);
100
100
  },
101
+ async cancel(reason) {
102
+ await generator.return(reason);
103
+ },
101
104
  });
102
105
  }
103
106
  }
@@ -0,0 +1 @@
1
+ export * from './dist/documents/index.js'
@@ -0,0 +1 @@
1
+ export * from './dist/embeddings.js'
@@ -0,0 +1 @@
1
+ export * from './dist/example_selectors/index.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/language_models/base.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/language_models/chat_models.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/language_models/llms.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/load/serializable.js'
package/load.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/load/index.js'
package/memory.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/memory.js'
package/messages.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/messages/index.js'
@@ -0,0 +1 @@
1
+ export * from './dist/output_parsers/index.js'
package/outputs.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/outputs.js'