langchain 0.0.195 → 0.0.197-rc.0

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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/openai/index.cjs +6 -2
  3. package/dist/agents/openai/index.js +6 -2
  4. package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
  5. package/dist/base_language/count_tokens.cjs +5 -70
  6. package/dist/base_language/count_tokens.d.ts +1 -10
  7. package/dist/base_language/count_tokens.js +1 -65
  8. package/dist/base_language/index.cjs +6 -196
  9. package/dist/base_language/index.d.ts +1 -111
  10. package/dist/base_language/index.js +1 -191
  11. package/dist/cache/base.cjs +15 -37
  12. package/dist/cache/base.d.ts +1 -20
  13. package/dist/cache/base.js +1 -33
  14. package/dist/cache/index.cjs +2 -46
  15. package/dist/cache/index.d.ts +1 -29
  16. package/dist/cache/index.js +1 -45
  17. package/dist/callbacks/base.cjs +3 -139
  18. package/dist/callbacks/base.d.ts +1 -266
  19. package/dist/callbacks/base.js +1 -126
  20. package/dist/callbacks/handlers/console.cjs +14 -221
  21. package/dist/callbacks/handlers/console.d.ts +1 -117
  22. package/dist/callbacks/handlers/console.js +1 -217
  23. package/dist/callbacks/handlers/initialize.cjs +15 -30
  24. package/dist/callbacks/handlers/initialize.d.ts +1 -16
  25. package/dist/callbacks/handlers/initialize.js +1 -27
  26. package/dist/callbacks/handlers/log_stream.cjs +15 -293
  27. package/dist/callbacks/handlers/log_stream.d.ts +1 -100
  28. package/dist/callbacks/handlers/log_stream.js +1 -289
  29. package/dist/callbacks/handlers/run_collector.cjs +15 -48
  30. package/dist/callbacks/handlers/run_collector.d.ts +1 -26
  31. package/dist/callbacks/handlers/run_collector.js +1 -46
  32. package/dist/callbacks/handlers/tracer.cjs +15 -375
  33. package/dist/callbacks/handlers/tracer.d.ts +1 -70
  34. package/dist/callbacks/handlers/tracer.js +1 -373
  35. package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
  36. package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
  37. package/dist/callbacks/handlers/tracer_langchain.js +1 -102
  38. package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
  39. package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
  40. package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
  41. package/dist/callbacks/manager.cjs +15 -676
  42. package/dist/callbacks/manager.d.ts +1 -180
  43. package/dist/callbacks/manager.js +1 -666
  44. package/dist/callbacks/promises.cjs +14 -42
  45. package/dist/callbacks/promises.d.ts +1 -11
  46. package/dist/callbacks/promises.js +1 -37
  47. package/dist/chains/graph_qa/prompts.d.ts +1 -1
  48. package/dist/chains/openai_functions/structured_output.cjs +2 -2
  49. package/dist/chains/openai_functions/structured_output.d.ts +1 -1
  50. package/dist/chains/openai_functions/structured_output.js +1 -1
  51. package/dist/chat_models/anthropic.cjs +15 -348
  52. package/dist/chat_models/anthropic.d.ts +1 -156
  53. package/dist/chat_models/anthropic.js +1 -346
  54. package/dist/chat_models/baiduwenxin.d.ts +1 -1
  55. package/dist/chat_models/base.cjs +15 -296
  56. package/dist/chat_models/base.d.ts +1 -122
  57. package/dist/chat_models/base.js +1 -292
  58. package/dist/chat_models/bedrock/web.cjs +21 -1
  59. package/dist/chat_models/bedrock/web.d.ts +2 -2
  60. package/dist/chat_models/bedrock/web.js +21 -1
  61. package/dist/chat_models/fireworks.d.ts +1 -1
  62. package/dist/document.cjs +2 -24
  63. package/dist/document.d.ts +1 -12
  64. package/dist/document.js +1 -23
  65. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
  66. package/dist/document_loaders/web/github.cjs +105 -0
  67. package/dist/document_loaders/web/github.d.ts +26 -0
  68. package/dist/document_loaders/web/github.js +105 -0
  69. package/dist/document_loaders/web/s3.d.ts +1 -1
  70. package/dist/embeddings/base.cjs +15 -22
  71. package/dist/embeddings/base.d.ts +1 -33
  72. package/dist/embeddings/base.js +1 -20
  73. package/dist/embeddings/cache_backed.cjs +2 -2
  74. package/dist/embeddings/cache_backed.js +1 -1
  75. package/dist/evaluation/agents/trajectory.d.ts +1 -1
  76. package/dist/evaluation/criteria/prompt.d.ts +2 -2
  77. package/dist/evaluation/qa/prompt.d.ts +2 -2
  78. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
  79. package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
  80. package/dist/llms/base.cjs +15 -278
  81. package/dist/llms/base.d.ts +1 -115
  82. package/dist/llms/base.js +1 -275
  83. package/dist/llms/bedrock/web.cjs +21 -1
  84. package/dist/llms/bedrock/web.d.ts +2 -2
  85. package/dist/llms/bedrock/web.js +21 -1
  86. package/dist/llms/fireworks.d.ts +1 -1
  87. package/dist/load/import_map.cjs +2 -1
  88. package/dist/load/import_map.d.ts +1 -0
  89. package/dist/load/import_map.js +1 -0
  90. package/dist/load/index.cjs +7 -148
  91. package/dist/load/index.js +7 -148
  92. package/dist/load/map_keys.cjs +0 -24
  93. package/dist/load/map_keys.d.ts +0 -6
  94. package/dist/load/map_keys.js +1 -17
  95. package/dist/load/serializable.cjs +15 -178
  96. package/dist/load/serializable.d.ts +1 -66
  97. package/dist/load/serializable.js +1 -175
  98. package/dist/memory/base.cjs +17 -92
  99. package/dist/memory/base.d.ts +2 -68
  100. package/dist/memory/base.js +2 -87
  101. package/dist/output_parsers/list.cjs +4 -122
  102. package/dist/output_parsers/list.d.ts +1 -57
  103. package/dist/output_parsers/list.js +1 -119
  104. package/dist/output_parsers/openai_functions.cjs +2 -2
  105. package/dist/output_parsers/openai_functions.d.ts +1 -1
  106. package/dist/output_parsers/openai_functions.js +1 -1
  107. package/dist/output_parsers/regex.d.ts +1 -1
  108. package/dist/output_parsers/structured.d.ts +1 -1
  109. package/dist/prompts/base.cjs +8 -183
  110. package/dist/prompts/base.d.ts +3 -132
  111. package/dist/prompts/base.js +3 -178
  112. package/dist/prompts/chat.cjs +13 -477
  113. package/dist/prompts/chat.d.ts +2 -219
  114. package/dist/prompts/chat.js +2 -466
  115. package/dist/prompts/few_shot.cjs +3 -352
  116. package/dist/prompts/few_shot.d.ts +1 -192
  117. package/dist/prompts/few_shot.js +1 -350
  118. package/dist/prompts/index.cjs +3 -2
  119. package/dist/prompts/index.d.ts +2 -1
  120. package/dist/prompts/index.js +2 -1
  121. package/dist/prompts/pipeline.cjs +2 -141
  122. package/dist/prompts/pipeline.d.ts +1 -98
  123. package/dist/prompts/pipeline.js +1 -140
  124. package/dist/prompts/prompt.cjs +2 -145
  125. package/dist/prompts/prompt.d.ts +1 -92
  126. package/dist/prompts/prompt.js +1 -144
  127. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +2 -147
  128. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
  129. package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
  130. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
  131. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
  132. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
  133. package/dist/prompts/selectors/conditional.cjs +5 -73
  134. package/dist/prompts/selectors/conditional.d.ts +1 -63
  135. package/dist/prompts/selectors/conditional.js +1 -69
  136. package/dist/prompts/serde.d.ts +1 -43
  137. package/dist/prompts/template.cjs +8 -88
  138. package/dist/prompts/template.d.ts +1 -36
  139. package/dist/prompts/template.js +1 -83
  140. package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
  141. package/dist/runnables/index.d.ts +1 -0
  142. package/dist/runnables/index.js +1 -0
  143. package/dist/schema/document.cjs +3 -34
  144. package/dist/schema/document.d.ts +2 -29
  145. package/dist/schema/document.js +2 -32
  146. package/dist/schema/index.cjs +37 -612
  147. package/dist/schema/index.d.ts +11 -311
  148. package/dist/schema/index.js +8 -583
  149. package/dist/schema/output_parser.cjs +15 -309
  150. package/dist/schema/output_parser.d.ts +1 -173
  151. package/dist/schema/output_parser.js +1 -301
  152. package/dist/schema/retriever.cjs +15 -77
  153. package/dist/schema/retriever.d.ts +1 -43
  154. package/dist/schema/retriever.js +1 -75
  155. package/dist/schema/runnable/base.cjs +10 -1072
  156. package/dist/schema/runnable/base.d.ts +1 -356
  157. package/dist/schema/runnable/base.js +1 -1060
  158. package/dist/schema/runnable/branch.cjs +2 -131
  159. package/dist/schema/runnable/branch.d.ts +1 -94
  160. package/dist/schema/runnable/branch.js +1 -130
  161. package/dist/schema/runnable/config.cjs +0 -6
  162. package/dist/schema/runnable/config.d.ts +1 -3
  163. package/dist/schema/runnable/config.js +1 -4
  164. package/dist/schema/runnable/index.cjs +15 -16
  165. package/dist/schema/runnable/index.d.ts +1 -5
  166. package/dist/schema/runnable/index.js +1 -4
  167. package/dist/schema/runnable/passthrough.cjs +3 -113
  168. package/dist/schema/runnable/passthrough.d.ts +1 -72
  169. package/dist/schema/runnable/passthrough.js +1 -111
  170. package/dist/schema/runnable/router.cjs +2 -71
  171. package/dist/schema/runnable/router.d.ts +1 -29
  172. package/dist/schema/runnable/router.js +1 -70
  173. package/dist/schema/storage.cjs +15 -8
  174. package/dist/schema/storage.d.ts +1 -57
  175. package/dist/schema/storage.js +1 -6
  176. package/dist/tools/bingserpapi.d.ts +1 -1
  177. package/dist/tools/searchapi.d.ts +1 -1
  178. package/dist/tools/serpapi.d.ts +1 -1
  179. package/dist/tools/serper.d.ts +1 -1
  180. package/dist/util/async_caller.cjs +14 -128
  181. package/dist/util/async_caller.d.ts +1 -45
  182. package/dist/util/async_caller.js +1 -124
  183. package/dist/vectorstores/momento_vector_index.cjs +39 -0
  184. package/dist/vectorstores/momento_vector_index.d.ts +17 -1
  185. package/dist/vectorstores/momento_vector_index.js +40 -1
  186. package/dist/vectorstores/mongodb_atlas.cjs +22 -2
  187. package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
  188. package/dist/vectorstores/mongodb_atlas.js +22 -2
  189. package/package.json +18 -11
  190. package/runnables.cjs +1 -0
  191. package/runnables.d.ts +1 -0
  192. package/runnables.js +1 -0
  193. package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
  194. package/dist/util/@cfworker/json-schema/index.js +0 -1
  195. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
  196. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
  197. package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
  198. package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
  199. package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
  200. package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
  201. package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
  202. package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
  203. package/dist/util/@cfworker/json-schema/src/format.js +0 -136
  204. package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
  205. package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
  206. package/dist/util/@cfworker/json-schema/src/index.js +0 -8
  207. package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
  208. package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
  209. package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
  210. package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
  211. package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
  212. package/dist/util/@cfworker/json-schema/src/types.js +0 -1
  213. package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
  214. package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
  215. package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
  216. package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
  217. package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
  218. package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
  219. package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
  220. package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
  221. package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
  222. package/dist/util/fast-json-patch/index.cjs +0 -49
  223. package/dist/util/fast-json-patch/index.d.ts +0 -22
  224. package/dist/util/fast-json-patch/index.js +0 -16
  225. package/dist/util/fast-json-patch/src/core.cjs +0 -469
  226. package/dist/util/fast-json-patch/src/core.d.ts +0 -111
  227. package/dist/util/fast-json-patch/src/core.js +0 -459
  228. package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
  229. package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
  230. package/dist/util/fast-json-patch/src/duplex.js +0 -230
  231. package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
  232. package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
  233. package/dist/util/fast-json-patch/src/helpers.js +0 -181
  234. package/dist/util/js-sha1/hash.cjs +0 -358
  235. package/dist/util/js-sha1/hash.d.ts +0 -1
  236. package/dist/util/js-sha1/hash.js +0 -355
