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,126 +1 @@
1
- import * as uuid from "uuid";
2
- import { Serializable, get_lc_unique_name, } from "../load/serializable.js";
3
- /**
4
- * Abstract class that provides a set of optional methods that can be
5
- * overridden in derived classes to handle various events during the
6
- * execution of a LangChain application.
7
- */
8
- class BaseCallbackHandlerMethodsClass {
9
- }
10
- /**
11
- * Abstract base class for creating callback handlers in the LangChain
12
- * framework. It provides a set of optional methods that can be overridden
13
- * in derived classes to handle various events during the execution of a
14
- * LangChain application.
15
- */
16
- export class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
17
- get lc_namespace() {
18
- return ["langchain", "callbacks", this.name];
19
- }
20
- get lc_secrets() {
21
- return undefined;
22
- }
23
- get lc_attributes() {
24
- return undefined;
25
- }
26
- get lc_aliases() {
27
- return undefined;
28
- }
29
- /**
30
- * The name of the serializable. Override to provide an alias or
31
- * to preserve the serialized module name in minified environments.
32
- *
33
- * Implemented as a static method to support loading logic.
34
- */
35
- static lc_name() {
36
- return this.name;
37
- }
38
- /**
39
- * The final serialized identifier for the module.
40
- */
41
- get lc_id() {
42
- return [
43
- ...this.lc_namespace,
44
- get_lc_unique_name(this.constructor),
45
- ];
46
- }
47
- constructor(input) {
48
- super();
49
- Object.defineProperty(this, "lc_serializable", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: false
54
- });
55
- Object.defineProperty(this, "lc_kwargs", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
- Object.defineProperty(this, "ignoreLLM", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: false
66
- });
67
- Object.defineProperty(this, "ignoreChain", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: false
72
- });
73
- Object.defineProperty(this, "ignoreAgent", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: false
78
- });
79
- Object.defineProperty(this, "ignoreRetriever", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: false
84
- });
85
- Object.defineProperty(this, "awaitHandlers", {
86
- enumerable: true,
87
- configurable: true,
88
- writable: true,
89
- value: typeof process !== "undefined"
90
- ? // eslint-disable-next-line no-process-env
91
- process.env?.LANGCHAIN_CALLBACKS_BACKGROUND !== "true"
92
- : true
93
- });
94
- this.lc_kwargs = input || {};
95
- if (input) {
96
- this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
97
- this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
98
- this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
99
- this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
100
- }
101
- }
102
- copy() {
103
- return new this.constructor(this);
104
- }
105
- toJSON() {
106
- return Serializable.prototype.toJSON.call(this);
107
- }
108
- toJSONNotImplemented() {
109
- return Serializable.prototype.toJSONNotImplemented.call(this);
110
- }
111
- static fromMethods(methods) {
112
- class Handler extends BaseCallbackHandler {
113
- constructor() {
114
- super();
115
- Object.defineProperty(this, "name", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: uuid.v4()
120
- });
121
- Object.assign(this, methods);
122
- }
123
- }
124
- return new Handler();
125
- }
126
- }
1
+ export * from "langchain-core/callbacks/base";
@@ -1,224 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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]; } };
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);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ConsoleCallbackHandler = void 0;
7
- const ansi_styles_1 = __importDefault(require("ansi-styles"));
8
- const tracer_js_1 = require("./tracer.cjs");
9
- function wrap(style, text) {
10
- return `${style.open}${text}${style.close}`;
11
- }
12
- function tryJsonStringify(obj, fallback) {
13
- try {
14
- return JSON.stringify(obj, null, 2);
15
- }
16
- catch (err) {
17
- return fallback;
18
- }
19
- }
20
- function elapsed(run) {
21
- if (!run.end_time)
22
- return "";
23
- const elapsed = run.end_time - run.start_time;
24
- if (elapsed < 1000) {
25
- return `${elapsed}ms`;
26
- }
27
- return `${(elapsed / 1000).toFixed(2)}s`;
28
- }
29
- const { color } = ansi_styles_1.default;
30
- /**
31
- * A tracer that logs all events to the console. It extends from the
32
- * `BaseTracer` class and overrides its methods to provide custom logging
33
- * functionality.
34
- * @example
35
- * ```typescript
36
- *
37
- * const llm = new ChatAnthropic({
38
- * temperature: 0,
39
- * tags: ["example", "callbacks", "constructor"],
40
- * callbacks: [new ConsoleCallbackHandler()],
41
- * });
42
- *
43
- * ```
44
- */
45
- class ConsoleCallbackHandler extends tracer_js_1.BaseTracer {
46
- constructor() {
47
- super(...arguments);
48
- Object.defineProperty(this, "name", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: "console_callback_handler"
53
- });
54
- }
55
- /**
56
- * Method used to persist the run. In this case, it simply returns a
57
- * resolved promise as there's no persistence logic.
58
- * @param _run The run to persist.
59
- * @returns A resolved promise.
60
- */
61
- persistRun(_run) {
62
- return Promise.resolve();
63
- }
64
- // utility methods
65
- /**
66
- * Method used to get all the parent runs of a given run.
67
- * @param run The run whose parents are to be retrieved.
68
- * @returns An array of parent runs.
69
- */
70
- getParents(run) {
71
- const parents = [];
72
- let currentRun = run;
73
- while (currentRun.parent_run_id) {
74
- const parent = this.runMap.get(currentRun.parent_run_id);
75
- if (parent) {
76
- parents.push(parent);
77
- currentRun = parent;
78
- }
79
- else {
80
- break;
81
- }
82
- }
83
- return parents;
84
- }
85
- /**
86
- * Method used to get a string representation of the run's lineage, which
87
- * is used in logging.
88
- * @param run The run whose lineage is to be retrieved.
89
- * @returns A string representation of the run's lineage.
90
- */
91
- getBreadcrumbs(run) {
92
- const parents = this.getParents(run).reverse();
93
- const string = [...parents, run]
94
- .map((parent, i, arr) => {
95
- const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;
96
- return i === arr.length - 1 ? wrap(ansi_styles_1.default.bold, name) : name;
97
- })
98
- .join(" > ");
99
- return wrap(color.grey, string);
100
- }
101
- // logging methods
102
- /**
103
- * Method used to log the start of a chain run.
104
- * @param run The chain run that has started.
105
- * @returns void
106
- */
107
- onChainStart(run) {
108
- const crumbs = this.getBreadcrumbs(run);
109
- console.log(`${wrap(color.green, "[chain/start]")} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(run.inputs, "[inputs]")}`);
110
- }
111
- /**
112
- * Method used to log the end of a chain run.
113
- * @param run The chain run that has ended.
114
- * @returns void
115
- */
116
- onChainEnd(run) {
117
- const crumbs = this.getBreadcrumbs(run);
118
- console.log(`${wrap(color.cyan, "[chain/end]")} [${crumbs}] [${elapsed(run)}] Exiting Chain run with output: ${tryJsonStringify(run.outputs, "[outputs]")}`);
119
- }
120
- /**
121
- * Method used to log any errors of a chain run.
122
- * @param run The chain run that has errored.
123
- * @returns void
124
- */
125
- onChainError(run) {
126
- const crumbs = this.getBreadcrumbs(run);
127
- console.log(`${wrap(color.red, "[chain/error]")} [${crumbs}] [${elapsed(run)}] Chain run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
128
- }
129
- /**
130
- * Method used to log the start of an LLM run.
131
- * @param run The LLM run that has started.
132
- * @returns void
133
- */
134
- onLLMStart(run) {
135
- const crumbs = this.getBreadcrumbs(run);
136
- const inputs = "prompts" in run.inputs
137
- ? { prompts: run.inputs.prompts.map((p) => p.trim()) }
138
- : run.inputs;
139
- console.log(`${wrap(color.green, "[llm/start]")} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(inputs, "[inputs]")}`);
140
- }
141
- /**
142
- * Method used to log the end of an LLM run.
143
- * @param run The LLM run that has ended.
144
- * @returns void
145
- */
146
- onLLMEnd(run) {
147
- const crumbs = this.getBreadcrumbs(run);
148
- console.log(`${wrap(color.cyan, "[llm/end]")} [${crumbs}] [${elapsed(run)}] Exiting LLM run with output: ${tryJsonStringify(run.outputs, "[response]")}`);
149
- }
150
- /**
151
- * Method used to log any errors of an LLM run.
152
- * @param run The LLM run that has errored.
153
- * @returns void
154
- */
155
- onLLMError(run) {
156
- const crumbs = this.getBreadcrumbs(run);
157
- console.log(`${wrap(color.red, "[llm/error]")} [${crumbs}] [${elapsed(run)}] LLM run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
158
- }
159
- /**
160
- * Method used to log the start of a tool run.
161
- * @param run The tool run that has started.
162
- * @returns void
163
- */
164
- onToolStart(run) {
165
- const crumbs = this.getBreadcrumbs(run);
166
- console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${run.inputs.input?.trim()}"`);
167
- }
168
- /**
169
- * Method used to log the end of a tool run.
170
- * @param run The tool run that has ended.
171
- * @returns void
172
- */
173
- onToolEnd(run) {
174
- const crumbs = this.getBreadcrumbs(run);
175
- console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${run.outputs?.output?.trim()}"`);
176
- }
177
- /**
178
- * Method used to log any errors of a tool run.
179
- * @param run The tool run that has errored.
180
- * @returns void
181
- */
182
- onToolError(run) {
183
- const crumbs = this.getBreadcrumbs(run);
184
- console.log(`${wrap(color.red, "[tool/error]")} [${crumbs}] [${elapsed(run)}] Tool run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
185
- }
186
- /**
187
- * Method used to log the start of a retriever run.
188
- * @param run The retriever run that has started.
189
- * @returns void
190
- */
191
- onRetrieverStart(run) {
192
- const crumbs = this.getBreadcrumbs(run);
193
- console.log(`${wrap(color.green, "[retriever/start]")} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(run.inputs, "[inputs]")}`);
194
- }
195
- /**
196
- * Method used to log the end of a retriever run.
197
- * @param run The retriever run that has ended.
198
- * @returns void
199
- */
200
- onRetrieverEnd(run) {
201
- const crumbs = this.getBreadcrumbs(run);
202
- console.log(`${wrap(color.cyan, "[retriever/end]")} [${crumbs}] [${elapsed(run)}] Exiting Retriever run with output: ${tryJsonStringify(run.outputs, "[outputs]")}`);
203
- }
204
- /**
205
- * Method used to log any errors of a retriever run.
206
- * @param run The retriever run that has errored.
207
- * @returns void
208
- */
209
- onRetrieverError(run) {
210
- const crumbs = this.getBreadcrumbs(run);
211
- console.log(`${wrap(color.red, "[retriever/error]")} [${crumbs}] [${elapsed(run)}] Retriever run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
212
- }
213
- /**
214
- * Method used to log the action selected by the agent.
215
- * @param run The run in which the agent action occurred.
216
- * @returns void
217
- */
218
- onAgentAction(run) {
219
- const agentRun = run;
220
- const crumbs = this.getBreadcrumbs(run);
221
- console.log(`${wrap(color.blue, "[agent/action]")} [${crumbs}] Agent selected action: ${tryJsonStringify(agentRun.actions[agentRun.actions.length - 1], "[action]")}`);
222
- }
223
- }
224
- exports.ConsoleCallbackHandler = ConsoleCallbackHandler;
17
+ __exportStar(require("langchain-core/callbacks/tracers/console"), exports);
@@ -1,117 +1 @@
1
- import { BaseTracer, Run } from "./tracer.js";
2
- /**
3
- * A tracer that logs all events to the console. It extends from the
4
- * `BaseTracer` class and overrides its methods to provide custom logging
5
- * functionality.
6
- * @example
7
- * ```typescript
8
- *
9
- * const llm = new ChatAnthropic({
10
- * temperature: 0,
11
- * tags: ["example", "callbacks", "constructor"],
12
- * callbacks: [new ConsoleCallbackHandler()],
13
- * });
14
- *
15
- * ```
16
- */
17
- export declare class ConsoleCallbackHandler extends BaseTracer {
18
- name: "console_callback_handler";
19
- /**
20
- * Method used to persist the run. In this case, it simply returns a
21
- * resolved promise as there's no persistence logic.
22
- * @param _run The run to persist.
23
- * @returns A resolved promise.
24
- */
25
- protected persistRun(_run: Run): Promise<void>;
26
- /**
27
- * Method used to get all the parent runs of a given run.
28
- * @param run The run whose parents are to be retrieved.
29
- * @returns An array of parent runs.
30
- */
31
- getParents(run: Run): Run[];
32
- /**
33
- * Method used to get a string representation of the run's lineage, which
34
- * is used in logging.
35
- * @param run The run whose lineage is to be retrieved.
36
- * @returns A string representation of the run's lineage.
37
- */
38
- getBreadcrumbs(run: Run): string;
39
- /**
40
- * Method used to log the start of a chain run.
41
- * @param run The chain run that has started.
42
- * @returns void
43
- */
44
- onChainStart(run: Run): void;
45
- /**
46
- * Method used to log the end of a chain run.
47
- * @param run The chain run that has ended.
48
- * @returns void
49
- */
50
- onChainEnd(run: Run): void;
51
- /**
52
- * Method used to log any errors of a chain run.
53
- * @param run The chain run that has errored.
54
- * @returns void
55
- */
56
- onChainError(run: Run): void;
57
- /**
58
- * Method used to log the start of an LLM run.
59
- * @param run The LLM run that has started.
60
- * @returns void
61
- */
62
- onLLMStart(run: Run): void;
63
- /**
64
- * Method used to log the end of an LLM run.
65
- * @param run The LLM run that has ended.
66
- * @returns void
67
- */
68
- onLLMEnd(run: Run): void;
69
- /**
70
- * Method used to log any errors of an LLM run.
71
- * @param run The LLM run that has errored.
72
- * @returns void
73
- */
74
- onLLMError(run: Run): void;
75
- /**
76
- * Method used to log the start of a tool run.
77
- * @param run The tool run that has started.
78
- * @returns void
79
- */
80
- onToolStart(run: Run): void;
81
- /**
82
- * Method used to log the end of a tool run.
83
- * @param run The tool run that has ended.
84
- * @returns void
85
- */
86
- onToolEnd(run: Run): void;
87
- /**
88
- * Method used to log any errors of a tool run.
89
- * @param run The tool run that has errored.
90
- * @returns void
91
- */
92
- onToolError(run: Run): void;
93
- /**
94
- * Method used to log the start of a retriever run.
95
- * @param run The retriever run that has started.
96
- * @returns void
97
- */
98
- onRetrieverStart(run: Run): void;
99
- /**
100
- * Method used to log the end of a retriever run.
101
- * @param run The retriever run that has ended.
102
- * @returns void
103
- */
104
- onRetrieverEnd(run: Run): void;
105
- /**
106
- * Method used to log any errors of a retriever run.
107
- * @param run The retriever run that has errored.
108
- * @returns void
109
- */
110
- onRetrieverError(run: Run): void;
111
- /**
112
- * Method used to log the action selected by the agent.
113
- * @param run The run in which the agent action occurred.
114
- * @returns void
115
- */
116
- onAgentAction(run: Run): void;
117
- }
1
+ export * from "langchain-core/callbacks/tracers/console";
@@ -1,217 +1 @@
1
- import styles from "ansi-styles";
2
- import { BaseTracer } from "./tracer.js";
3
- function wrap(style, text) {
4
- return `${style.open}${text}${style.close}`;
5
- }
6
- function tryJsonStringify(obj, fallback) {
7
- try {
8
- return JSON.stringify(obj, null, 2);
9
- }
10
- catch (err) {
11
- return fallback;
12
- }
13
- }
14
- function elapsed(run) {
15
- if (!run.end_time)
16
- return "";
17
- const elapsed = run.end_time - run.start_time;
18
- if (elapsed < 1000) {
19
- return `${elapsed}ms`;
20
- }
21
- return `${(elapsed / 1000).toFixed(2)}s`;
22
- }
23
- const { color } = styles;
24
- /**
25
- * A tracer that logs all events to the console. It extends from the
26
- * `BaseTracer` class and overrides its methods to provide custom logging
27
- * functionality.
28
- * @example
29
- * ```typescript
30
- *
31
- * const llm = new ChatAnthropic({
32
- * temperature: 0,
33
- * tags: ["example", "callbacks", "constructor"],
34
- * callbacks: [new ConsoleCallbackHandler()],
35
- * });
36
- *
37
- * ```
38
- */
39
- export class ConsoleCallbackHandler extends BaseTracer {
40
- constructor() {
41
- super(...arguments);
42
- Object.defineProperty(this, "name", {
43
- enumerable: true,
44
- configurable: true,
45
- writable: true,
46
- value: "console_callback_handler"
47
- });
48
- }
49
- /**
50
- * Method used to persist the run. In this case, it simply returns a
51
- * resolved promise as there's no persistence logic.
52
- * @param _run The run to persist.
53
- * @returns A resolved promise.
54
- */
55
- persistRun(_run) {
56
- return Promise.resolve();
57
- }
58
- // utility methods
59
- /**
60
- * Method used to get all the parent runs of a given run.
61
- * @param run The run whose parents are to be retrieved.
62
- * @returns An array of parent runs.
63
- */
64
- getParents(run) {
65
- const parents = [];
66
- let currentRun = run;
67
- while (currentRun.parent_run_id) {
68
- const parent = this.runMap.get(currentRun.parent_run_id);
69
- if (parent) {
70
- parents.push(parent);
71
- currentRun = parent;
72
- }
73
- else {
74
- break;
75
- }
76
- }
77
- return parents;
78
- }
79
- /**
80
- * Method used to get a string representation of the run's lineage, which
81
- * is used in logging.
82
- * @param run The run whose lineage is to be retrieved.
83
- * @returns A string representation of the run's lineage.
84
- */
85
- getBreadcrumbs(run) {
86
- const parents = this.getParents(run).reverse();
87
- const string = [...parents, run]
88
- .map((parent, i, arr) => {
89
- const name = `${parent.execution_order}:${parent.run_type}:${parent.name}`;
90
- return i === arr.length - 1 ? wrap(styles.bold, name) : name;
91
- })
92
- .join(" > ");
93
- return wrap(color.grey, string);
94
- }
95
- // logging methods
96
- /**
97
- * Method used to log the start of a chain run.
98
- * @param run The chain run that has started.
99
- * @returns void
100
- */
101
- onChainStart(run) {
102
- const crumbs = this.getBreadcrumbs(run);
103
- console.log(`${wrap(color.green, "[chain/start]")} [${crumbs}] Entering Chain run with input: ${tryJsonStringify(run.inputs, "[inputs]")}`);
104
- }
105
- /**
106
- * Method used to log the end of a chain run.
107
- * @param run The chain run that has ended.
108
- * @returns void
109
- */
110
- onChainEnd(run) {
111
- const crumbs = this.getBreadcrumbs(run);
112
- console.log(`${wrap(color.cyan, "[chain/end]")} [${crumbs}] [${elapsed(run)}] Exiting Chain run with output: ${tryJsonStringify(run.outputs, "[outputs]")}`);
113
- }
114
- /**
115
- * Method used to log any errors of a chain run.
116
- * @param run The chain run that has errored.
117
- * @returns void
118
- */
119
- onChainError(run) {
120
- const crumbs = this.getBreadcrumbs(run);
121
- console.log(`${wrap(color.red, "[chain/error]")} [${crumbs}] [${elapsed(run)}] Chain run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
122
- }
123
- /**
124
- * Method used to log the start of an LLM run.
125
- * @param run The LLM run that has started.
126
- * @returns void
127
- */
128
- onLLMStart(run) {
129
- const crumbs = this.getBreadcrumbs(run);
130
- const inputs = "prompts" in run.inputs
131
- ? { prompts: run.inputs.prompts.map((p) => p.trim()) }
132
- : run.inputs;
133
- console.log(`${wrap(color.green, "[llm/start]")} [${crumbs}] Entering LLM run with input: ${tryJsonStringify(inputs, "[inputs]")}`);
134
- }
135
- /**
136
- * Method used to log the end of an LLM run.
137
- * @param run The LLM run that has ended.
138
- * @returns void
139
- */
140
- onLLMEnd(run) {
141
- const crumbs = this.getBreadcrumbs(run);
142
- console.log(`${wrap(color.cyan, "[llm/end]")} [${crumbs}] [${elapsed(run)}] Exiting LLM run with output: ${tryJsonStringify(run.outputs, "[response]")}`);
143
- }
144
- /**
145
- * Method used to log any errors of an LLM run.
146
- * @param run The LLM run that has errored.
147
- * @returns void
148
- */
149
- onLLMError(run) {
150
- const crumbs = this.getBreadcrumbs(run);
151
- console.log(`${wrap(color.red, "[llm/error]")} [${crumbs}] [${elapsed(run)}] LLM run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
152
- }
153
- /**
154
- * Method used to log the start of a tool run.
155
- * @param run The tool run that has started.
156
- * @returns void
157
- */
158
- onToolStart(run) {
159
- const crumbs = this.getBreadcrumbs(run);
160
- console.log(`${wrap(color.green, "[tool/start]")} [${crumbs}] Entering Tool run with input: "${run.inputs.input?.trim()}"`);
161
- }
162
- /**
163
- * Method used to log the end of a tool run.
164
- * @param run The tool run that has ended.
165
- * @returns void
166
- */
167
- onToolEnd(run) {
168
- const crumbs = this.getBreadcrumbs(run);
169
- console.log(`${wrap(color.cyan, "[tool/end]")} [${crumbs}] [${elapsed(run)}] Exiting Tool run with output: "${run.outputs?.output?.trim()}"`);
170
- }
171
- /**
172
- * Method used to log any errors of a tool run.
173
- * @param run The tool run that has errored.
174
- * @returns void
175
- */
176
- onToolError(run) {
177
- const crumbs = this.getBreadcrumbs(run);
178
- console.log(`${wrap(color.red, "[tool/error]")} [${crumbs}] [${elapsed(run)}] Tool run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
179
- }
180
- /**
181
- * Method used to log the start of a retriever run.
182
- * @param run The retriever run that has started.
183
- * @returns void
184
- */
185
- onRetrieverStart(run) {
186
- const crumbs = this.getBreadcrumbs(run);
187
- console.log(`${wrap(color.green, "[retriever/start]")} [${crumbs}] Entering Retriever run with input: ${tryJsonStringify(run.inputs, "[inputs]")}`);
188
- }
189
- /**
190
- * Method used to log the end of a retriever run.
191
- * @param run The retriever run that has ended.
192
- * @returns void
193
- */
194
- onRetrieverEnd(run) {
195
- const crumbs = this.getBreadcrumbs(run);
196
- console.log(`${wrap(color.cyan, "[retriever/end]")} [${crumbs}] [${elapsed(run)}] Exiting Retriever run with output: ${tryJsonStringify(run.outputs, "[outputs]")}`);
197
- }
198
- /**
199
- * Method used to log any errors of a retriever run.
200
- * @param run The retriever run that has errored.
201
- * @returns void
202
- */
203
- onRetrieverError(run) {
204
- const crumbs = this.getBreadcrumbs(run);
205
- console.log(`${wrap(color.red, "[retriever/error]")} [${crumbs}] [${elapsed(run)}] Retriever run errored with error: ${tryJsonStringify(run.error, "[error]")}`);
206
- }
207
- /**
208
- * Method used to log the action selected by the agent.
209
- * @param run The run in which the agent action occurred.
210
- * @returns void
211
- */
212
- onAgentAction(run) {
213
- const agentRun = run;
214
- const crumbs = this.getBreadcrumbs(run);
215
- console.log(`${wrap(color.blue, "[agent/action]")} [${crumbs}] Agent selected action: ${tryJsonStringify(agentRun.actions[agentRun.actions.length - 1], "[action]")}`);
216
- }
217
- }
1
+ export * from "langchain-core/callbacks/tracers/console";