@digipair/skill-llm 0.7.3 → 0.8.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.
@@ -0,0 +1,1089 @@
1
+ import { f as BaseChain } from './index.esm2.js';
2
+
3
+ /**
4
+ * Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#implementing_basic_set_operations
5
+ */ /**
6
+ * returns intersection of two sets
7
+ */ function intersection(setA, setB) {
8
+ var _intersection = new Set();
9
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10
+ try {
11
+ for(var _iterator = setB[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12
+ var elem = _step.value;
13
+ if (setA.has(elem)) {
14
+ _intersection.add(elem);
15
+ }
16
+ }
17
+ } catch (err) {
18
+ _didIteratorError = true;
19
+ _iteratorError = err;
20
+ } finally{
21
+ try {
22
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
23
+ _iterator.return();
24
+ }
25
+ } finally{
26
+ if (_didIteratorError) {
27
+ throw _iteratorError;
28
+ }
29
+ }
30
+ }
31
+ return _intersection;
32
+ }
33
+ /**
34
+ * returns union of two sets
35
+ */ function union(setA, setB) {
36
+ var _union = new Set(setA);
37
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
38
+ try {
39
+ for(var _iterator = setB[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
40
+ var elem = _step.value;
41
+ _union.add(elem);
42
+ }
43
+ } catch (err) {
44
+ _didIteratorError = true;
45
+ _iteratorError = err;
46
+ } finally{
47
+ try {
48
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
49
+ _iterator.return();
50
+ }
51
+ } finally{
52
+ if (_didIteratorError) {
53
+ throw _iteratorError;
54
+ }
55
+ }
56
+ }
57
+ return _union;
58
+ }
59
+ /**
60
+ * returns difference of two sets
61
+ */ function difference(setA, setB) {
62
+ var _difference = new Set(setA);
63
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
64
+ try {
65
+ for(var _iterator = setB[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
66
+ var elem = _step.value;
67
+ _difference.delete(elem);
68
+ }
69
+ } catch (err) {
70
+ _didIteratorError = true;
71
+ _iteratorError = err;
72
+ } finally{
73
+ try {
74
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75
+ _iterator.return();
76
+ }
77
+ } finally{
78
+ if (_didIteratorError) {
79
+ throw _iteratorError;
80
+ }
81
+ }
82
+ }
83
+ return _difference;
84
+ }
85
+
86
+ function _assert_this_initialized(self) {
87
+ if (self === void 0) {
88
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
89
+ }
90
+ return self;
91
+ }
92
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
93
+ try {
94
+ var info = gen[key](arg);
95
+ var value = info.value;
96
+ } catch (error) {
97
+ reject(error);
98
+ return;
99
+ }
100
+ if (info.done) {
101
+ resolve(value);
102
+ } else {
103
+ Promise.resolve(value).then(_next, _throw);
104
+ }
105
+ }
106
+ function _async_to_generator(fn) {
107
+ return function() {
108
+ var self = this, args = arguments;
109
+ return new Promise(function(resolve, reject) {
110
+ var gen = fn.apply(self, args);
111
+ function _next(value) {
112
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
113
+ }
114
+ function _throw(err) {
115
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
116
+ }
117
+ _next(undefined);
118
+ });
119
+ };
120
+ }
121
+ function _class_call_check(instance, Constructor) {
122
+ if (!(instance instanceof Constructor)) {
123
+ throw new TypeError("Cannot call a class as a function");
124
+ }
125
+ }
126
+ function _defineProperties(target, props) {
127
+ for(var i = 0; i < props.length; i++){
128
+ var descriptor = props[i];
129
+ descriptor.enumerable = descriptor.enumerable || false;
130
+ descriptor.configurable = true;
131
+ if ("value" in descriptor) descriptor.writable = true;
132
+ Object.defineProperty(target, descriptor.key, descriptor);
133
+ }
134
+ }
135
+ function _create_class(Constructor, protoProps, staticProps) {
136
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
137
+ if (staticProps) _defineProperties(Constructor, staticProps);
138
+ return Constructor;
139
+ }
140
+ function _define_property(obj, key, value) {
141
+ if (key in obj) {
142
+ Object.defineProperty(obj, key, {
143
+ value: value,
144
+ enumerable: true,
145
+ configurable: true,
146
+ writable: true
147
+ });
148
+ } else {
149
+ obj[key] = value;
150
+ }
151
+ return obj;
152
+ }
153
+ function _get_prototype_of(o) {
154
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
155
+ return o.__proto__ || Object.getPrototypeOf(o);
156
+ };
157
+ return _get_prototype_of(o);
158
+ }
159
+ function _inherits(subClass, superClass) {
160
+ if (typeof superClass !== "function" && superClass !== null) {
161
+ throw new TypeError("Super expression must either be null or a function");
162
+ }
163
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
164
+ constructor: {
165
+ value: subClass,
166
+ writable: true,
167
+ configurable: true
168
+ }
169
+ });
170
+ if (superClass) _set_prototype_of(subClass, superClass);
171
+ }
172
+ function _possible_constructor_return(self, call) {
173
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
174
+ return call;
175
+ }
176
+ return _assert_this_initialized(self);
177
+ }
178
+ function _set_prototype_of(o, p) {
179
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
180
+ o.__proto__ = p;
181
+ return o;
182
+ };
183
+ return _set_prototype_of(o, p);
184
+ }
185
+ function _type_of(obj) {
186
+ "@swc/helpers - typeof";
187
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
188
+ }
189
+ function _is_native_reflect_construct() {
190
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
191
+ if (Reflect.construct.sham) return false;
192
+ if (typeof Proxy === "function") return true;
193
+ try {
194
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
195
+ return true;
196
+ } catch (e) {
197
+ return false;
198
+ }
199
+ }
200
+ function _create_super(Derived) {
201
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
202
+ return function _createSuperInternal() {
203
+ var Super = _get_prototype_of(Derived), result;
204
+ if (hasNativeReflectConstruct) {
205
+ var NewTarget = _get_prototype_of(this).constructor;
206
+ result = Reflect.construct(Super, arguments, NewTarget);
207
+ } else {
208
+ result = Super.apply(this, arguments);
209
+ }
210
+ return _possible_constructor_return(this, result);
211
+ };
212
+ }
213
+ function _ts_generator(thisArg, body) {
214
+ var f, y, t, g, _ = {
215
+ label: 0,
216
+ sent: function() {
217
+ if (t[0] & 1) throw t[1];
218
+ return t[1];
219
+ },
220
+ trys: [],
221
+ ops: []
222
+ };
223
+ return g = {
224
+ next: verb(0),
225
+ "throw": verb(1),
226
+ "return": verb(2)
227
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
228
+ return this;
229
+ }), g;
230
+ function verb(n) {
231
+ return function(v) {
232
+ return step([
233
+ n,
234
+ v
235
+ ]);
236
+ };
237
+ }
238
+ function step(op) {
239
+ if (f) throw new TypeError("Generator is already executing.");
240
+ while(_)try {
241
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
242
+ if (y = 0, t) op = [
243
+ op[0] & 2,
244
+ t.value
245
+ ];
246
+ switch(op[0]){
247
+ case 0:
248
+ case 1:
249
+ t = op;
250
+ break;
251
+ case 4:
252
+ _.label++;
253
+ return {
254
+ value: op[1],
255
+ done: false
256
+ };
257
+ case 5:
258
+ _.label++;
259
+ y = op[1];
260
+ op = [
261
+ 0
262
+ ];
263
+ continue;
264
+ case 7:
265
+ op = _.ops.pop();
266
+ _.trys.pop();
267
+ continue;
268
+ default:
269
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
270
+ _ = 0;
271
+ continue;
272
+ }
273
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
274
+ _.label = op[1];
275
+ break;
276
+ }
277
+ if (op[0] === 6 && _.label < t[1]) {
278
+ _.label = t[1];
279
+ t = op;
280
+ break;
281
+ }
282
+ if (t && _.label < t[2]) {
283
+ _.label = t[2];
284
+ _.ops.push(op);
285
+ break;
286
+ }
287
+ if (t[2]) _.ops.pop();
288
+ _.trys.pop();
289
+ continue;
290
+ }
291
+ op = body.call(thisArg, _);
292
+ } catch (e) {
293
+ op = [
294
+ 6,
295
+ e
296
+ ];
297
+ y = 0;
298
+ } finally{
299
+ f = t = 0;
300
+ }
301
+ if (op[0] & 5) throw op[1];
302
+ return {
303
+ value: op[0] ? op[1] : void 0,
304
+ done: true
305
+ };
306
+ }
307
+ }
308
+ function formatSet(input) {
309
+ return Array.from(input).map(function(i) {
310
+ return '"'.concat(i, '"');
311
+ }).join(", ");
312
+ }
313
+ /**
314
+ * Chain where the outputs of one chain feed directly into next.
315
+ * @example
316
+ * ```typescript
317
+ * const promptTemplate = new PromptTemplate({
318
+ * template: `You are a playwright. Given the title of play and the era it is set in, it is your job to write a synopsis for that title.
319
+ * Title: {title}
320
+ * Era: {era}
321
+ * Playwright: This is a synopsis for the above play:`,
322
+ * inputVariables: ["title", "era"],
323
+ * });
324
+
325
+ * const reviewPromptTemplate = new PromptTemplate({
326
+ * template: `You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
327
+ *
328
+ * Play Synopsis:
329
+ * {synopsis}
330
+ * Review from a New York Times play critic of the above play:`,
331
+ * inputVariables: ["synopsis"],
332
+ * });
333
+
334
+ * const overallChain = new SequentialChain({
335
+ * chains: [
336
+ * new LLMChain({
337
+ * llm: new ChatOpenAI({ temperature: 0 }),
338
+ * prompt: promptTemplate,
339
+ * outputKey: "synopsis",
340
+ * }),
341
+ * new LLMChain({
342
+ * llm: new OpenAI({ temperature: 0 }),
343
+ * prompt: reviewPromptTemplate,
344
+ * outputKey: "review",
345
+ * }),
346
+ * ],
347
+ * inputVariables: ["era", "title"],
348
+ * outputVariables: ["synopsis", "review"],
349
+ * verbose: true,
350
+ * });
351
+
352
+ * const chainExecutionResult = await overallChain.call({
353
+ * title: "Tragedy at sunset on the beach",
354
+ * era: "Victorian England",
355
+ * });
356
+ * console.log(chainExecutionResult);
357
+ * ```
358
+ *
359
+ * @deprecated
360
+ * Switch to {@link https://js.langchain.com/docs/expression_language/ | expression language}.
361
+ * Will be removed in 0.2.0
362
+ */ var SequentialChain = /*#__PURE__*/ function(BaseChain1) {
363
+ _inherits(SequentialChain, BaseChain1);
364
+ var _super = _create_super(SequentialChain);
365
+ function SequentialChain(fields) {
366
+ _class_call_check(this, SequentialChain);
367
+ var _this;
368
+ _this = _super.call(this, fields);
369
+ Object.defineProperty(_assert_this_initialized(_this), "chains", {
370
+ enumerable: true,
371
+ configurable: true,
372
+ writable: true,
373
+ value: void 0
374
+ });
375
+ Object.defineProperty(_assert_this_initialized(_this), "inputVariables", {
376
+ enumerable: true,
377
+ configurable: true,
378
+ writable: true,
379
+ value: void 0
380
+ });
381
+ Object.defineProperty(_assert_this_initialized(_this), "outputVariables", {
382
+ enumerable: true,
383
+ configurable: true,
384
+ writable: true,
385
+ value: void 0
386
+ });
387
+ Object.defineProperty(_assert_this_initialized(_this), "returnAll", {
388
+ enumerable: true,
389
+ configurable: true,
390
+ writable: true,
391
+ value: void 0
392
+ });
393
+ _this.chains = fields.chains;
394
+ _this.inputVariables = fields.inputVariables;
395
+ var _fields_outputVariables;
396
+ _this.outputVariables = (_fields_outputVariables = fields.outputVariables) !== null && _fields_outputVariables !== void 0 ? _fields_outputVariables : [];
397
+ if (_this.outputVariables.length > 0 && fields.returnAll) {
398
+ throw new Error("Either specify variables to return using `outputVariables` or use `returnAll` param. Cannot apply both conditions at the same time.");
399
+ }
400
+ var _fields_returnAll;
401
+ _this.returnAll = (_fields_returnAll = fields.returnAll) !== null && _fields_returnAll !== void 0 ? _fields_returnAll : false;
402
+ _this._validateChains();
403
+ return _this;
404
+ }
405
+ _create_class(SequentialChain, [
406
+ {
407
+ key: "inputKeys",
408
+ get: function get() {
409
+ return this.inputVariables;
410
+ }
411
+ },
412
+ {
413
+ key: "outputKeys",
414
+ get: function get() {
415
+ return this.outputVariables;
416
+ }
417
+ },
418
+ {
419
+ /** @ignore */ key: "_validateChains",
420
+ value: function _validateChains() {
421
+ var _this_memory;
422
+ if (this.chains.length === 0) {
423
+ throw new Error("Sequential chain must have at least one chain.");
424
+ }
425
+ var _this_memory_memoryKeys;
426
+ var memoryKeys = (_this_memory_memoryKeys = (_this_memory = this.memory) === null || _this_memory === void 0 ? void 0 : _this_memory.memoryKeys) !== null && _this_memory_memoryKeys !== void 0 ? _this_memory_memoryKeys : [];
427
+ var inputKeysSet = new Set(this.inputKeys);
428
+ var memoryKeysSet = new Set(memoryKeys);
429
+ var keysIntersection = intersection(inputKeysSet, memoryKeysSet);
430
+ if (keysIntersection.size > 0) {
431
+ throw new Error("The following keys: ".concat(formatSet(keysIntersection), " are overlapping between memory and input keys of the chain variables. This can lead to unexpected behaviour. Please use input and memory keys that don't overlap."));
432
+ }
433
+ var availableKeys = union(inputKeysSet, memoryKeysSet);
434
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
435
+ try {
436
+ for(var _iterator = this.chains[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
437
+ var chain = _step.value;
438
+ var missingKeys = difference(new Set(chain.inputKeys), availableKeys);
439
+ if (chain.memory) {
440
+ missingKeys = difference(missingKeys, new Set(chain.memory.memoryKeys));
441
+ }
442
+ if (missingKeys.size > 0) {
443
+ throw new Error('Missing variables for chain "'.concat(chain._chainType(), '": ').concat(formatSet(missingKeys), ". Only got the following variables: ").concat(formatSet(availableKeys), "."));
444
+ }
445
+ var outputKeysSet = new Set(chain.outputKeys);
446
+ var overlappingOutputKeys = intersection(availableKeys, outputKeysSet);
447
+ if (overlappingOutputKeys.size > 0) {
448
+ throw new Error('The following output variables for chain "'.concat(chain._chainType(), '" are overlapping: ').concat(formatSet(overlappingOutputKeys), ". This can lead to unexpected behaviour."));
449
+ }
450
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
451
+ try {
452
+ for(var _iterator1 = outputKeysSet[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
453
+ var outputKey = _step1.value;
454
+ availableKeys.add(outputKey);
455
+ }
456
+ } catch (err) {
457
+ _didIteratorError1 = true;
458
+ _iteratorError1 = err;
459
+ } finally{
460
+ try {
461
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
462
+ _iterator1.return();
463
+ }
464
+ } finally{
465
+ if (_didIteratorError1) {
466
+ throw _iteratorError1;
467
+ }
468
+ }
469
+ }
470
+ }
471
+ } catch (err) {
472
+ _didIteratorError = true;
473
+ _iteratorError = err;
474
+ } finally{
475
+ try {
476
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
477
+ _iterator.return();
478
+ }
479
+ } finally{
480
+ if (_didIteratorError) {
481
+ throw _iteratorError;
482
+ }
483
+ }
484
+ }
485
+ if (this.outputVariables.length === 0) {
486
+ if (this.returnAll) {
487
+ var outputKeys = difference(availableKeys, inputKeysSet);
488
+ this.outputVariables = Array.from(outputKeys);
489
+ } else {
490
+ this.outputVariables = this.chains[this.chains.length - 1].outputKeys;
491
+ }
492
+ } else {
493
+ var missingKeys1 = difference(new Set(this.outputVariables), new Set(availableKeys));
494
+ if (missingKeys1.size > 0) {
495
+ throw new Error("The following output variables were expected to be in the final chain output but were not found: ".concat(formatSet(missingKeys1), "."));
496
+ }
497
+ }
498
+ }
499
+ },
500
+ {
501
+ key: "_call",
502
+ value: /** @ignore */ function _call(values, runManager) {
503
+ var _this = this;
504
+ return _async_to_generator(function() {
505
+ var input, allChainValues, i, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, chain, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, key, err, output, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, key1;
506
+ return _ts_generator(this, function(_state) {
507
+ switch(_state.label){
508
+ case 0:
509
+ input = {};
510
+ allChainValues = values;
511
+ i = 0;
512
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
513
+ _state.label = 1;
514
+ case 1:
515
+ _state.trys.push([
516
+ 1,
517
+ 6,
518
+ 7,
519
+ 8
520
+ ]);
521
+ _iterator = _this.chains[Symbol.iterator]();
522
+ _state.label = 2;
523
+ case 2:
524
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
525
+ 3,
526
+ 5
527
+ ];
528
+ chain = _step.value;
529
+ i += 1;
530
+ return [
531
+ 4,
532
+ chain.call(allChainValues, runManager === null || runManager === void 0 ? void 0 : runManager.getChild("step_".concat(i)))
533
+ ];
534
+ case 3:
535
+ input = _state.sent();
536
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
537
+ try {
538
+ for(_iterator1 = Object.keys(input)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
539
+ key = _step1.value;
540
+ allChainValues[key] = input[key];
541
+ }
542
+ } catch (err) {
543
+ _didIteratorError1 = true;
544
+ _iteratorError1 = err;
545
+ } finally{
546
+ try {
547
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
548
+ _iterator1.return();
549
+ }
550
+ } finally{
551
+ if (_didIteratorError1) {
552
+ throw _iteratorError1;
553
+ }
554
+ }
555
+ }
556
+ _state.label = 4;
557
+ case 4:
558
+ _iteratorNormalCompletion = true;
559
+ return [
560
+ 3,
561
+ 2
562
+ ];
563
+ case 5:
564
+ return [
565
+ 3,
566
+ 8
567
+ ];
568
+ case 6:
569
+ err = _state.sent();
570
+ _didIteratorError = true;
571
+ _iteratorError = err;
572
+ return [
573
+ 3,
574
+ 8
575
+ ];
576
+ case 7:
577
+ try {
578
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
579
+ _iterator.return();
580
+ }
581
+ } finally{
582
+ if (_didIteratorError) {
583
+ throw _iteratorError;
584
+ }
585
+ }
586
+ return [
587
+ 7
588
+ ];
589
+ case 8:
590
+ output = {};
591
+ _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
592
+ try {
593
+ for(_iterator2 = _this.outputVariables[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
594
+ key1 = _step2.value;
595
+ output[key1] = allChainValues[key1];
596
+ }
597
+ } catch (err) {
598
+ _didIteratorError2 = true;
599
+ _iteratorError2 = err;
600
+ } finally{
601
+ try {
602
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
603
+ _iterator2.return();
604
+ }
605
+ } finally{
606
+ if (_didIteratorError2) {
607
+ throw _iteratorError2;
608
+ }
609
+ }
610
+ }
611
+ return [
612
+ 2,
613
+ output
614
+ ];
615
+ }
616
+ });
617
+ })();
618
+ }
619
+ },
620
+ {
621
+ key: "_chainType",
622
+ value: function _chainType() {
623
+ return "sequential_chain";
624
+ }
625
+ },
626
+ {
627
+ key: "serialize",
628
+ value: function serialize() {
629
+ var chains = [];
630
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
631
+ try {
632
+ for(var _iterator = this.chains[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
633
+ var chain = _step.value;
634
+ chains.push(chain.serialize());
635
+ }
636
+ } catch (err) {
637
+ _didIteratorError = true;
638
+ _iteratorError = err;
639
+ } finally{
640
+ try {
641
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
642
+ _iterator.return();
643
+ }
644
+ } finally{
645
+ if (_didIteratorError) {
646
+ throw _iteratorError;
647
+ }
648
+ }
649
+ }
650
+ return {
651
+ _type: this._chainType(),
652
+ input_variables: this.inputVariables,
653
+ output_variables: this.outputVariables,
654
+ chains: chains
655
+ };
656
+ }
657
+ }
658
+ ], [
659
+ {
660
+ key: "lc_name",
661
+ value: function lc_name() {
662
+ return "SequentialChain";
663
+ }
664
+ },
665
+ {
666
+ key: "deserialize",
667
+ value: function deserialize(data) {
668
+ return _async_to_generator(function() {
669
+ var chains, inputVariables, outputVariables, serializedChains, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, serializedChain, deserializedChain, err;
670
+ return _ts_generator(this, function(_state) {
671
+ switch(_state.label){
672
+ case 0:
673
+ chains = [];
674
+ inputVariables = data.input_variables;
675
+ outputVariables = data.output_variables;
676
+ serializedChains = data.chains;
677
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
678
+ _state.label = 1;
679
+ case 1:
680
+ _state.trys.push([
681
+ 1,
682
+ 6,
683
+ 7,
684
+ 8
685
+ ]);
686
+ _iterator = serializedChains[Symbol.iterator]();
687
+ _state.label = 2;
688
+ case 2:
689
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
690
+ 3,
691
+ 5
692
+ ];
693
+ serializedChain = _step.value;
694
+ return [
695
+ 4,
696
+ BaseChain.deserialize(serializedChain)
697
+ ];
698
+ case 3:
699
+ deserializedChain = _state.sent();
700
+ chains.push(deserializedChain);
701
+ _state.label = 4;
702
+ case 4:
703
+ _iteratorNormalCompletion = true;
704
+ return [
705
+ 3,
706
+ 2
707
+ ];
708
+ case 5:
709
+ return [
710
+ 3,
711
+ 8
712
+ ];
713
+ case 6:
714
+ err = _state.sent();
715
+ _didIteratorError = true;
716
+ _iteratorError = err;
717
+ return [
718
+ 3,
719
+ 8
720
+ ];
721
+ case 7:
722
+ try {
723
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
724
+ _iterator.return();
725
+ }
726
+ } finally{
727
+ if (_didIteratorError) {
728
+ throw _iteratorError;
729
+ }
730
+ }
731
+ return [
732
+ 7
733
+ ];
734
+ case 8:
735
+ return [
736
+ 2,
737
+ new SequentialChain({
738
+ chains: chains,
739
+ inputVariables: inputVariables,
740
+ outputVariables: outputVariables
741
+ })
742
+ ];
743
+ }
744
+ });
745
+ })();
746
+ }
747
+ }
748
+ ]);
749
+ return SequentialChain;
750
+ }(BaseChain);
751
+ /**
752
+ * @deprecated Switch to expression language: https://js.langchain.com/docs/expression_language/
753
+ * Simple chain where a single string output of one chain is fed directly into the next.
754
+ * @augments BaseChain
755
+ * @augments SimpleSequentialChainInput
756
+ *
757
+ * @example
758
+ * ```ts
759
+ * import { SimpleSequentialChain, LLMChain } from "langchain/chains";
760
+ * import { OpenAI } from "langchain/llms/openai";
761
+ * import { PromptTemplate } from "langchain/prompts";
762
+ *
763
+ * // This is an LLMChain to write a synopsis given a title of a play.
764
+ * const llm = new OpenAI({ temperature: 0 });
765
+ * const template = `You are a playwright. Given the title of play, it is your job to write a synopsis for that title.
766
+ *
767
+ * Title: {title}
768
+ * Playwright: This is a synopsis for the above play:`
769
+ * const promptTemplate = new PromptTemplate({ template, inputVariables: ["title"] });
770
+ * const synopsisChain = new LLMChain({ llm, prompt: promptTemplate });
771
+ *
772
+ *
773
+ * // This is an LLMChain to write a review of a play given a synopsis.
774
+ * const reviewLLM = new OpenAI({ temperature: 0 })
775
+ * const reviewTemplate = `You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
776
+ *
777
+ * Play Synopsis:
778
+ * {synopsis}
779
+ * Review from a New York Times play critic of the above play:`
780
+ * const reviewPromptTemplate = new PromptTemplate({ template: reviewTemplate, inputVariables: ["synopsis"] });
781
+ * const reviewChain = new LLMChain({ llm: reviewLLM, prompt: reviewPromptTemplate });
782
+ *
783
+ * const overallChain = new SimpleSequentialChain({chains: [synopsisChain, reviewChain], verbose:true})
784
+ * const review = await overallChain.run("Tragedy at sunset on the beach")
785
+ * // the variable review contains resulting play review.
786
+ * ```
787
+ */ var SimpleSequentialChain = /*#__PURE__*/ function(BaseChain1) {
788
+ _inherits(SimpleSequentialChain, BaseChain1);
789
+ var _super = _create_super(SimpleSequentialChain);
790
+ function SimpleSequentialChain(fields) {
791
+ _class_call_check(this, SimpleSequentialChain);
792
+ var _this;
793
+ _this = _super.call(this, fields);
794
+ Object.defineProperty(_assert_this_initialized(_this), "chains", {
795
+ enumerable: true,
796
+ configurable: true,
797
+ writable: true,
798
+ value: void 0
799
+ });
800
+ Object.defineProperty(_assert_this_initialized(_this), "inputKey", {
801
+ enumerable: true,
802
+ configurable: true,
803
+ writable: true,
804
+ value: "input"
805
+ });
806
+ Object.defineProperty(_assert_this_initialized(_this), "outputKey", {
807
+ enumerable: true,
808
+ configurable: true,
809
+ writable: true,
810
+ value: "output"
811
+ });
812
+ Object.defineProperty(_assert_this_initialized(_this), "trimOutputs", {
813
+ enumerable: true,
814
+ configurable: true,
815
+ writable: true,
816
+ value: void 0
817
+ });
818
+ _this.chains = fields.chains;
819
+ var _fields_trimOutputs;
820
+ _this.trimOutputs = (_fields_trimOutputs = fields.trimOutputs) !== null && _fields_trimOutputs !== void 0 ? _fields_trimOutputs : false;
821
+ _this._validateChains();
822
+ return _this;
823
+ }
824
+ _create_class(SimpleSequentialChain, [
825
+ {
826
+ key: "inputKeys",
827
+ get: function get() {
828
+ return [
829
+ this.inputKey
830
+ ];
831
+ }
832
+ },
833
+ {
834
+ key: "outputKeys",
835
+ get: function get() {
836
+ return [
837
+ this.outputKey
838
+ ];
839
+ }
840
+ },
841
+ {
842
+ /** @ignore */ key: "_validateChains",
843
+ value: function _validateChains() {
844
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
845
+ try {
846
+ var _loop = function() {
847
+ var chain = _step.value;
848
+ if (chain.inputKeys.filter(function(k) {
849
+ var _chain_memory;
850
+ var _ref;
851
+ return (_ref = !((_chain_memory = chain.memory) === null || _chain_memory === void 0 ? void 0 : _chain_memory.memoryKeys.includes(k))) !== null && _ref !== void 0 ? _ref : true;
852
+ }).length !== 1) {
853
+ throw new Error("Chains used in SimpleSequentialChain should all have one input, got ".concat(chain.inputKeys.length, " for ").concat(chain._chainType(), "."));
854
+ }
855
+ if (chain.outputKeys.length !== 1) {
856
+ throw new Error("Chains used in SimpleSequentialChain should all have one output, got ".concat(chain.outputKeys.length, " for ").concat(chain._chainType(), "."));
857
+ }
858
+ };
859
+ for(var _iterator = this.chains[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
860
+ } catch (err) {
861
+ _didIteratorError = true;
862
+ _iteratorError = err;
863
+ } finally{
864
+ try {
865
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
866
+ _iterator.return();
867
+ }
868
+ } finally{
869
+ if (_didIteratorError) {
870
+ throw _iteratorError;
871
+ }
872
+ }
873
+ }
874
+ }
875
+ },
876
+ {
877
+ key: "_call",
878
+ value: /** @ignore */ function _call(values, runManager) {
879
+ var _this = this;
880
+ return _async_to_generator(function() {
881
+ var input, i, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, chain, _obj, err;
882
+ return _ts_generator(this, function(_state) {
883
+ switch(_state.label){
884
+ case 0:
885
+ input = values[_this.inputKey];
886
+ i = 0;
887
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
888
+ _state.label = 1;
889
+ case 1:
890
+ _state.trys.push([
891
+ 1,
892
+ 7,
893
+ 8,
894
+ 9
895
+ ]);
896
+ _iterator = _this.chains[Symbol.iterator]();
897
+ _state.label = 2;
898
+ case 2:
899
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
900
+ 3,
901
+ 6
902
+ ];
903
+ chain = _step.value;
904
+ i += 1;
905
+ return [
906
+ 4,
907
+ chain.call((_obj = {}, _define_property(_obj, chain.inputKeys[0], input), _define_property(_obj, "signal", values.signal), _obj), runManager === null || runManager === void 0 ? void 0 : runManager.getChild("step_".concat(i)))
908
+ ];
909
+ case 3:
910
+ input = _state.sent()[chain.outputKeys[0]];
911
+ if (_this.trimOutputs) {
912
+ input = input.trim();
913
+ }
914
+ return [
915
+ 4,
916
+ runManager === null || runManager === void 0 ? void 0 : runManager.handleText(input)
917
+ ];
918
+ case 4:
919
+ _state.sent();
920
+ _state.label = 5;
921
+ case 5:
922
+ _iteratorNormalCompletion = true;
923
+ return [
924
+ 3,
925
+ 2
926
+ ];
927
+ case 6:
928
+ return [
929
+ 3,
930
+ 9
931
+ ];
932
+ case 7:
933
+ err = _state.sent();
934
+ _didIteratorError = true;
935
+ _iteratorError = err;
936
+ return [
937
+ 3,
938
+ 9
939
+ ];
940
+ case 8:
941
+ try {
942
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
943
+ _iterator.return();
944
+ }
945
+ } finally{
946
+ if (_didIteratorError) {
947
+ throw _iteratorError;
948
+ }
949
+ }
950
+ return [
951
+ 7
952
+ ];
953
+ case 9:
954
+ return [
955
+ 2,
956
+ _define_property({}, _this.outputKey, input)
957
+ ];
958
+ }
959
+ });
960
+ })();
961
+ }
962
+ },
963
+ {
964
+ key: "_chainType",
965
+ value: function _chainType() {
966
+ return "simple_sequential_chain";
967
+ }
968
+ },
969
+ {
970
+ key: "serialize",
971
+ value: function serialize() {
972
+ var chains = [];
973
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
974
+ try {
975
+ for(var _iterator = this.chains[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
976
+ var chain = _step.value;
977
+ chains.push(chain.serialize());
978
+ }
979
+ } catch (err) {
980
+ _didIteratorError = true;
981
+ _iteratorError = err;
982
+ } finally{
983
+ try {
984
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
985
+ _iterator.return();
986
+ }
987
+ } finally{
988
+ if (_didIteratorError) {
989
+ throw _iteratorError;
990
+ }
991
+ }
992
+ }
993
+ return {
994
+ _type: this._chainType(),
995
+ chains: chains
996
+ };
997
+ }
998
+ }
999
+ ], [
1000
+ {
1001
+ key: "lc_name",
1002
+ value: function lc_name() {
1003
+ return "SimpleSequentialChain";
1004
+ }
1005
+ },
1006
+ {
1007
+ key: "deserialize",
1008
+ value: function deserialize(data) {
1009
+ return _async_to_generator(function() {
1010
+ var chains, serializedChains, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, serializedChain, deserializedChain, err;
1011
+ return _ts_generator(this, function(_state) {
1012
+ switch(_state.label){
1013
+ case 0:
1014
+ chains = [];
1015
+ serializedChains = data.chains;
1016
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1017
+ _state.label = 1;
1018
+ case 1:
1019
+ _state.trys.push([
1020
+ 1,
1021
+ 6,
1022
+ 7,
1023
+ 8
1024
+ ]);
1025
+ _iterator = serializedChains[Symbol.iterator]();
1026
+ _state.label = 2;
1027
+ case 2:
1028
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1029
+ 3,
1030
+ 5
1031
+ ];
1032
+ serializedChain = _step.value;
1033
+ return [
1034
+ 4,
1035
+ BaseChain.deserialize(serializedChain)
1036
+ ];
1037
+ case 3:
1038
+ deserializedChain = _state.sent();
1039
+ chains.push(deserializedChain);
1040
+ _state.label = 4;
1041
+ case 4:
1042
+ _iteratorNormalCompletion = true;
1043
+ return [
1044
+ 3,
1045
+ 2
1046
+ ];
1047
+ case 5:
1048
+ return [
1049
+ 3,
1050
+ 8
1051
+ ];
1052
+ case 6:
1053
+ err = _state.sent();
1054
+ _didIteratorError = true;
1055
+ _iteratorError = err;
1056
+ return [
1057
+ 3,
1058
+ 8
1059
+ ];
1060
+ case 7:
1061
+ try {
1062
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1063
+ _iterator.return();
1064
+ }
1065
+ } finally{
1066
+ if (_didIteratorError) {
1067
+ throw _iteratorError;
1068
+ }
1069
+ }
1070
+ return [
1071
+ 7
1072
+ ];
1073
+ case 8:
1074
+ return [
1075
+ 2,
1076
+ new SimpleSequentialChain({
1077
+ chains: chains
1078
+ })
1079
+ ];
1080
+ }
1081
+ });
1082
+ })();
1083
+ }
1084
+ }
1085
+ ]);
1086
+ return SimpleSequentialChain;
1087
+ }(BaseChain);
1088
+
1089
+ export { SequentialChain, SimpleSequentialChain };