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,301 +1,8 @@
1
+ import { BaseMessage, HumanMessage, AIMessage, SystemMessage, } from "langchain-core/schema/messages";
1
2
  import { Serializable } from "../load/serializable.js";
2
- export const RUN_KEY = "__run";
3
- /**
4
- * Chunk of a single generation. Used for streaming.
5
- */
6
- export class GenerationChunk {
7
- constructor(fields) {
8
- Object.defineProperty(this, "text", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: void 0
13
- });
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- Object.defineProperty(this, "generationInfo", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: void 0
20
- });
21
- this.text = fields.text;
22
- this.generationInfo = fields.generationInfo;
23
- }
24
- concat(chunk) {
25
- return new GenerationChunk({
26
- text: this.text + chunk.text,
27
- generationInfo: {
28
- ...this.generationInfo,
29
- ...chunk.generationInfo,
30
- },
31
- });
32
- }
33
- }
34
- function mergeContent(firstContent, secondContent) {
35
- // If first content is a string
36
- if (typeof firstContent === "string") {
37
- if (typeof secondContent === "string") {
38
- return firstContent + secondContent;
39
- }
40
- else {
41
- return [{ type: "text", text: firstContent }, ...secondContent];
42
- }
43
- // If both are arrays
44
- }
45
- else if (Array.isArray(secondContent)) {
46
- return [...firstContent, ...secondContent];
47
- // If the first content is a list and second is a string
48
- }
49
- else {
50
- // Otherwise, add the second content as a new element of the list
51
- return [...firstContent, { type: "text", text: secondContent }];
52
- }
53
- }
54
- /**
55
- * Base class for all types of messages in a conversation. It includes
56
- * properties like `content`, `name`, and `additional_kwargs`. It also
57
- * includes methods like `toDict()` and `_getType()`.
58
- */
59
- export class BaseMessage extends Serializable {
60
- /**
61
- * @deprecated
62
- * Use {@link BaseMessage.content} instead.
63
- */
64
- get text() {
65
- return typeof this.content === "string" ? this.content : "";
66
- }
67
- constructor(fields,
68
- /** @deprecated */
69
- kwargs) {
70
- if (typeof fields === "string") {
71
- // eslint-disable-next-line no-param-reassign
72
- fields = { content: fields, additional_kwargs: kwargs };
73
- }
74
- // Make sure the default value for additional_kwargs is passed into super() for serialization
75
- if (!fields.additional_kwargs) {
76
- // eslint-disable-next-line no-param-reassign
77
- fields.additional_kwargs = {};
78
- }
79
- super(fields);
80
- Object.defineProperty(this, "lc_namespace", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: ["langchain", "schema"]
85
- });
86
- Object.defineProperty(this, "lc_serializable", {
87
- enumerable: true,
88
- configurable: true,
89
- writable: true,
90
- value: true
91
- });
92
- /** The content of the message. */
93
- Object.defineProperty(this, "content", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: void 0
98
- });
99
- /** The name of the message sender in a multi-user chat. */
100
- Object.defineProperty(this, "name", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- /** Additional keyword arguments */
107
- Object.defineProperty(this, "additional_kwargs", {
108
- enumerable: true,
109
- configurable: true,
110
- writable: true,
111
- value: void 0
112
- });
113
- this.name = fields.name;
114
- this.content = fields.content;
115
- this.additional_kwargs = fields.additional_kwargs;
116
- }
117
- toDict() {
118
- return {
119
- type: this._getType(),
120
- data: this.toJSON()
121
- .kwargs,
122
- };
123
- }
124
- toChunk() {
125
- const type = this._getType();
126
- if (type === "human") {
127
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
128
- return new HumanMessageChunk({ ...this });
129
- }
130
- else if (type === "ai") {
131
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
132
- return new AIMessageChunk({ ...this });
133
- }
134
- else if (type === "system") {
135
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
136
- return new SystemMessageChunk({ ...this });
137
- }
138
- else if (type === "function") {
139
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
140
- return new FunctionMessageChunk({ ...this });
141
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
142
- }
143
- else if (ChatMessage.isInstance(this)) {
144
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
145
- return new ChatMessageChunk({ ...this });
146
- }
147
- else {
148
- throw new Error("Unknown message type.");
149
- }
150
- }
151
- }
152
- function isOpenAIToolCallArray(value) {
153
- return (Array.isArray(value) &&
154
- value.every((v) => typeof v.index === "number"));
155
- }
156
- /**
157
- * Represents a chunk of a message, which can be concatenated with other
158
- * message chunks. It includes a method `_merge_kwargs_dict()` for merging
159
- * additional keyword arguments from another `BaseMessageChunk` into this
160
- * one. It also overrides the `__add__()` method to support concatenation
161
- * of `BaseMessageChunk` instances.
162
- */
163
- export class BaseMessageChunk extends BaseMessage {
164
- static _mergeAdditionalKwargs(left, right) {
165
- const merged = { ...left };
166
- for (const [key, value] of Object.entries(right)) {
167
- if (merged[key] === undefined) {
168
- merged[key] = value;
169
- }
170
- else if (typeof merged[key] !== typeof value) {
171
- throw new Error(`additional_kwargs[${key}] already exists in the message chunk, but with a different type.`);
172
- }
173
- else if (typeof merged[key] === "string") {
174
- merged[key] = merged[key] + value;
175
- }
176
- else if (!Array.isArray(merged[key]) &&
177
- typeof merged[key] === "object") {
178
- merged[key] = this._mergeAdditionalKwargs(merged[key], value);
179
- }
180
- else if (key === "tool_calls" &&
181
- isOpenAIToolCallArray(merged[key]) &&
182
- isOpenAIToolCallArray(value)) {
183
- for (const toolCall of value) {
184
- if (merged[key]?.[toolCall.index] !== undefined) {
185
- merged[key] = merged[key]?.map((value, i) => {
186
- if (i !== toolCall.index) {
187
- return value;
188
- }
189
- return {
190
- ...value,
191
- ...toolCall,
192
- function: {
193
- name: toolCall.function.name ?? value.function.name,
194
- arguments: (value.function.arguments ?? "") +
195
- (toolCall.function.arguments ?? ""),
196
- },
197
- };
198
- });
199
- }
200
- else {
201
- merged[key][toolCall.index] = toolCall;
202
- }
203
- }
204
- }
205
- else {
206
- throw new Error(`additional_kwargs[${key}] already exists in this message chunk.`);
207
- }
208
- }
209
- return merged;
210
- }
211
- }
212
- /**
213
- * Represents a human message in a conversation.
214
- */
215
- export class HumanMessage extends BaseMessage {
216
- static lc_name() {
217
- return "HumanMessage";
218
- }
219
- _getType() {
220
- return "human";
221
- }
222
- }
223
- /**
224
- * Represents a chunk of a human message, which can be concatenated with
225
- * other human message chunks.
226
- */
227
- export class HumanMessageChunk extends BaseMessageChunk {
228
- static lc_name() {
229
- return "HumanMessageChunk";
230
- }
231
- _getType() {
232
- return "human";
233
- }
234
- concat(chunk) {
235
- return new HumanMessageChunk({
236
- content: mergeContent(this.content, chunk.content),
237
- additional_kwargs: HumanMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
238
- });
239
- }
240
- }
241
- /**
242
- * Represents an AI message in a conversation.
243
- */
244
- export class AIMessage extends BaseMessage {
245
- static lc_name() {
246
- return "AIMessage";
247
- }
248
- _getType() {
249
- return "ai";
250
- }
251
- }
252
- /**
253
- * Represents a chunk of an AI message, which can be concatenated with
254
- * other AI message chunks.
255
- */
256
- export class AIMessageChunk extends BaseMessageChunk {
257
- static lc_name() {
258
- return "AIMessageChunk";
259
- }
260
- _getType() {
261
- return "ai";
262
- }
263
- concat(chunk) {
264
- return new AIMessageChunk({
265
- content: mergeContent(this.content, chunk.content),
266
- additional_kwargs: AIMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
267
- });
268
- }
269
- }
270
- /**
271
- * Represents a system message in a conversation.
272
- */
273
- export class SystemMessage extends BaseMessage {
274
- static lc_name() {
275
- return "SystemMessage";
276
- }
277
- _getType() {
278
- return "system";
279
- }
280
- }
281
- /**
282
- * Represents a chunk of a system message, which can be concatenated with
283
- * other system message chunks.
284
- */
285
- export class SystemMessageChunk extends BaseMessageChunk {
286
- static lc_name() {
287
- return "SystemMessageChunk";
288
- }
289
- _getType() {
290
- return "system";
291
- }
292
- concat(chunk) {
293
- return new SystemMessageChunk({
294
- content: mergeContent(this.content, chunk.content),
295
- additional_kwargs: SystemMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
296
- });
297
- }
298
- }
3
+ export { RUN_KEY } from "langchain-core/schema/output";
4
+ export { BaseMessageChunk, HumanMessageChunk, AIMessageChunk, SystemMessageChunk, FunctionMessage, FunctionMessageChunk, ToolMessage, ToolMessageChunk, ChatMessage, mapStoredMessageToChatMessage, ChatMessageChunk, coerceMessageLikeToMessage, isBaseMessage, isBaseMessageChunk, } from "langchain-core/schema/messages";
5
+ export { BaseMessage, HumanMessage, AIMessage, SystemMessage };
299
6
  /**
300
7
  * @deprecated
301
8
  * Use {@link BaseMessage} instead.
@@ -316,292 +23,10 @@ export const AIChatMessage = AIMessage;
316
23
  * Use {@link SystemMessage} instead.
317
24
  */