@@ -1,266 +1 @@
1
- import { AgentAction, AgentFinish, BaseMessage, ChainValues, ChatGenerationChunk, GenerationChunk, LLMResult } from "../schema/index.js";
2
- import { Serializable, Serialized, SerializedNotImplemented } from "../load/serializable.js";
3
- import { SerializedFields } from "../load/map_keys.js";
4
- import { Document } from "../document.js";
5
- type Error = any;
6
- /**
7
- * Interface for the input parameters of the BaseCallbackHandler class. It
8
- * allows to specify which types of events should be ignored by the
9
- * callback handler.
10
- */
11
- export interface BaseCallbackHandlerInput {
12
- ignoreLLM?: boolean;
13
- ignoreChain?: boolean;
14
- ignoreAgent?: boolean;
15
- ignoreRetriever?: boolean;
16
- }
17
- /**
18
- * Interface for the indices of a new token produced by an LLM or Chat
19
- * Model in streaming mode.
20
- */
21
- export interface NewTokenIndices {
22
- prompt: number;
23
- completion: number;
24
- }
25
- export type HandleLLMNewTokenCallbackFields = {
26
- chunk?: GenerationChunk | ChatGenerationChunk;
27
- };
28
- /**
29
- * Abstract class that provides a set of optional methods that can be
30
- * overridden in derived classes to handle various events during the
31
- * execution of a LangChain application.
32
- */
33
- declare abstract class BaseCallbackHandlerMethodsClass {
34
- /**
35
- * Called at the start of an LLM or Chat Model run, with the prompt(s)
36
- * and the run ID.
37
- */
38
- handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- Promise<any> | any;
40
- /**
41
- * Called when an LLM/ChatModel in `streaming` mode produces a new token
42
- */
43
- handleLLMNewToken?(token: string,
44
- /**
45
- * idx.prompt is the index of the prompt that produced the token
46
- * (if there are multiple prompts)
47
- * idx.completion is the index of the completion that produced the token
48
- * (if multiple completions per prompt are requested)
49
- */
50
- idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- Promise<any> | any;
52
- /**
53
- * Called if an LLM/ChatModel run encounters an error
54
- */
55
- handleLLMError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- Promise<any> | any;
57
- /**
58
- * Called at the end of an LLM/ChatModel run, with the output and the run ID.
59
- */
60
- handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- Promise<any> | any;
62
- /**
63
- * Called at the start of a Chat Model run, with the prompt(s)
64
- * and the run ID.
65
- */
66
- handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- Promise<any> | any;
68
- /**
69
- * Called at the start of a Chain run, with the chain name and inputs
70
- * and the run ID.
71
- */
72
- handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, runType?: string, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- Promise<any> | any;
74
- /**
75
- * Called if a Chain run encounters an error
76
- */
77
- handleChainError?(err: Error, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
78
- inputs?: Record<string, unknown>;
79
- }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
- Promise<any> | any;
81
- /**
82
- * Called at the end of a Chain run, with the outputs and the run ID.
83
- */
84
- handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], kwargs?: {
85
- inputs?: Record<string, unknown>;
86
- }): // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- Promise<any> | any;
88
- /**
89
- * Called at the start of a Tool run, with the tool name and input
90
- * and the run ID.
91
- */
92
- handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
93
- Promise<any> | any;
94
- /**
95
- * Called if a Tool run encounters an error
96
- */
97
- handleToolError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- Promise<any> | any;
99
- /**
100
- * Called at the end of a Tool run, with the tool output and the run ID.
101
- */
102
- handleToolEnd?(output: string, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- Promise<any> | any;
104
- handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
105
- /**
106
- * Called when an agent is about to execute an action,
107
- * with the action and the run ID.
108
- */
109
- handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
110
- /**
111
- * Called when an agent finishes execution, before it exits.
112
- * with the final output and the run ID.
113
- */
114
- handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
115
- handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>, name?: string): // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- Promise<any> | any;
117
- handleRetrieverEnd?(documents: Document[], runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- Promise<any> | any;
119
- handleRetrieverError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
- Promise<any> | any;
121
- }
122
- /**
123
- * Base interface for callbacks. All methods are optional. If a method is not
124
- * implemented, it will be ignored. If a method is implemented, it will be
125
- * called at the appropriate time. All methods are called with the run ID of
126
- * the LLM/ChatModel/Chain that is running, which is generated by the
127
- * CallbackManager.
128
- *
129
- * @interface
130
- */
131
- export type CallbackHandlerMethods = BaseCallbackHandlerMethodsClass;
132
- /**
133
- * Abstract base class for creating callback handlers in the LangChain
134
- * framework. It provides a set of optional methods that can be overridden
135
- * in derived classes to handle various events during the execution of a
136
- * LangChain application.
137
- */
138
- export declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass implements BaseCallbackHandlerInput, Serializable {
139
- lc_serializable: boolean;
140
- get lc_namespace(): ["langchain", "callbacks", string];
141
- get lc_secrets(): {
142
- [key: string]: string;
143
- } | undefined;
144
- get lc_attributes(): {
145
- [key: string]: string;
146
- } | undefined;
147
- get lc_aliases(): {
148
- [key: string]: string;
149
- } | undefined;
150
- /**
151
- * The name of the serializable. Override to provide an alias or
152
- * to preserve the serialized module name in minified environments.
153
- *
154
- * Implemented as a static method to support loading logic.
155
- */
156
- static lc_name(): string;
157
- /**
158
- * The final serialized identifier for the module.
159
- */
160
- get lc_id(): string[];
161
- lc_kwargs: SerializedFields;
162
- abstract name: string;
163
- ignoreLLM: boolean;
164
- ignoreChain: boolean;
165
- ignoreAgent: boolean;
166
- ignoreRetriever: boolean;
167
- awaitHandlers: boolean;
168
- constructor(input?: BaseCallbackHandlerInput);
169
- copy(): BaseCallbackHandler;
170
- toJSON(): Serialized;
171
- toJSONNotImplemented(): SerializedNotImplemented;
172
- static fromMethods(methods: CallbackHandlerMethods): {
173
- name: string;
174
- lc_serializable: boolean;
175
- readonly lc_namespace: ["langchain", "callbacks", string];
176
- readonly lc_secrets: {
177
- [key: string]: string;
178
- } | undefined;
179
- readonly lc_attributes: {
180
- [key: string]: string;
181
- } | undefined;
182
- readonly lc_aliases: {
183
- [key: string]: string;
184
- } | undefined;
185
- /**
186
- * The final serialized identifier for the module.
187
- */
188
- readonly lc_id: string[];
189
- lc_kwargs: SerializedFields;
190
- ignoreLLM: boolean;
191
- ignoreChain: boolean;
192
- ignoreAgent: boolean;
193
- ignoreRetriever: boolean;
194
- awaitHandlers: boolean;
195
- copy(): BaseCallbackHandler;
196
- toJSON(): Serialized;
197
- toJSONNotImplemented(): SerializedNotImplemented;
198
- /**
199
- * Called at the start of an LLM or Chat Model run, with the prompt(s)
200
- * and the run ID.
201
- */
202
- handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
203
- /**
204
- * Called when an LLM/ChatModel in `streaming` mode produces a new token
205
- */
206
- handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, fields?: HandleLLMNewTokenCallbackFields | undefined): any;
207
- /**
208
- * Called if an LLM/ChatModel run encounters an error
209
- */
210
- handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
211
- /**
212
- * Called at the end of an LLM/ChatModel run, with the output and the run ID.
213
- */
214
- handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
215
- /**
216
- * Called at the start of a Chat Model run, with the prompt(s)
217
- * and the run ID.
218
- */
219
- handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
220
- /**
221
- * Called at the start of a Chain run, with the chain name and inputs
222
- * and the run ID.
223
- */
224
- handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, runType?: string | undefined, name?: string | undefined): any;
225
- /**
226
- * Called if a Chain run encounters an error
227
- */
228
- handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
229
- inputs?: Record<string, unknown> | undefined;
230
- } | undefined): any;
231
- /**
232
- * Called at the end of a Chain run, with the outputs and the run ID.
233
- */
234
- handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, kwargs?: {
235
- inputs?: Record<string, unknown> | undefined;
236
- } | undefined): any;
237
- /**
238
- * Called at the start of a Tool run, with the tool name and input
239
- * and the run ID.
240
- */
241
- handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
242
- /**
243
- * Called if a Tool run encounters an error
244
- */
245
- handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
246
- /**
247
- * Called at the end of a Tool run, with the tool output and the run ID.
248
- */
249
- handleToolEnd?(output: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
250
- handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
251
- /**
252
- * Called when an agent is about to execute an action,
253
- * with the action and the run ID.
254
- */
255
- handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
256
- /**
257
- * Called when an agent finishes execution, before it exits.
258
- * with the final output and the run ID.
259
- */
260
- handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
261
- handleRetrieverStart?(retriever: Serialized, query: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined, name?: string | undefined): any;
262
- handleRetrieverEnd?(documents: Document<Record<string, any>>[], runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
263
- handleRetrieverError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): any;
264
- };
265
- }
266
- export {};
1
+ export * from "langchain-core/callbacks/base";
@@ -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/tracers/console"), exports);