medpromptjs 0.3.2 → 0.4.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.
@@ -35,283 +35,149 @@ function _asyncToGenerator(n) {
35
35
  });
36
36
  };
37
37
  }
38
+ function _defineProperties(e, r) {
39
+ for (var t = 0; t < r.length; t++) {
40
+ var o = r[t];
41
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
42
+ }
43
+ }
44
+ function _createClass(e, r, t) {
45
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
46
+ writable: !1
47
+ }), e;
48
+ }
38
49
  function _inheritsLoose(t, o) {
39
50
  t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
40
51
  }
41
- function _regeneratorRuntime() {
42
- _regeneratorRuntime = function () {
43
- return r;
44
- };
45
- var t,
46
- r = {},
47
- e = Object.prototype,
48
- n = e.hasOwnProperty,
49
- o = "function" == typeof Symbol ? Symbol : {},
50
- i = o.iterator || "@@iterator",
51
- a = o.asyncIterator || "@@asyncIterator",
52
- u = o.toStringTag || "@@toStringTag";
53
- function c(t, r, e, n) {
54
- Object.defineProperty(t, r, {
55
- value: e,
56
- enumerable: !n,
57
- configurable: !n,
58
- writable: !n
59
- });
60
- }
61
- try {
62
- c({}, "");
63
- } catch (t) {
64
- c = function (t, r, e) {
65
- return t[r] = e;
66
- };
67
- }
68
- function h(r, e, n, o) {
69
- var i = e && e.prototype instanceof Generator ? e : Generator,
70
- a = Object.create(i.prototype);
71
- return c(a, "_invoke", function (r, e, n) {
72
- var o = 1;
73
- return function (i, a) {
74
- if (3 === o) throw Error("Generator is already running");
75
- if (4 === o) {
76
- if ("throw" === i) throw a;
77
- return {
78
- value: t,
79
- done: !0
80
- };
81
- }
82
- for (n.method = i, n.arg = a;;) {
83
- var u = n.delegate;
84
- if (u) {
85
- var c = d(u, n);
86
- if (c) {
87
- if (c === f) continue;
88
- return c;
89
- }
52
+ function _regenerator() {
53
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
54
+ var e,
55
+ t,
56
+ r = "function" == typeof Symbol ? Symbol : {},
57
+ n = r.iterator || "@@iterator",
58
+ o = r.toStringTag || "@@toStringTag";
59
+ function i(r, n, o, i) {
60
+ var c = n && n.prototype instanceof Generator ? n : Generator,
61
+ u = Object.create(c.prototype);
62
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
63
+ var i,
64
+ c,
65
+ u,
66
+ f = 0,
67
+ p = o || [],
68
+ y = !1,
69
+ G = {
70
+ p: 0,
71
+ n: 0,
72
+ v: e,
73
+ a: d,
74
+ f: d.bind(e, 4),
75
+ d: function (t, r) {
76
+ return i = t, c = 0, u = e, G.n = r, a;
90
77
  }
91
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
92
- if (1 === o) throw o = 4, n.arg;
93
- n.dispatchException(n.arg);
94
- } else "return" === n.method && n.abrupt("return", n.arg);
95
- o = 3;
96
- var h = s(r, e, n);
97
- if ("normal" === h.type) {
98
- if (o = n.done ? 4 : 2, h.arg === f) continue;
99
- return {
100
- value: h.arg,
101
- done: n.done
102
- };
78
+ };
79
+ function d(r, n) {
80
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
81
+ var o,
82
+ i = p[t],
83
+ d = G.p,
84
+ l = i[2];
85
+ r > 3 ? (o = l === n) && (c = i[4] || 3, u = i[5] === e ? i[3] : i[5], i[4] = 3, i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
86
+ }
87
+ if (o || r > 1) return a;
88
+ throw y = !0, n;
89
+ }
90
+ return function (o, p, l) {
91
+ if (f > 1) throw TypeError("Generator is already running");
92
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
93
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
94
+ try {
95
+ if (f = 2, i) {
96
+ if (c || (o = "next"), t = i[o]) {
97
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
98
+ if (!t.done) return t;
99
+ u = t.value, c < 2 && (c = 0);
100
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
101
+ i = e;
102
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
103
+ } catch (t) {
104
+ i = e, c = 1, u = t;
105
+ } finally {
106
+ f = 1;
103
107
  }
104
- "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg);
105
108
  }
109
+ return {
110
+ value: t,
111
+ done: y
112
+ };
106
113
  };
107
- }(r, n, new Context(o || [])), !0), a;
114
+ }(r, o, i), !0), u;
108
115
  }
109
- function s(t, r, e) {
110
- try {
111
- return {
112
- type: "normal",
113
- arg: t.call(r, e)
114
- };
115
- } catch (t) {
116
- return {
117
- type: "throw",
118
- arg: t
119
- };
120
- }
121
- }
122
- r.wrap = h;
123
- var f = {};
116
+ var a = {};
124
117
  function Generator() {}
125
118
  function GeneratorFunction() {}
126
119
  function GeneratorFunctionPrototype() {}
127
- var l = {};
128
- c(l, i, function () {
129
- return this;
130
- });
131
- var p = Object.getPrototypeOf,
132
- y = p && p(p(x([])));
133
- y && y !== e && n.call(y, i) && (l = y);
134
- var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l);
135
- function g(t) {
136
- ["next", "throw", "return"].forEach(function (r) {
137
- c(t, r, function (t) {
138
- return this._invoke(r, t);
139
- });
140
- });
141
- }
142
- function AsyncIterator(t, r) {
143
- function e(o, i, a, u) {
144
- var c = s(t[o], t, i);
145
- if ("throw" !== c.type) {
146
- var h = c.arg,
147
- f = h.value;
148
- return f && "object" == typeof f && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) {
149
- e("next", t, a, u);
150
- }, function (t) {
151
- e("throw", t, a, u);
152
- }) : r.resolve(f).then(function (t) {
153
- h.value = t, a(h);
154
- }, function (t) {
155
- return e("throw", t, a, u);
156
- });
157
- }
158
- u(c.arg);
159
- }
160
- var o;
161
- c(this, "_invoke", function (t, n) {
162
- function i() {
163
- return new r(function (r, o) {
164
- e(t, n, r, o);
165
- });
166
- }
167
- return o = o ? o.then(i, i) : i();
168
- }, !0);
169
- }
170
- function d(r, e) {
171
- var n = e.method,
172
- o = r.i[n];
173
- if (o === t) return e.delegate = null, "throw" === n && r.i.return && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f;
174
- var i = s(o, r.i, e.arg);
175
- if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f;
176
- var a = i.arg;
177
- return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f);
178
- }
179
- function w(t) {
180
- this.tryEntries.push(t);
120
+ t = Object.getPrototypeOf;
121
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
122
+ return this;
123
+ }), t),
124
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
125
+ function f(e) {
126
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
181
127
  }
