medpromptjs 0.3.2 → 0.4.2

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;
104
- }
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
- }
110
+ }(r, o, i), !0), u;
117
111
  }
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
- });
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;
137
123
  }
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);
177
- }
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 () {
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 () {
211
125
  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 () {
219
- 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) {
@@ -495,19 +451,17 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
495
451
  schema: schema,
496
452
  func: func
497
453
  }) || this;
454
+ /** @hidden */
498
455
  _this.container = void 0;
499
456
  _this.name = void 0;
500
457
  _this.description = void 0;
501
458
  _this.schema = void 0;
502
459
  _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) {
460
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(args) {
461
+ return _regenerator().w(function (_context) {
462
+ while (1) switch (_context.n) {
506
463
  case 0:
507
- return _context.abrupt("return", 'override this');
508
- case 1:
509
- case "end":
510
- return _context.stop();
464
+ return _context.a(2, 'override this');
511
465
  }
512
466
  }, _callee);
513
467
  }));
@@ -535,57 +489,30 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
535
489
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
536
490
  return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
537
491
  }).replace(/\s+/g, '');
538
- };
539
- return BaseTool;
540
- }(DynamicStructuredTool);
541
-
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
492
  }
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];
493
+ /**
494
+ * @param input - The input to process in batch.
495
+ * @param config - The configuration for the batch.
496
+ * @returns A promise resolving to an array of results.
497
+ */;
498
+ _proto._batchWithConfig =
499
+ /*#__PURE__*/
500
+ function () {
501
+ var _batchWithConfig2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(input, config) {
502
+ return _regenerator().w(function (_context2) {
503
+ while (1) switch (_context2.n) {
504
+ case 0:
505
+ return _context2.a(2, _DynamicStructuredToo.prototype._batchWithConfig.call(this, input, config));
506
+ }
507
+ }, _callee2, this);
508
+ }));
509
+ function _batchWithConfig(_x2, _x3) {
510
+ return _batchWithConfig2.apply(this, arguments);
579
511
  }
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);
512
+ return _batchWithConfig;
513
+ }();
514
+ return BaseTool;
515
+ }(DynamicStructuredTool);
589
516
 
590
517
  var log = /*#__PURE__*/new Logger();
591
518
  var LLMLoop = /*#__PURE__*/function (_BaseChain) {
@@ -596,21 +523,19 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
596
523
  }
597
524
  _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
598
525
  // 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, '', '');
526
+ _this.stringExpression = '';
527
+ _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: ";
528
+ _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: ";
529
+ _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
530
  return _this;
606
531
  }
607
532
  _inheritsLoose(LLMLoop, _BaseChain);
608
533
  var _proto = LLMLoop.prototype;
609
534
  _proto.checkAssertion = /*#__PURE__*/function () {
610
- var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
535
+ var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(expression, context) {
611
536
  var _expression, _context, _content, _input, result;
612
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
613
- while (1) switch (_context2.prev = _context2.next) {
537
+ return _regenerator().w(function (_context2) {
538
+ while (1) switch (_context2.n) {
614
539
  case 0:
615
540
  _expression = '';
616
541
  try {
@@ -651,15 +576,12 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
651
576
  context: _content
652
577
  }
653
578
  };
654
- _context2.next = 12;
579
+ _context2.n = 1;
655
580
  return this.chain(_input);
656
- case 12:
657
- result = _context2.sent;
581
+ case 1:
582
+ result = _context2.v;
658
583
  log.info("Assertion check result: " + result);
659
- return _context2.abrupt("return", result);
660
- case 15:
661
- case "end":
662
- return _context2.stop();
584
+ return _context2.a(2, result);
663
585
  }
664
586
  }, _callee, this);
665
587
  }));
@@ -669,20 +591,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
669
591
  return checkAssertion;
670
592
  }();
671
593
  _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) {
594
+ var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(expression, context) {
595
+ return _regenerator().w(function (_context3) {
596
+ while (1) switch (_context3.n) {
675
597
  case 0:
676
598
  if (!(expression && context)) {
677
- _context3.next = 2;
599
+ _context3.n = 1;
678
600
  break;
679
601
  }
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();
602
+ return _context3.a(2, true);
603
+ case 1:
604
+ return _context3.a(2, false);
686
605
  }
687
606
  }, _callee2);
688
607
  }));
@@ -692,20 +611,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
692
611
  return checkMention;
693
612
  }();
