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