182
- function m(r) {
183
- var e = r[4] || {};
184
- e.type = "normal", e.arg = t, r[4] = e;
185
- }
186
- function Context(t) {
187
- this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0);
188
- }
189
- function x(r) {
190
- if (null != r) {
191
- var e = r[i];
192
- if (e) return e.call(r);
193
- if ("function" == typeof r.next) return r;
194
- if (!isNaN(r.length)) {
195
- var o = -1,
196
- a = function e() {
197
- for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e;
198
- return e.value = t, e.done = !0, e;
199
- };
200
- return a.next = a;
201
- }
202
- }
203
- throw new TypeError(typeof r + " is not iterable");
204
- }
205
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), c(GeneratorFunctionPrototype, u, GeneratorFunction.displayName = "GeneratorFunction"), r.isGeneratorFunction = function (t) {
206
- var r = "function" == typeof t && t.constructor;
207
- return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
208
- }, r.mark = function (t) {
209
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t;
210
- }, r.awrap = function (t) {
211
- return {
212
- __await: t
213
- };
214
- }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () {
215
- return this;
216
- }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) {
217
- void 0 === i && (i = Promise);
218
- var a = new AsyncIterator(h(t, e, n, o), i);
219
- return r.isGeneratorFunction(e) ? a : a.next().then(function (t) {
220
- return t.done ? t.value : a.next();
221
- });
222
- }, g(v), c(v, u, "Generator"), c(v, i, function () {
128
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
223
129
  return this;
224
- }), c(v, "toString", function () {
130
+ }), _regeneratorDefine(u, "toString", function () {
225
131
  return "[object Generator]";
226
- }), r.keys = function (t) {
227
- var r = Object(t),
228
- e = [];
229
- for (var n in r) e.unshift(n);
230
- return function t() {
231
- for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t;
232
- return t.done = !0, t;
132
+ }), (_regenerator = function () {
133
+ return {
134
+ w: i,
135
+ m: f
233
136
  };
234
- }, r.values = x, Context.prototype = {
235
- constructor: Context,
236
- reset: function (r) {
237
- if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+e.slice(1)) && (this[e] = t);
238
- },
239
- stop: function () {
240
- this.done = !0;
241
- var t = this.tryEntries[0][4];
242
- if ("throw" === t.type) throw t.arg;
243
- return this.rval;
244
- },
245
- dispatchException: function (r) {
246
- if (this.done) throw r;
247
- var e = this;
248
- function n(t) {
249
- a.type = "throw", a.arg = r, e.next = t;
250
- }
251
- for (var o = e.tryEntries.length - 1; o >= 0; --o) {
252
- var i = this.tryEntries[o],
253
- a = i[4],
254
- u = this.prev,
255
- c = i[1],
256
- h = i[2];
257
- if (-1 === i[0]) return n("end"), !1;
258
- if (!c && !h) throw Error("try statement without catch or finally");
259
- if (null != i[0] && i[0] <= u) {
260
- if (u < c) return this.method = "next", this.arg = t, n(c), !0;
261
- if (u < h) return n(h), !1;
262
- }
263
- }
264
- },
265
- abrupt: function (t, r) {
266
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
267
- var n = this.tryEntries[e];
268
- if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) {
269
- var o = n;
270
- break;
271
- }
272
- }
273
- o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null);
274
- var i = o ? o[4] : {};
275
- return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i);
276
- },
277
- complete: function (t, r) {
278
- if ("throw" === t.type) throw t.arg;
279
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f;
280
- },
281
- finish: function (t) {
282
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
283
- var e = this.tryEntries[r];
284
- if (e[2] === t) return this.complete(e[4], e[3]), m(e), f;
285
- }
286
- },
287
- catch: function (t) {
288
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
289
- var e = this.tryEntries[r];
290
- if (e[0] === t) {
291
- var n = e[4];
292
- if ("throw" === n.type) {
293
- var o = n.arg;
294
- m(e);
295
- }
296
- return o;
297
- }
137
+ })();
138
+ }
139
+ function _regeneratorDefine(e, r, n, t) {
140
+ var i = Object.defineProperty;
141
+ try {
142
+ i({}, "", {});
143
+ } catch (e) {
144
+ i = 0;
145
+ }
146
+ _regeneratorDefine = function (e, r, n, t) {
147
+ if (r) i ? i(e, r, {
148
+ value: n,
149
+ enumerable: !t,
150
+ configurable: !t,
151
+ writable: !t
152
+ }) : e[r] = n;else {
153
+ function o(r, n) {
154
+ _regeneratorDefine(e, r, function (e) {
155
+ return this._invoke(r, n, e);
156
+ });
298
157
  }
299
- throw Error("illegal catch attempt");
300
- },
301
- delegateYield: function (r, e, n) {
302
- return this.delegate = {
303
- i: x(r),
304
- r: e,
305
- n: n
306
- }, "next" === this.method && (this.arg = t), f;
307
- }
308
- }, r;
158
+ o("next", 0), o("throw", 1), o("return", 2);
159
+ }
160
+ }, _regeneratorDefine(e, r, n, t);
309
161
  }