694
613
  _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) {
614
+ var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(expression, context) {
615
+ return _regenerator().w(function (_context4) {
616
+ while (1) switch (_context4.n) {
698
617
  case 0:
699
618
  if (!(expression && context)) {
700
- _context4.next = 2;
619
+ _context4.n = 1;
701
620
  break;
702
621
  }
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();
622
+ return _context4.a(2, true);
623
+ case 1:
624
+ return _context4.a(2, false);
709
625
  }
710
626
  }, _callee3);
711
627
  }));
@@ -740,10 +656,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
740
656
  });
741
657
  };
742
658
  _proto.textSplitter = /*#__PURE__*/function () {
743
- var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text, chunkSize, chunkOverlap) {
659
+ var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(text, chunkSize, chunkOverlap) {
744
660
  var textSplitter, texts;
745
- return _regeneratorRuntime().wrap(function _callee4$(_context5) {
746
- while (1) switch (_context5.prev = _context5.next) {
661
+ return _regenerator().w(function (_context5) {
662
+ while (1) switch (_context5.n) {
747
663
  case 0:
748
664
  if (chunkSize === void 0) {
749
665
  chunkSize = 3900;
@@ -755,17 +671,17 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
755
671
  chunkSize: chunkSize,
756
672
  chunkOverlap: chunkOverlap
757
673
  });
758
- _context5.next = 5;
674
+ _context5.n = 1;
759
675
  return textSplitter.splitText(text);
760
- case 5:
761
- texts = _context5.sent;
676
+ case 1:
677
+ texts = _context5.v;
762
678
  if (!(texts.length === 0)) {
763
- _context5.next = 9;
679
+ _context5.n = 2;
764
680
  break;
765
681
  }
766
682
  log.warn('No text chunks created. Please check the input text.');
767
- return _context5.abrupt("return", []);
768
- case 9:
683
+ return _context5.a(2, []);
684
+ case 2:
769
685
  if (texts.length > 100) {
770
686
  log.warn("Warning: More than 100 text chunks created (" + texts.length + "). This may affect performance.");
771
687
  }
@@ -773,10 +689,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
773
689
  log.warn("Warning: Chunk size is less than 1000 characters (" + chunkSize + "). This may lead to very small chunks.");
774
690
  }
775
691
  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();
692
+ return _context5.a(2, texts);
780
693
  }
781
694
  }, _callee4);
782
695
  }));
@@ -819,45 +732,52 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
819
732
  if (typeof obj[key] === 'object') {
820
733
  this._printValues(obj[key]);
821
734
  } else {
822
- this.string_expression += obj[key] + ' ';
735
+ this.stringExpression += obj[key] + ' ';
823
736
  }
824
737
  }
825
738
  var _eliminate = ['true', 'false', 'null', 'undefined', 'String', 'Number', 'Object', 'Array', 'Boolean', 'value', 'Type', 'Specifier', 'Named'];
826
739
  _eliminate.forEach(function (element) {
827
740
  var regex = new RegExp(element, 'g');
828
- _this2.string_expression = _this2.string_expression.replace(regex, '');
741
+ _this2.stringExpression = _this2.stringExpression.replace(regex, '');
829
742
  });
830
- this.string_expression = this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
831
- return this.camelToString(this.string_expression);
743
+ this.stringExpression = this.stringExpression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
744
+ return this.camelToString(this.stringExpression);
832
745
  };