318
25
  export const SystemChatMessage = SystemMessage;
319
- /**
320
- * Represents a function message in a conversation.
321
- */
322
- export class FunctionMessage extends BaseMessage {
323
- static lc_name() {
324
- return "FunctionMessage";
325
- }
326
- constructor(fields,
327
- /** @deprecated */
328
- name) {
329
- if (typeof fields === "string") {
330
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
331
- fields = { content: fields, name: name };
332
- }
333
- super(fields);
334
- }
335
- _getType() {
336
- return "function";
337
- }
338
- }
339
- /**
340
- * Represents a chunk of a function message, which can be concatenated
341
- * with other function message chunks.
342
- */
343
- export class FunctionMessageChunk extends BaseMessageChunk {
344
- static lc_name() {
345
- return "FunctionMessageChunk";
346
- }
347
- _getType() {
348
- return "function";
349
- }
350
- concat(chunk) {
351
- return new FunctionMessageChunk({
352
- content: mergeContent(this.content, chunk.content),
353
- additional_kwargs: FunctionMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
354
- name: this.name ?? "",
355
- });
356
- }
357
- }
358
- /**
359
- * Represents a tool message in a conversation.
360
- */
361
- export class ToolMessage extends BaseMessage {
362
- static lc_name() {
363
- return "ToolMessage";
364
- }
365
- constructor(fields, tool_call_id, name) {
366
- if (typeof fields === "string") {
367
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
368
- fields = { content: fields, name, tool_call_id: tool_call_id };
369
- }
370
- super(fields);
371
- Object.defineProperty(this, "tool_call_id", {
372
- enumerable: true,
373
- configurable: true,
374
- writable: true,
375
- value: void 0
376
- });
377
- this.tool_call_id = fields.tool_call_id;
378
- }
379
- _getType() {
380
- return "tool";
381
- }
382
- }
383
- /**
384
- * Represents a chunk of a tool message, which can be concatenated
385
- * with other tool message chunks.
386
- */
387
- export class ToolMessageChunk extends BaseMessageChunk {
388
- constructor(fields) {
389
- super(fields);
390
- Object.defineProperty(this, "tool_call_id", {
391
- enumerable: true,
392
- configurable: true,
393
- writable: true,
394
- value: void 0
395
- });
396
- this.tool_call_id = fields.tool_call_id;
397
- }
398
- static lc_name() {
399
- return "ToolMessageChunk";
400
- }
401
- _getType() {
402
- return "tool";
403
- }
404
- concat(chunk) {
405
- return new ToolMessageChunk({
406
- content: mergeContent(this.content, chunk.content),
407
- additional_kwargs: ToolMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
408
- tool_call_id: this.tool_call_id,
409
- });
410
- }
411
- }
412
- /**
413
- * Represents a chat message in a conversation.
414
- */
415
- export class ChatMessage extends BaseMessage {
416
- static lc_name() {
417
- return "ChatMessage";
418
- }
419
- constructor(fields, role) {
420
- if (typeof fields === "string") {
421
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
422
- fields = { content: fields, role: role };
423
- }
424
- super(fields);
425
- Object.defineProperty(this, "role", {
426
- enumerable: true,
427
- configurable: true,
428
- writable: true,
429
- value: void 0
430
- });
431
- this.role = fields.role;
432
- }
433
- _getType() {
434
- return "generic";
435
- }
436
- static isInstance(message) {
437
- return message._getType() === "generic";
438
- }
439
- }
440
- export function isBaseMessage(messageLike) {
441
- return typeof messageLike?._getType === "function";
442
- }
443
- export function isBaseMessageChunk(messageLike) {
444
- return (isBaseMessage(messageLike) &&
445
- typeof messageLike.concat === "function");
446
- }
447
- export function coerceMessageLikeToMessage(messageLike) {
448
- if (typeof messageLike === "string") {
449
- return new HumanMessage(messageLike);
450
- }
451
- else if (isBaseMessage(messageLike)) {
452
- return messageLike;
453
- }
454
- const [type, content] = messageLike;
455
- if (type === "human" || type === "user") {
456
- return new HumanMessage({ content });
457
- }
458
- else if (type === "ai" || type === "assistant") {
459
- return new AIMessage({ content });
460
- }
461
- else if (type === "system") {
462
- return new SystemMessage({ content });
463
- }
464
- else {
465
- throw new Error(`Unable to coerce message from array: only human, AI, or system message coercion is currently supported.`);
466
- }
467
- }
468
- /**
469
- * Represents a chunk of a chat message, which can be concatenated with
470
- * other chat message chunks.
471
- */
472
- export class ChatMessageChunk extends BaseMessageChunk {
473
- static lc_name() {
474
- return "ChatMessageChunk";
475
- }
476
- constructor(fields, role) {
477
- if (typeof fields === "string") {
478
- // eslint-disable-next-line no-param-reassign, @typescript-eslint/no-non-null-assertion
479
- fields = { content: fields, role: role };
480
- }
481
- super(fields);
482
- Object.defineProperty(this, "role", {
483
- enumerable: true,
484
- configurable: true,
485
- writable: true,
486
- value: void 0
487
- });
488
- this.role = fields.role;
489
- }
490
- _getType() {
491
- return "generic";
492
- }
493
- concat(chunk) {
494
- return new ChatMessageChunk({
495
- content: mergeContent(this.content, chunk.content),
496
- additional_kwargs: ChatMessageChunk._mergeAdditionalKwargs(this.additional_kwargs, chunk.additional_kwargs),
497
- role: this.role,
498
- });
499
- }
500
- }
501
- export class ChatGenerationChunk extends GenerationChunk {
502
- constructor(fields) {
503
- super(fields);
504
- Object.defineProperty(this, "message", {
505
- enumerable: true,
506
- configurable: true,
507
- writable: true,
508
- value: void 0
509
- });
510
- this.message = fields.message;
511
- }
512
- concat(chunk) {
513
- return new ChatGenerationChunk({
514
- text: this.text + chunk.text,
515
- generationInfo: {
516
- ...this.generationInfo,
517
- ...chunk.generationInfo,
518
- },
519
- message: this.message.concat(chunk.message),
520
- });
521
- }
522
- }
523
- /**
524
- * Maps messages from an older format (V1) to the current `StoredMessage`
525
- * format. If the message is already in the `StoredMessage` format, it is
526
- * returned as is. Otherwise, it transforms the V1 message into a
527
- * `StoredMessage`. This function is important for maintaining
528
- * compatibility with older message formats.
529
- */
530
- function mapV1MessageToStoredMessage(message) {
531
- // TODO: Remove this mapper when we deprecate the old message format.
532
- if (message.data !== undefined) {
533
- return message;
534
- }
535
- else {
536
- const v1Message = message;
537
- return {
538
- type: v1Message.type,
539
- data: {
540
- content: v1Message.text,
541
- role: v1Message.role,
542
- name: undefined,
543
- tool_call_id: undefined,
544
- },
545
- };
546
- }
547
- }
548
- export function mapStoredMessageToChatMessage(message) {
549
- const storedMessage = mapV1MessageToStoredMessage(message);
550
- switch (storedMessage.type) {
551
- case "human":
552
- return new HumanMessage(storedMessage.data);
553
- case "ai":
554
- return new AIMessage(storedMessage.data);
555
- case "system":
556
- return new SystemMessage(storedMessage.data);
557
- case "function":
558
- if (storedMessage.data.name === undefined) {
559
- throw new Error("Name must be defined for function messages");
560
- }
561
- return new FunctionMessage(storedMessage.data);
562
- case "tool":
563
- if (storedMessage.data.tool_call_id === undefined) {
564
- throw new Error("Tool call ID must be defined for tool messages");
565
- }
566
- return new ToolMessage(storedMessage.data);
567
- case "chat": {
568
- if (storedMessage.data.role === undefined) {
569
- throw new Error("Role must be defined for chat messages");
570
- }
571
- return new ChatMessage(storedMessage.data);
572
- }
573
- default:
574
- throw new Error(`Got unexpected type: ${storedMessage.type}`);
575
- }
576
- }
577
- /**
578
- * Base PromptValue class. All prompt values should extend this class.
579
- */
580
- export class BasePromptValue extends Serializable {
581
- }
582
- /**
583
- * Base class for all chat message histories. All chat message histories
584
- * should extend this class.
585
- */
586
- export class BaseChatMessageHistory extends Serializable {
587
- }
588
- /**
589
- * Base class for all list chat message histories. All list chat message
590
- * histories should extend this class.
591
- */
592
- export class BaseListChatMessageHistory extends Serializable {
593
- addUserMessage(message) {
594
- return this.addMessage(new HumanMessage(message));
595
- }
596
- addAIChatMessage(message) {
597
- return this.addMessage(new AIMessage(message));
598
- }
599
- }
600
- /**
601
- * Base class for all caches. All caches should extend this class.
602
- */
603
- export class BaseCache {
604
- }
26
+ export { GenerationChunk, ChatGenerationChunk, } from "langchain-core/schema/output";
27
+ export { BasePromptValue } from "langchain-core/schema/prompt";
28
+ export { BaseChatMessageHistory, BaseListChatMessageHistory, } from "langchain-core/schema/chat_history";
29
+ export { BaseCache } from "langchain-core/schema/cache";
605
30
  /**
606
31
  * Base class for all file stores. All file stores should extend this
607
32
  * class.