310
162
  function _setPrototypeOf(t, e) {
311
163
  return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
312
164
  return t.__proto__ = e, t;
313
165
  }, _setPrototypeOf(t, e);
314
166
  }
167
+ function _toPrimitive(t, r) {
168
+ if ("object" != typeof t || !t) return t;
169
+ var e = t[Symbol.toPrimitive];
170
+ if (void 0 !== e) {
171
+ var i = e.call(t, r || "default");
172
+ if ("object" != typeof i) return i;
173
+ throw new TypeError("@@toPrimitive must return a primitive value.");
174
+ }
175
+ return ("string" === r ? String : Number)(t);
176
+ }
177
+ function _toPropertyKey(t) {
178
+ var i = _toPrimitive(t, "string");
179
+ return "symbol" == typeof i ? i : i + "";
180
+ }
315
181
 
316
182
  /**
317
183
  * Copyright 2024 Bell Eapen
@@ -337,38 +203,41 @@ var mydi = function mydi(c, m, b) {
337
203
  };
338
204
 
339
205
  var BaseChain = /*#__PURE__*/function () {
340
- function BaseChain(container, name, description, template) {
341
- if (template === void 0) {
342
- template = "\n Summarize the following text:\n {input}\n ";
343
- }
206
+ function BaseChain(container) {
344
207
  this.container = void 0;
345
- this.tools = void 0;
346
- this.name = void 0;
347
- this.description = void 0;
208
+ this._name = '';
209
+ this._description = '';
210
+ this._template = '';
348
211
  this.prompt = void 0;
349
212
  this.llm = void 0;
350
- this.template = void 0;
351
213
  this.chat_model = void 0;
352
214
  this.runnable = void 0;
353
215
  this.container = container;
354
- this.name = name === '' ? this.camelize(this.constructor.name) : name;
355
- this.description = description === '' ? this.snake_case(this.constructor.name) : description;
356
- this.template = template;
357
- this.tools = this.resolve('tools');
358
216
  this.llm = this.resolve('main-llm');
359
217
  this.chat_model = false;
360
- try {
361
- this.chat_model = this.resolve('chat_model');
362
- } catch (e) {}
218
+ this.initialize();
219
+ }
220
+ // Getters and setters
221
+ var _proto = BaseChain.prototype;
222
+ _proto.initialize = function initialize() {
223
+ if (this._name === '') {
224
+ this._name = this.camelize(this.constructor.name);
225
+ }
226
+ if (this._description === '') {
227
+ this._description = this.snake_case(this.constructor.name);
228
+ }
229
+ if (this._template === '') {
230
+ this._template = "{{input}}";
231
+ }
232
+ this.prompt = this.prompt || prompts.PromptTemplate.fromTemplate(this._template);
363
233
  if (this.chat_model) {
364
- this.prompt = prompts.ChatPromptTemplate.fromTemplate(this.template);
234
+ this.prompt = prompts.ChatPromptTemplate.fromTemplate(this._template);
365
235
  } else {
366
- this.prompt = prompts.PromptTemplate.fromTemplate(this.template);
236
+ this.prompt = prompts.PromptTemplate.fromTemplate(this._template);
367
237
  }
368
- }
369
- var _proto = BaseChain.prototype;
238
+ };
370
239
  _proto.resolve = function resolve(name) {
371
- return mydi(this.container, this.name, name);
240
+ return mydi(this.container, this._name, name);
372
241
  };
373
242
  _proto.camelize = function camelize(str) {
374
243
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
@@ -386,30 +255,27 @@ var BaseChain = /*#__PURE__*/function () {
386
255
  _proto.chain =
387
256
  /*#__PURE__*/
388
257
  function () {
389
- var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
258
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
390
259
  var response, aiMessage;
391
- return _regeneratorRuntime().wrap(function _callee$(_context) {
392
- while (1) switch (_context.prev = _context.next) {
260
+ return _regenerator().w(function (_context) {
261
+ while (1) switch (_context.n) {
393
262
  case 0:
394
263
  this.runnable = runnables.RunnableSequence.from([new runnables.RunnablePassthrough(), this.prompt, this.llm]);
395
264
  if (!this.chat_model) {
396
- _context.next = 7;
265
+ _context.n = 2;
397
266
  break;
398
267
  }
399
- _context.next = 4;
268
+ _context.n = 1;
400
269
  return this.runnable.invoke(input);
401
- case 4:
402
- response = _context.sent;
270
+ case 1:
271
+ response = _context.v;
403
272
  aiMessage = new messages.AIMessage(response);
404
- return _context.abrupt("return", aiMessage.content);
405
- case 7:
406
- _context.next = 9;
273
+ return _context.a(2, aiMessage.content);
274
+ case 2:
275
+ _context.n = 3;
407
276
  return this.runnable.invoke(input);
408
- case 9:
409
- return _context.abrupt("return", _context.sent);
410
- case 10:
411
- case "end":
412
- return _context.stop();
277
+ case 3:
278
+ return _context.a(2, _context.v);
413
279
  }
414
280
  }, _callee, this);
415
281
  }));
@@ -418,26 +284,78 @@ var BaseChain = /*#__PURE__*/function () {
418
284
  }
419
285
  return chain;
420
286
  }();
421
- return BaseChain;
287
+ return _createClass(BaseChain, [{
288
+ key: "name",
289
+ get: function get() {
290
+ return this._name;
291
+ },
292
+ set: function set(value) {
293
+ this._name = value === '' ? this.camelize(this.constructor.name) : value;
294
+ }
295
+ }, {
296
+ key: "description",
297
+ get: function get() {
298
+ return this._description;
299
+ },
300
+ set: function set(value) {
301
+ this._description = value === '' ? this.snake_case(this.constructor.name) : value;
302
+ }
303
+ }, {
304
+ key: "template",
305
+ get: function get() {
306
+ return this._template;
307
+ },
308
+ set: function set(value) {
309
+ this._template = value;
310
+ try {
311
+ this.chat_model = this.resolve('chat_model');
312
+ } catch (e) {}
313
+ if (this.chat_model) {
314
+ this.prompt = prompts.ChatPromptTemplate.fromTemplate(this._template);
315
+ } else {
316
+ this.prompt = prompts.PromptTemplate.fromTemplate(this._template);
317
+ }
318
+ }
319
+ }]);
422
320
  }();
423
321
 
424
322
  var BaseAgent = /*#__PURE__*/function () {
425
323
  function BaseAgent(container) {
426
324
  this.container = void 0;
427
- this.tools = void 0;
428
- this.name = void 0;
325
+ this._name = '';
326
+ this._description = '';
327
+ this._template = "\n ## Question: {question}\n ## Answer: {answer}\n Given the above question and answer, generate a chain of thought explanation for the answer.\n First, start with the model generated chain of thought explanation.\n End the chain of though explanation with:\n Therefore, the answer is {answer}.\n ";
328
+ this._tools = [];
429
329
  this.prompt = void 0;
430
330
  this.llm = void 0;
431
- this.template = "\n ## Question: {question}\n ## Answer: {answer}\n Given the above question and answer, generate a chain of thought explanation for the answer.\n First, start with the model generated chain of thought explanation.\n End the chain of though explanation with:\n Therefore, the answer is {answer}.\n ";
331
+ this.chat_model = void 0;
332
+ this.runnable = void 0;
432
333
  this.container = container;
433
- this.name = this.camelize(this.constructor.name);
434
- this.tools = this.resolve('tools');
435
- this.prompt = this.resolve('prompt') !== '' ? this.resolve('prompt') : prompts.PromptTemplate.fromTemplate(this.template);
436
334
  this.llm = this.resolve('main-llm');
335
+ this.chat_model = false;
336
+ this.initialize();
437
337
  }
338
+ // Getters and setters
438
339
  var _proto = BaseAgent.prototype;
340
+ _proto.initialize = function initialize() {
341
+ if (this._name === '') {
342
+ this._name = this.camelize(this.constructor.name);
343
+ }
344
+ if (this._description === '') {
345
+ this._description = this.snake_case(this.constructor.name);
346
+ }
347
+ if (this._template === '') {
348
+ this._template = "{{input}}";
349
+ }
350
+ this.prompt = this.prompt || prompts.PromptTemplate.fromTemplate(this._template);
351
+ if (this.chat_model) {
352
+ this.prompt = prompts.ChatPromptTemplate.fromTemplate(this._template);
353
+ } else {
354
+ this.prompt = prompts.PromptTemplate.fromTemplate(this._template);
355
+ }
356
+ };
439
357
  _proto.resolve = function resolve(name) {
440
- return mydi(this.container, this.name, name);
358
+ return mydi(this.container, this._name, name);
441
359
  };
442
360
  _proto.camelize = function camelize(str) {
443
361
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
@@ -450,32 +368,29 @@ var BaseAgent = /*#__PURE__*/function () {
450
368
  }).replace(/\s+/g, '');
451
369
  };
452
370
  _proto.run = /*#__PURE__*/function () {
453
- var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
371
+ var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(input) {
454
372
  var agent, agentExecutor;
455
- return _regeneratorRuntime().wrap(function _callee$(_context) {
456
- while (1) switch (_context.prev = _context.next) {
373
+ return _regenerator().w(function (_context) {
374
+ while (1) switch (_context.n) {
457
375
  case 0:
458
- _context.next = 2;
376
+ _context.n = 1;
459
377
  return agents.createStructuredChatAgent({
460
378
  llm: this.llm,
461
- tools: this.tools,
379
+ tools: this._tools,
462
380
  prompt: this.prompt
463
381
  });
464
- case 2:
465
- agent = _context.sent;
382
+ case 1:
383
+ agent = _context.v;
466
384
  agentExecutor = new agents.AgentExecutor({
467
385
  agent: agent,
468
386
  tools: this.tools,
469
387
  // verbose: true,
470
388
  handleParsingErrors: 'Please try again, paying close attention to the final answer'
471
389
  });
472
- _context.next = 6;
390
+ _context.n = 2;
473
391
  return agentExecutor.invoke(input);
474
- case 6:
475
- return _context.abrupt("return", _context.sent);
476
- case 7:
477
- case "end":
478
- return _context.stop();
392
+ case 2:
393
+ return _context.a(2, _context.v);
479
394
  }
480
395
  }, _callee, this);
481
396
  }));
@@ -484,7 +399,48 @@ var BaseAgent = /*#__PURE__*/function () {
484
399
  }
485
400
  return run;
486
401
  }();
487
- return BaseAgent;
402
+ return _createClass(BaseAgent, [{
403
+ key: "name",
404
+ get: function get() {
405
+ return this._name;
406
+ },
407
+ set: function set(value) {
408
+ this._name = value === '' ? this.camelize(this.constructor.name) : value;
409
+ }
410
+ }, {
411
+ key: "description",
412
+ get: function get() {
413
+ return this._description;
414
+ },
415
+ set: function set(value) {
416
+ this._description = value === '' ? this.snake_case(this.constructor.name) : value;
417
+ }
418
+ }, {
419
+ key: "template",
420
+ get: function get() {
421
+ return this._template;
422
+ },
423
+ set: function set(value) {
424
+ this._template = value;
425
+ try {
426
+ this.chat_model = this.resolve('chat_model');
427
+ } catch (e) {}
428
+ if (this.chat_model) {
429
+ this.prompt = prompts.ChatPromptTemplate.fromTemplate(this._template);
430
+ } else {
431
+ this.prompt = prompts.PromptTemplate.fromTemplate(this._template);
432
+ }
433
+ }
434
+ // Getters and setters for tools
435
+ }, {
436
+ key: "tools",
437
+ get: function get() {
438
+ return this._tools;
439
+ },
440
+ set: function set(value) {
441
+ this._tools = value;
442
+ }
443
+ }]);
488
444
  }();
489
445
 
490
446
  var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
@@ -504,14 +460,11 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
504
460
  _this.description = void 0;
505
461
  _this.schema = void 0;
506
462
  _this.func = /*#__PURE__*/function () {
507
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
508
- return _regeneratorRuntime().wrap(function _callee$(_context) {
509
- while (1) switch (_context.prev = _context.next) {
463
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(args) {
464
+ return _regenerator().w(function (_context) {
465
+ while (1) switch (_context.n) {
510
466
  case 0:
511
- return _context.abrupt("return", 'override this');
512
- case 1:
513
- case "end":
514
- return _context.stop();
467
+ return _context.a(2, 'override this');
515
468
  }
516
469
  }, _callee);
517
470
  }));
@@ -543,54 +496,6 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
543
496
  return BaseTool;
544
497
  }(tools.DynamicStructuredTool);
545
498
 
546
- var MapQuery = /*#__PURE__*/function (_BaseChain) {
547
- function MapQuery() {
548
- var _this;
549
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
550
- args[_key] = arguments[_key];
551
- }
552
- _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
553
- _this.name = 'MapQuery';
554
- _this.description = 'Map a CQL query to a natural language.';
555
- _this.template = "\n You are an assistant that can convert statements to a natural language query as in the example below.\n\n\n\n Statements: Visual foot exam in the last month. Visual foot exam showed active infection.\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n Statements: {expression}\n query: ";
556
- return _this;
557
- }
558
- _inheritsLoose(MapQuery, _BaseChain);
559
- return MapQuery;
560
- }(BaseChain);
561
-
562
- var MapDoc = /*#__PURE__*/function (_BaseChain) {
563
- function MapDoc() {
564
- var _this;
565
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
566
- args[_key] = arguments[_key];
567
- }
568
- _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
569
- _this.name = 'MapDoc';
570
- _this.description = 'Map a set of documents to facts.';
571
- _this.template = "\n You will be given a document and few statements.\n\n Extract facts from the document that are relevant to the statements.\n\n Do not include any irrelevant information or context.\n\n\n \n Example:\n\n document: The patient is a 45-year-old male with a history of hypertension. He presented with chest pain and was diagnosed with myocardial infarction. He was treated with aspirin and beta-blockers.\n\n statements: diagnosis of myocardial infarction. currently on beta-blockers.\n\n facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\n\n document: {document} \n\n statements: {statements}\n\n facts: ";
572
- return _this;
573
- }
574
- _inheritsLoose(MapDoc, _BaseChain);
575
- return MapDoc;
576
- }(BaseChain);
577
-
578
- var ReduceChain = /*#__PURE__*/function (_BaseChain) {
579
- function ReduceChain() {
580
- var _this;
581
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
582
- args[_key] = arguments[_key];
583
- }
584
- _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
585
- _this.name = 'Reduce';
586
- _this.description = 'Reduce a set of documents to binary answer.';
587
- _this.template = "\n Say yes if the facts mentions all aspects of the query, else say no.\n\n\n Example:\n facts: Patient had a laproscopy 27 days back. The findings were normal. \n\n query: Did the patient have a laproscopy this month?\n\n answer: YES. The patient had a laproscopy 27 days back.\n\n facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \n\n query: Is the patient on heparin and metformin?\n\n answer: NO. The patient is on heparin but not on metformin.\n\n facts: A visual foot examination was performed 26 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\n\n facts: A visual foot examination was performed 126 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\n\n facts: {facts} \n\n query: {query}\n\n answer: ";
588
- return _this;
589
- }
590
- _inheritsLoose(ReduceChain, _BaseChain);
591
- return ReduceChain;
592
- }(BaseChain);
593
-
594
499
  var log = /*#__PURE__*/new tslog.Logger();