833
746
  _proto.chain = /*#__PURE__*/function () {
834
- var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(input) {
747
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(input) {
835
748
  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) {
749
+ var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQuery, mapDoc, reduceChain, mapQueryChain, mapDocChain, parallelChain, sequence;
750
+ return _regenerator().w(function (_context9) {
751
+ while (1) switch (_context9.n) {
839
752
  case 0:
840
- _context9.next = 2;
753
+ _context9.n = 1;
841
754
  return import('@langchain/core/runnables');
842
- case 2:
843
- _yield$import = _context9.sent;
755
+ case 1:
756
+ _yield$import = _context9.v;
844
757
  RunnableSequence = _yield$import.RunnableSequence;
845
758
  RunnableParallel = _yield$import.RunnableParallel;
846
759
  RunnablePassthrough = _yield$import.RunnablePassthrough;
760
+ mapQuery = new BaseChain(this.container);
761
+ mapDoc = new BaseChain(this.container);
762
+ reduceChain = new BaseChain(this.container);
763
+ mapQuery.name = 'MapQuery';
764
+ mapQuery.description = 'Map the expression to a natural language query.';
765
+ mapQuery.template = this._mapQueryTemplate;
766
+ mapDoc.name = 'MapDoc';
767
+ mapDoc.description = 'Map the document to a set of facts.';
768
+ mapDoc.template = this._mapDocTemplate;
769
+ reduceChain.name = 'ReduceChain';
770
+ reduceChain.description = 'Reduce a set of documents to binary answer.';
771
+ reduceChain.template = this._reduceChainTemplate;
847
772
  mapQueryChain = RunnablePassthrough.assign({
848
773
  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) {
774
+ var _query = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(input) {
775
+ return _regenerator().w(function (_context6) {
776
+ while (1) switch (_context6.n) {
852
777
  case 0:
853
- return _context6.abrupt("return", _this3.mapQuery.chain({
854
- input: {
855
- expression: input.input.expression
856
- }
778
+ return _context6.a(2, mapQuery.chain({
779
+ expression: input.input.expression
857
780
  }));
858
- case 1:
859
- case "end":
860
- return _context6.stop();
861
781
  }
862
782
  }, _callee5);
863
783
  }));
@@ -869,26 +789,21 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
869
789
  });
870
790
  mapDocChain = RunnablePassthrough.assign({
871
791
  documents: function () {
872
- var _documents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
792
+ var _documents = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(input) {
873
793
  var textChunks;
874
- return _regeneratorRuntime().wrap(function _callee6$(_context7) {
875
- while (1) switch (_context7.prev = _context7.next) {
794
+ return _regenerator().w(function (_context7) {
795
+ while (1) switch (_context7.n) {
876
796
  case 0:
877
- _context7.next = 2;
797
+ _context7.n = 1;
878
798
  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
- }
799
+ case 1:
800
+ textChunks = _context7.v;
801
+ return _context7.a(2, Promise.all(textChunks.map(function (chunk) {
802
+ return mapDoc.chain({
803
+ document: chunk,
804
+ statements: input.input.expression
887
805
  });
888
806
  })));
889
- case 4:
890
- case "end":
891
- return _context7.stop();
892
807
  }
893
808
  }, _callee6);
894
809
  }));
@@ -900,10 +815,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
900
815
  });
901
816
  parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
902
817
  sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
903
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
818
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(results) {
904
819
  var expression, query, documents;
905
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
906
- while (1) switch (_context8.prev = _context8.next) {
820
+ return _regenerator().w(function (_context8) {
821
+ while (1) switch (_context8.n) {
907
822
  case 0:
908
823
  /* results is an array: [{ query: ... }, { documents: [...] }]
909
824
  {
@@ -929,15 +844,10 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
929
844
  expression = results[0].input.expression;
930
845
  query = results[0].query;
931
846
  documents = results[1].documents;
932
- return _context8.abrupt("return", _this3.reduceChain.chain({
933
- input: {
934
- facts: documents,
935
- query: query + ' ' + expression
936
- }
847
+ return _context8.a(2, reduceChain.chain({
848
+ facts: documents,
849
+ query: query + ' ' + expression
937
850
  }));
938
- case 5:
939
- case "end":
940
- return _context8.stop();
941
851
  }
942
852
  }, _callee7);
943
853
  }));
@@ -947,19 +857,42 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
947
857
  }()), function (result) {
948
858
  return _this3.stringToBoolean(result);
949
859
  }]);
950
- return _context9.abrupt("return", sequence.invoke(input));
951
- case 11:
952
- case "end":
953
- return _context9.stop();
860
+ return _context9.a(2, sequence.invoke(input));
954
861
  }
955
- }, _callee8);
862
+ }, _callee8, this);
956
863
  }));
957
864
  function chain(_x0) {
958
865
  return _chain.apply(this, arguments);
959
866
  }
960
867
  return chain;
961
868
  }();
962
- return LLMLoop;
869
+ return _createClass(LLMLoop, [{
870
+ key: "mapQueryTemplate",
871
+ get:
872
+ // Add getters and setters for the templates if needed
873
+ function get() {
874
+ return this._mapQueryTemplate;
875
+ },
876
+ set: function set(template) {
877
+ this._mapQueryTemplate = template;
878
+ }
879
+ }, {
880
+ key: "mapDocTemplate",
881
+ get: function get() {
882
+ return this._mapDocTemplate;
883
+ },
884
+ set: function set(template) {
885
+ this._mapDocTemplate = template;
886
+ }
887
+ }, {
888
+ key: "reduceChainTemplate",
889
+ get: function get() {
890
+ return this._reduceChainTemplate;
891
+ },
892
+ set: function set(template) {
893
+ this._reduceChainTemplate = template;
894
+ }
895
+ }]);
963
896
  }(BaseChain);
964
897
 
965
898
  export { BaseAgent, BaseChain, BaseTool, LLMLoop };