595
500
  var LLMLoop = /*#__PURE__*/function (_BaseChain) {
596
501
  function LLMLoop() {
@@ -600,21 +505,19 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
600
505
  }
601
506
  _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
602
507
  // Implement the LLM loop logic here
603
- _this.string_expression = '';
604
- _this.name = 'LLMLoop';
605
- _this.description = 'Base LLM Loop.';
606
- _this.mapQuery = new MapQuery(_this.container, '', '');
607
- _this.mapDoc = new MapDoc(_this.container, '', '');
608
- _this.reduceChain = new ReduceChain(_this.container, '', '');
508
+ _this.stringExpression = '';
509
+ _this._mapQueryTemplate = "\n You are an assistant that can convert statements to a natural language query as in the example below.\n\n\n\n Statements: Visual foot exam in the last month. Visual foot exam showed active infection.\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n Statements: {expression}\n query: ";
510
+ _this._mapDocTemplate = "\n You will be given a document and few statements.\n\n Extract facts from the document that are relevant to the statements.\n\n Do not include any irrelevant information or context.\n\n\n\n Example:\n\n document: The patient is a 45-year-old male with a history of hypertension. He presented with chest pain and was diagnosed with myocardial infarction. He was treated with aspirin and beta-blockers.\n\n statements: diagnosis of myocardial infarction. currently on beta-blockers.\n\n facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\n\n document: {document} \n\n statements: {statements}\n\n facts: ";
511
+ _this._reduceChainTemplate = "\n Say yes if the facts mentions all aspects of the query, else say no.\n\n\n Example:\n facts: Patient had a laproscopy 27 days back. The findings were normal. \n\n query: Did the patient have a laproscopy this month?\n\n answer: YES. The patient had a laproscopy 27 days back.\n\n facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \n\n query: Is the patient on heparin and metformin?\n\n answer: NO. The patient is on heparin but not on metformin.\n\n facts: A visual foot examination was performed 26 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\n\n facts: A visual foot examination was performed 126 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\n\n facts: {facts} \n\n query: {query}\n\n answer: ";
609
512
  return _this;
610
513
  }
611
514
  _inheritsLoose(LLMLoop, _BaseChain);
612
515
  var _proto = LLMLoop.prototype;
613
516
  _proto.checkAssertion = /*#__PURE__*/function () {
614
- var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
517
+ var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(expression, context) {
615
518
  var _expression, _context, _content, _input, result;
616
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
617
- while (1) switch (_context2.prev = _context2.next) {
519
+ return _regenerator().w(function (_context2) {
520
+ while (1) switch (_context2.n) {
618
521
  case 0:
619
522
  _expression = '';
620
523
  try {
@@ -655,15 +558,12 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
655
558
  context: _content
656
559
  }
657
560
  };
658
- _context2.next = 12;
561
+ _context2.n = 1;
659
562
  return this.chain(_input);
660
- case 12:
661
- result = _context2.sent;
563
+ case 1:
564
+ result = _context2.v;
662
565
  log.info("Assertion check result: " + result);
663
- return _context2.abrupt("return", result);
664
- case 15:
665
- case "end":
666
- return _context2.stop();
566
+ return _context2.a(2, result);
667
567
  }
668
568
  }, _callee, this);
669
569
  }));
@@ -673,20 +573,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
673
573
  return checkAssertion;
674
574
  }();
675
575
  _proto.checkMention = /*#__PURE__*/function () {
676
- var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(expression, context) {
677
- return _regeneratorRuntime().wrap(function _callee2$(_context3) {
678
- while (1) switch (_context3.prev = _context3.next) {
576
+ var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(expression, context) {
577
+ return _regenerator().w(function (_context3) {
578
+ while (1) switch (_context3.n) {
679
579
  case 0:
680
580
  if (!(expression && context)) {
681
- _context3.next = 2;
581
+ _context3.n = 1;
682
582
  break;
683
583
  }
684
- return _context3.abrupt("return", true);
685
- case 2:
686
- return _context3.abrupt("return", false);
687
- case 3:
688
- case "end":
689
- return _context3.stop();
584
+ return _context3.a(2, true);
585
+ case 1:
586
+ return _context3.a(2, false);
690
587
  }
691
588
  }, _callee2);
692
589
  }));
@@ -696,20 +593,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
696
593
  return checkMention;
697
594
  }();
698
595
  _proto.checkNegation = /*#__PURE__*/function () {
699
- var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(expression, context) {
700
- return _regeneratorRuntime().wrap(function _callee3$(_context4) {
701
- while (1) switch (_context4.prev = _context4.next) {
596
+ var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(expression, context) {
597
+ return _regenerator().w(function (_context4) {
598
+ while (1) switch (_context4.n) {
702
599
  case 0:
703
600
  if (!(expression && context)) {
704
- _context4.next = 2;
601
+ _context4.n = 1;
705
602
  break;
706
603
  }
707
- return _context4.abrupt("return", true);
708
- case 2:
709
- return _context4.abrupt("return", false);
710
- case 3:
711
- case "end":
712
- return _context4.stop();
604
+ return _context4.a(2, true);
605
+ case 1:
606
+ return _context4.a(2, false);
713
607
  }
714
608
  }, _callee3);
715
609
  }));
@@ -744,10 +638,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
744
638
  });
745
639
  };
746
640
  _proto.textSplitter = /*#__PURE__*/function () {
747
- var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text, chunkSize, chunkOverlap) {
641
+ var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(text, chunkSize, chunkOverlap) {
748
642
  var textSplitter, texts;
749
- return _regeneratorRuntime().wrap(function _callee4$(_context5) {
750
- while (1) switch (_context5.prev = _context5.next) {
643
+ return _regenerator().w(function (_context5) {
644
+ while (1) switch (_context5.n) {
751
645
  case 0:
752
646
  if (chunkSize === void 0) {
753
647
  chunkSize = 3900;
@@ -759,17 +653,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
759
653
  chunkSize: chunkSize,
760
654
  chunkOverlap: chunkOverlap
761
655
  });
762
- _context5.next = 5;
656
+ _context5.n = 1;
763
657
  return textSplitter.splitText(text);
764
- case 5:
765
- texts = _context5.sent;
658
+ case 1:
659
+ texts = _context5.v;
766
660
  if (!(texts.length === 0)) {
767
- _context5.next = 9;
661
+ _context5.n = 2;
768
662
  break;
769
663
  }
770
664
  log.warn('No text chunks created. Please check the input text.');
771
- return _context5.abrupt("return", []);
772
- case 9:
665
+ return _context5.a(2, []);
666
+ case 2:
773
667
  if (texts.length > 100) {
774
668
  log.warn("Warning: More than 100 text chunks created (" + texts.length + "). This may affect performance.");
775
669
  }
@@ -777,10 +671,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
777
671
  log.warn("Warning: Chunk size is less than 1000 characters (" + chunkSize + "). This may lead to very small chunks.");
778
672
  }
779
673
  log.info("Text split into " + texts.length + " chunks with size " + chunkSize + " and overlap " + chunkOverlap);
780
- return _context5.abrupt("return", texts);
781
- case 13:
782
- case "end":
783
- return _context5.stop();
674
+ return _context5.a(2, texts);
784
675
  }
785
676
  }, _callee4);
786
677
  }));
@@ -823,45 +714,52 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
823
714
  if (typeof obj[key] === 'object') {
824
715
  this._printValues(obj[key]);
825
716
  } else {
826
- this.string_expression += obj[key] + ' ';
717
+ this.stringExpression += obj[key] + ' ';
827
718
  }
828
719
  }
829
720
  var _eliminate = ['true', 'false', 'null', 'undefined', 'String', 'Number', 'Object', 'Array', 'Boolean', 'value', 'Type', 'Specifier', 'Named'];
830
721
  _eliminate.forEach(function (element) {
831
722
  var regex = new RegExp(element, 'g');
832
- _this2.string_expression = _this2.string_expression.replace(regex, '');
723
+ _this2.stringExpression = _this2.stringExpression.replace(regex, '');
833
724
  });
834
- this.string_expression = this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
835
- return this.camelToString(this.string_expression);
725
+ this.stringExpression = this.stringExpression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
726
+ return this.camelToString(this.stringExpression);
836
727
  };
837
728
  _proto.chain = /*#__PURE__*/function () {
838
- var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(input) {
729
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(input) {
839
730
  var _this3 = this;
840
- var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQueryChain, mapDocChain, parallelChain, sequence;
841
- return _regeneratorRuntime().wrap(function _callee8$(_context9) {
842
- while (1) switch (_context9.prev = _context9.next) {
731
+ var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQuery, mapDoc, reduceChain, mapQueryChain, mapDocChain, parallelChain, sequence;
732
+ return _regenerator().w(function (_context9) {
733
+ while (1) switch (_context9.n) {
843
734
  case 0:
844
- _context9.next = 2;
735
+ _context9.n = 1;
845
736
  return import('@langchain/core/runnables');
846
- case 2:
847
- _yield$import = _context9.sent;
737
+ case 1:
738
+ _yield$import = _context9.v;
848
739
  RunnableSequence = _yield$import.RunnableSequence;
849
740
  RunnableParallel = _yield$import.RunnableParallel;
850
741
  RunnablePassthrough = _yield$import.RunnablePassthrough;
742
+ mapQuery = new BaseChain(this.container);
743
+ mapDoc = new BaseChain(this.container);
744
+ reduceChain = new BaseChain(this.container);
745
+ mapQuery.name = 'MapQuery';
746
+ mapQuery.description = 'Map the expression to a natural language query.';
747
+ mapQuery.template = this._mapQueryTemplate;
748
+ mapDoc.name = 'MapDoc';
749
+ mapDoc.description = 'Map the document to a set of facts.';
750
+ mapDoc.template = this._mapDocTemplate;
751
+ reduceChain.name = 'ReduceChain';
752
+ reduceChain.description = 'Reduce a set of documents to binary answer.';
753
+ reduceChain.template = this._reduceChainTemplate;
851
754
  mapQueryChain = RunnablePassthrough.assign({
852
755
  query: function () {
853
- var _query = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(input) {
854
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
855
- while (1) switch (_context6.prev = _context6.next) {
756
+ var _query = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(input) {
757
+ return _regenerator().w(function (_context6) {
758
+ while (1) switch (_context6.n) {
856
759
  case 0:
857
- return _context6.abrupt("return", _this3.mapQuery.chain({
858
- input: {
859
- expression: input.input.expression
860
- }
760
+ return _context6.a(2, mapQuery.chain({
761
+ expression: input.input.expression
861
762
  }));
862
- case 1:
863
- case "end":
864
- return _context6.stop();
865
763
  }
866
764
  }, _callee5);
867
765
  }));
@@ -873,26 +771,21 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
873
771
  });
874
772
  mapDocChain = RunnablePassthrough.assign({
875
773
  documents: function () {
876
- var _documents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
774
+ var _documents = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(input) {
877
775
  var textChunks;
878
- return _regeneratorRuntime().wrap(function _callee6$(_context7) {
879
- while (1) switch (_context7.prev = _context7.next) {
776
+ return _regenerator().w(function (_context7) {
777
+ while (1) switch (_context7.n) {
880
778
  case 0:
881
- _context7.next = 2;
779
+ _context7.n = 1;
882
780
  return _this3.textSplitter(input.input.context);
883
- case 2:
884
- textChunks = _context7.sent;
885
- return _context7.abrupt("return", Promise.all(textChunks.map(function (chunk) {
886
- return _this3.mapDoc.chain({
887
- input: {
888
- document: chunk,
889
- statements: input.input.expression
890
- }
781
+ case 1:
782
+ textChunks = _context7.v;
783
+ return _context7.a(2, Promise.all(textChunks.map(function (chunk) {
784
+ return mapDoc.chain({
785
+ document: chunk,
786
+ statements: input.input.expression
891
787
  });
892
788
  })));
893
- case 4:
894
- case "end":
895
- return _context7.stop();
896
789
  }
897
790
  }, _callee6);
898
791
  }));
@@ -904,10 +797,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
904
797
  });
905
798
  parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
906
799
  sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
907
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
800
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(results) {
908
801
  var expression, query, documents;
909
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
910
- while (1) switch (_context8.prev = _context8.next) {
802
+ return _regenerator().w(function (_context8) {
803
+ while (1) switch (_context8.n) {
911
804
  case 0:
912
805
  /* results is an array: [{ query: ... }, { documents: [...] }]
913
806
  {
@@ -933,15 +826,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
933
826
  expression = results[0].input.expression;
934
827
  query = results[0].query;
935
828
  documents = results[1].documents;
936
- return _context8.abrupt("return", _this3.reduceChain.chain({
937
- input: {
938
- facts: documents,
939
- query: query + ' ' + expression
940
- }
829
+ return _context8.a(2, reduceChain.chain({
830
+ facts: documents,
831
+ query: query + ' ' + expression
941
832
  }));
942
- case 5:
943
- case "end":
944
- return _context8.stop();
945
833
  }
946
834
  }, _callee7);
947
835
  }));
@@ -951,19 +839,42 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
951
839
  }()), function (result) {
952
840
  return _this3.stringToBoolean(result);
953
841
  }]);
954
- return _context9.abrupt("return", sequence.invoke(input));
955
- case 11:
956
- case "end":
957
- return _context9.stop();
842
+ return _context9.a(2, sequence.invoke(input));
958
843
  }
959
- }, _callee8);
844
+ }, _callee8, this);
960
845
  }));
961
846
  function chain(_x0) {
962
847
  return _chain.apply(this, arguments);
963
848
  }
964
849
  return chain;
965
850
  }();
966
- return LLMLoop;
851
+ return _createClass(LLMLoop, [{
852
+ key: "mapQueryTemplate",
853
+ get:
854
+ // Add getters and setters for the templates if needed
855
+ function get() {
856
+ return this._mapQueryTemplate;
857
+ },
858
+ set: function set(template) {
859
+ this._mapQueryTemplate = template;
860
+ }
861
+ }, {
862
+ key: "mapDocTemplate",
863
+ get: function get() {
864
+ return this._mapDocTemplate;
865
+ },
866
+ set: function set(template) {
867
+ this._mapDocTemplate = template;
868
+ }
869
+ }, {
870
+ key: "reduceChainTemplate",
871
+ get: function get() {
872
+ return this._reduceChainTemplate;
873
+ },
874
+ set: function set(template) {
875
+ this._reduceChainTemplate = template;
876
+ }
877
+ }]);
967
878
  }(BaseChain);
968
879
 
969
880
  exports.BaseAgent = BaseAgent;