medpromptjs 0.2.2 → 0.3.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.
@@ -4,87 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var prompts = require('@langchain/core/prompts');
6
6
  var runnables = require('@langchain/core/runnables');
7
+ var messages = require('@langchain/core/messages');
7
8
  var agents = require('langchain/agents');
8
9
  var tools = require('langchain/tools');
9
10
 
10
- /**
11
- * Copyright 2024 Bell Eapen
12
- *
13
- * Licensed under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License.
15
- * You may obtain a copy of the License at
16
- *
17
- * https://www.apache.org/licenses/LICENSE-2.0
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- var mydi = function mydi(c, m, b) {
26
- try {
27
- return c.resolve(m + "_" + b);
28
- } catch (e) {
29
- return c.resolve(b);
30
- }
31
- };
32
-
33
- /**
34
- * Copyright 2024 Bell Eapen
35
- *
36
- * Licensed under the Apache License, Version 2.0 (the "License");
37
- * you may not use this file except in compliance with the License.
38
- * You may obtain a copy of the License at
39
- *
40
- * https://www.apache.org/licenses/LICENSE-2.0
41
- *
42
- * Unless required by applicable law or agreed to in writing, software
43
- * distributed under the License is distributed on an "AS IS" BASIS,
44
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45
- * See the License for the specific language governing permissions and
46
- * limitations under the License.
47
- */
48
- var BaseChain = /*#__PURE__*/function () {
49
- function BaseChain(container, name, description, template) {
50
- this.container = void 0;
51
- this.tools = void 0;
52
- this.name = void 0;
53
- this.description = void 0;
54
- this.prompt = void 0;
55
- this.llm = void 0;
56
- this.template = "\n Summarize the following text:\n {input}\n ";
57
- this.container = container;
58
- this.name = name === "" ? this.camelize(this.constructor.name) : name;
59
- this.description = description === "" ? this.snake_case(this.constructor.name) : description;
60
- this.tools = this.resolve("tools");
61
- this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : prompts.PromptTemplate.fromTemplate(this.template);
62
- this.llm = this.resolve("main-llm");
63
- }
64
- var _proto = BaseChain.prototype;
65
- _proto.resolve = function resolve(name) {
66
- return mydi(this.container, this.name, name);
67
- };
68
- _proto.camelize = function camelize(str) {
69
- return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
70
- return index === 0 ? word.toLowerCase() : word.toUpperCase();
71
- }).replace(/\s+/g, '');
72
- };
73
- _proto.snake_case = function snake_case(str) {
74
- return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
75
- return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
76
- }).replace(/\s+/g, '');
77
- }
78
- // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/
79
- //! Override this method
80
- ;
81
- _proto.chain = function chain(input) {
82
- var _chain = runnables.RunnableSequence.from([new runnables.RunnablePassthrough(), this.prompt, this.llm]);
83
- return _chain.invoke(input);
84
- };
85
- return BaseChain;
86
- }();
87
-
88
11
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
89
12
  try {
90
13
  var i = n[a](c),
@@ -115,47 +38,77 @@ function _inheritsLoose(t, o) {
115
38
  }
116
39
  function _regeneratorRuntime() {
117
40
  _regeneratorRuntime = function () {
118
- return e;
41
+ return r;
119
42
  };
120
43
  var t,
121
- e = {},
122
- r = Object.prototype,
123
- n = r.hasOwnProperty,
124
- o = Object.defineProperty || function (t, e, r) {
125
- t[e] = r.value;
126
- },
127
- i = "function" == typeof Symbol ? Symbol : {},
128
- a = i.iterator || "@@iterator",
129
- c = i.asyncIterator || "@@asyncIterator",
130
- u = i.toStringTag || "@@toStringTag";
131
- function define(t, e, r) {
132
- return Object.defineProperty(t, e, {
133
- value: r,
134
- enumerable: !0,
135
- configurable: !0,
136
- writable: !0
137
- }), t[e];
44
+ r = {},
45
+ e = Object.prototype,
46
+ n = e.hasOwnProperty,
47
+ o = "function" == typeof Symbol ? Symbol : {},
48
+ i = o.iterator || "@@iterator",
49
+ a = o.asyncIterator || "@@asyncIterator",
50
+ u = o.toStringTag || "@@toStringTag";
51
+ function c(t, r, e, n) {
52
+ return Object.defineProperty(t, r, {
53
+ value: e,
54
+ enumerable: !n,
55
+ configurable: !n,
56
+ writable: !n
57
+ });
138
58
  }
139
59
  try {
140
- define({}, "");
60
+ c({}, "");
141
61
  } catch (t) {
142
- define = function (t, e, r) {
143
- return t[e] = r;
62
+ c = function (t, r, e) {
63
+ return t[r] = e;
144
64
  };
145
65
  }
146
- function wrap(t, e, r, n) {
66
+ function h(r, e, n, o) {
147
67
  var i = e && e.prototype instanceof Generator ? e : Generator,
148
- a = Object.create(i.prototype),
149
- c = new Context(n || []);
150
- return o(a, "_invoke", {
151
- value: makeInvokeMethod(t, r, c)
152
- }), a;
68
+ a = Object.create(i.prototype);
69
+ return c(a, "_invoke", function (r, e, n) {
70
+ var o = 1;
71
+ return function (i, a) {
72
+ if (3 === o) throw Error("Generator is already running");
73
+ if (4 === o) {
74
+ if ("throw" === i) throw a;
75
+ return {
76
+ value: t,
77
+ done: !0
78
+ };
79
+ }
80
+ for (n.method = i, n.arg = a;;) {
81
+ var u = n.delegate;
82
+ if (u) {
83
+ var c = d(u, n);
84
+ if (c) {
85
+ if (c === f) continue;
86
+ return c;
87
+ }
88
+ }
89
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
90
+ if (1 === o) throw o = 4, n.arg;
91
+ n.dispatchException(n.arg);
92
+ } else "return" === n.method && n.abrupt("return", n.arg);
93
+ o = 3;
94
+ var h = s(r, e, n);
95
+ if ("normal" === h.type) {
96
+ if (o = n.done ? 4 : 2, h.arg === f) continue;
97
+ return {
98
+ value: h.arg,
99
+ done: n.done
100
+ };
101
+ }
102
+ "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg);
103
+ }
104
+ };
105
+ }(r, n, new Context(o || [])), !0), a;
153
106
  }
154
- function tryCatch(t, e, r) {
107
+ function s(t, r, e) {
155
108
  try {
156
109
  return {
157
110
  type: "normal",
158
- arg: t.call(e, r)
111
+ arg: t.call(r, e)
159
112
  };
160
113
  } catch (t) {
161
114
  return {
@@ -164,255 +117,193 @@ function _regeneratorRuntime() {
164
117
  };
165
118
  }
166
119
  }
167
- e.wrap = wrap;
168
- var h = "suspendedStart",
169
- l = "suspendedYield",
170
- f = "executing",
171
- s = "completed",
172
- y = {};
120
+ r.wrap = h;
121
+ var f = {};
173
122
  function Generator() {}
174
123
  function GeneratorFunction() {}
175
124
  function GeneratorFunctionPrototype() {}
176
- var p = {};
177
- define(p, a, function () {
125
+ var l = {};
126
+ c(l, i, function () {
178
127
  return this;
179
128
  });
180
- var d = Object.getPrototypeOf,
181
- v = d && d(d(values([])));
182
- v && v !== r && n.call(v, a) && (p = v);
183
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
184
- function defineIteratorMethods(t) {
185
- ["next", "throw", "return"].forEach(function (e) {
186
- define(t, e, function (t) {
187
- return this._invoke(e, t);
129
+ var p = Object.getPrototypeOf,
130
+ y = p && p(p(x([])));
131
+ y && y !== e && n.call(y, i) && (l = y);
132
+ var v = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(l);
133
+ function g(t) {
134
+ ["next", "throw", "return"].forEach(function (r) {
135
+ c(t, r, function (t) {
136
+ return this._invoke(r, t);
188
137
  });
189
138
  });
190
139
  }
191
- function AsyncIterator(t, e) {
192
- function invoke(r, o, i, a) {
193
- var c = tryCatch(t[r], t, o);
140
+ function AsyncIterator(t, r) {
141
+ function e(o, i, a, u) {
142
+ var c = s(t[o], t, i);
194
143
  if ("throw" !== c.type) {
195
- var u = c.arg,
196
- h = u.value;
197
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
198
- invoke("next", t, i, a);
144
+ var h = c.arg,
145
+ f = h.value;
146
+ return f && "object" == typeof f && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) {
147
+ e("next", t, a, u);
199
148
  }, function (t) {
200
- invoke("throw", t, i, a);
201
- }) : e.resolve(h).then(function (t) {
202
- u.value = t, i(u);
149
+ e("throw", t, a, u);
150
+ }) : r.resolve(f).then(function (t) {
151
+ h.value = t, a(h);
203
152
  }, function (t) {
204
- return invoke("throw", t, i, a);
153
+ return e("throw", t, a, u);
205
154
  });
206
155
  }
207
- a(c.arg);
156
+ u(c.arg);
208
157
  }
209
- var r;
210
- o(this, "_invoke", {
211
- value: function (t, n) {
212
- function callInvokeWithMethodAndArg() {
213
- return new e(function (e, r) {
214
- invoke(t, n, e, r);
215
- });
216
- }
217
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
218
- }
219
- });
220
- }
221
- function makeInvokeMethod(e, r, n) {
222
- var o = h;
223
- return function (i, a) {
224
- if (o === f) throw Error("Generator is already running");
225
- if (o === s) {
226
- if ("throw" === i) throw a;
227
- return {
228
- value: t,
229
- done: !0
230
- };
231
- }
232
- for (n.method = i, n.arg = a;;) {
233
- var c = n.delegate;
234
- if (c) {
235
- var u = maybeInvokeDelegate(c, n);
236
- if (u) {
237
- if (u === y) continue;
238
- return u;
239
- }
240
- }
241
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
242
- if (o === h) throw o = s, n.arg;
243
- n.dispatchException(n.arg);
244
- } else "return" === n.method && n.abrupt("return", n.arg);
245
- o = f;
246
- var p = tryCatch(e, r, n);
247
- if ("normal" === p.type) {
248
- if (o = n.done ? s : l, p.arg === y) continue;
249
- return {
250
- value: p.arg,
251
- done: n.done
252
- };
253
- }
254
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
158
+ var o;
159
+ c(this, "_invoke", function (t, n) {
160
+ function i() {
161
+ return new r(function (r, o) {
162
+ e(t, n, r, o);
163
+ });
255
164
  }
256
- };
165
+ return o = o ? o.then(i, i) : i();
166
+ }, !0);
257
167
  }
258
- function maybeInvokeDelegate(e, r) {
259
- var n = r.method,
260
- o = e.iterator[n];
261
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
262
- var i = tryCatch(o, e.iterator, r.arg);
263
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
168
+ function d(r, e) {
169
+ var n = e.method,
170
+ o = r.i[n];
171
+ 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;
172
+ var i = s(o, r.i, e.arg);
173
+ if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f;
264
174
  var a = i.arg;
265
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
175
+ 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);
266
176
  }
267
- function pushTryEntry(t) {
268
- var e = {
269
- tryLoc: t[0]
270
- };
271
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
177
+ function w(t) {
178
+ this.tryEntries.push(t);
272
179
  }
273
- function resetTryEntry(t) {
274
- var e = t.completion || {};
275
- e.type = "normal", delete e.arg, t.completion = e;
180
+ function m(r) {
181
+ var e = r[4] || {};
182
+ e.type = "normal", e.arg = t, r[4] = e;
276
183
  }
277
184
  function Context(t) {
278
- this.tryEntries = [{
279
- tryLoc: "root"
280
- }], t.forEach(pushTryEntry, this), this.reset(!0);
185
+ this.tryEntries = [[-1]], t.forEach(w, this), this.reset(!0);
281
186
  }
282
- function values(e) {
283
- if (e || "" === e) {
284
- var r = e[a];
285
- if (r) return r.call(e);
286
- if ("function" == typeof e.next) return e;
287
- if (!isNaN(e.length)) {
187
+ function x(r) {
188
+ if (null != r) {
189
+ var e = r[i];
190
+ if (e) return e.call(r);
191
+ if ("function" == typeof r.next) return r;
192
+ if (!isNaN(r.length)) {
288
193
  var o = -1,
289
- i = function next() {
290
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
291
- return next.value = t, next.done = !0, next;
194
+ a = function e() {
195
+ for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e;
196
+ return e.value = t, e.done = !0, e;
292
197
  };
293
- return i.next = i;
198
+ return a.next = a;
294
199
  }
295
200
  }
296
- throw new TypeError(typeof e + " is not iterable");
201
+ throw new TypeError(typeof r + " is not iterable");
297
202
  }
298
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
299
- value: GeneratorFunctionPrototype,
300
- configurable: !0
301
- }), o(GeneratorFunctionPrototype, "constructor", {
302
- value: GeneratorFunction,
303
- configurable: !0
304
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
305
- var e = "function" == typeof t && t.constructor;
306
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
307
- }, e.mark = function (t) {
308
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
309
- }, e.awrap = function (t) {
203
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) {
204
+ var r = "function" == typeof t && t.constructor;
205
+ return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
206
+ }, r.mark = function (t) {
207
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = Object.create(v), t;
208
+ }, r.awrap = function (t) {
310
209
  return {
311
210
  __await: t
312
211
  };
313
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
212
+ }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () {
314
213
  return this;
315
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
214
+ }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) {
316
215
  void 0 === i && (i = Promise);
317
- var a = new AsyncIterator(wrap(t, r, n, o), i);
318
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
216
+ var a = new AsyncIterator(h(t, e, n, o), i);
217
+ return r.isGeneratorFunction(e) ? a : a.next().then(function (t) {
319
218
  return t.done ? t.value : a.next();
320
219
  });
321
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
220
+ }, g(v), c(v, u, "Generator"), c(v, i, function () {
322
221
  return this;
323
- }), define(g, "toString", function () {
222
+ }), c(v, "toString", function () {
324
223
  return "[object Generator]";
325
- }), e.keys = function (t) {
326
- var e = Object(t),
327
- r = [];
328
- for (var n in e) r.push(n);
329
- return r.reverse(), function next() {
330
- for (; r.length;) {
331
- var t = r.pop();
332
- if (t in e) return next.value = t, next.done = !1, next;
333
- }
334
- return next.done = !0, next;
224
+ }), r.keys = function (t) {
225
+ var r = Object(t),
226
+ e = [];
227
+ for (var n in r) e.unshift(n);
228
+ return function t() {
229
+ for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t;
230
+ return t.done = !0, t;
335
231
  };
336
- }, e.values = values, Context.prototype = {
232
+ }, r.values = x, Context.prototype = {
337
233
  constructor: Context,
338
- reset: function (e) {
339
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
234
+ reset: function (r) {
235
+ 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);
340
236
  },
341
237
  stop: function () {
342
238
  this.done = !0;
343
- var t = this.tryEntries[0].completion;
239
+ var t = this.tryEntries[0][4];
344
240
  if ("throw" === t.type) throw t.arg;
345
241
  return this.rval;
346
242
  },
347
- dispatchException: function (e) {
348
- if (this.done) throw e;
349
- var r = this;
350
- function handle(n, o) {
351
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
243
+ dispatchException: function (r) {
244
+ if (this.done) throw r;
245
+ var e = this;
246
+ function n(t) {
247
+ a.type = "throw", a.arg = r, e.next = t;
352
248
  }
353
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
249
+ for (var o = e.tryEntries.length - 1; o >= 0; --o) {
354
250
  var i = this.tryEntries[o],
355
- a = i.completion;
356
- if ("root" === i.tryLoc) return handle("end");
357
- if (i.tryLoc <= this.prev) {
358
- var c = n.call(i, "catchLoc"),
359
- u = n.call(i, "finallyLoc");
360
- if (c && u) {
361
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
362
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
363
- } else if (c) {
364
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
365
- } else {
366
- if (!u) throw Error("try statement without catch or finally");
367
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
368
- }
251
+ a = i[4],
252
+ u = this.prev,
253
+ c = i[1],
254
+ h = i[2];
255
+ if (-1 === i[0]) return n("end"), !1;
256
+ if (!c && !h) throw Error("try statement without catch or finally");
257
+ if (null != i[0] && i[0] <= u) {
258
+ if (u < c) return this.method = "next", this.arg = t, n(c), !0;
259
+ if (u < h) return n(h), !1;
369
260
  }
370
261
  }
371
262
  },
372
- abrupt: function (t, e) {
373
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
374
- var o = this.tryEntries[r];
375
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
376
- var i = o;
263
+ abrupt: function (t, r) {
264
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
265
+ var n = this.tryEntries[e];
266
+ if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) {
267
+ var o = n;
377
268
  break;
378
269
  }
379
270
  }
380
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
381
- var a = i ? i.completion : {};
382
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
271
+ o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null);
272
+ var i = o ? o[4] : {};
273
+ return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i);
383
274
  },
384
- complete: function (t, e) {
275
+ complete: function (t, r) {
385
276
  if ("throw" === t.type) throw t.arg;
386
- 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 && e && (this.next = e), y;
277
+ 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;
387
278
  },
388
279
  finish: function (t) {
389
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
390
- var r = this.tryEntries[e];
391
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
280
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
281
+ var e = this.tryEntries[r];
282
+ if (e[2] === t) return this.complete(e[4], e[3]), m(e), f;
392
283
  }
393
284
  },
394
285
  catch: function (t) {
395
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
396
- var r = this.tryEntries[e];
397
- if (r.tryLoc === t) {
398
- var n = r.completion;
286
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
287
+ var e = this.tryEntries[r];
288
+ if (e[0] === t) {
289
+ var n = e[4];
399
290
  if ("throw" === n.type) {
400
291
  var o = n.arg;
401
- resetTryEntry(r);
292
+ m(e);
402
293
  }
403
294
  return o;
404
295
  }
405
296
  }
406
297
  throw Error("illegal catch attempt");
407
298
  },
408
- delegateYield: function (e, r, n) {
299
+ delegateYield: function (r, e, n) {
409
300
  return this.delegate = {
410
- iterator: values(e),
411
- resultName: r,
412
- nextLoc: n
413
- }, "next" === this.method && (this.arg = t), y;
301
+ i: x(r),
302
+ r: e,
303
+ n: n
304
+ }, "next" === this.method && (this.arg = t), f;
414
305
  }
415
- }, e;
306
+ }, r;
416
307
  }
417
308
  function _setPrototypeOf(t, e) {
418
309
  return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
@@ -420,6 +311,114 @@ function _setPrototypeOf(t, e) {
420
311
  }, _setPrototypeOf(t, e);
421
312
  }
422
313
 
314
+ /**
315
+ * Copyright 2024 Bell Eapen
316
+ *
317
+ * Licensed under the Apache License, Version 2.0 (the "License");
318
+ * you may not use this file except in compliance with the License.
319
+ * You may obtain a copy of the License at
320
+ *
321
+ * https://www.apache.org/licenses/LICENSE-2.0
322
+ *
323
+ * Unless required by applicable law or agreed to in writing, software
324
+ * distributed under the License is distributed on an "AS IS" BASIS,
325
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
326
+ * See the License for the specific language governing permissions and
327
+ * limitations under the License.
328
+ */
329
+ var mydi = function mydi(c, m, b) {
330
+ try {
331
+ return c.resolve(m + '_' + b);
332
+ } catch (e) {
333
+ return c.resolve(b);
334
+ }
335
+ };
336
+
337
+ var BaseChain = /*#__PURE__*/function () {
338
+ function BaseChain(container, name, description, template) {
339
+ if (template === void 0) {
340
+ template = "\n Summarize the following text:\n {input}\n ";
341
+ }
342
+ this.container = void 0;
343
+ this.tools = void 0;
344
+ this.name = void 0;
345
+ this.description = void 0;
346
+ this.prompt = void 0;
347
+ this.llm = void 0;
348
+ this.template = void 0;
349
+ this.chat_model = void 0;
350
+ this.runnable = void 0;
351
+ this.container = container;
352
+ this.name = name === '' ? this.camelize(this.constructor.name) : name;
353
+ this.description = description === '' ? this.snake_case(this.constructor.name) : description;
354
+ this.template = template;
355
+ this.tools = this.resolve('tools');
356
+ this.llm = this.resolve('main-llm');
357
+ this.chat_model = false;
358
+ try {
359
+ this.chat_model = this.resolve('chat_model');
360
+ } catch (e) {}
361
+ if (this.chat_model) {
362
+ this.prompt = prompts.ChatPromptTemplate.fromTemplate(this.template);
363
+ } else {
364
+ this.prompt = prompts.PromptTemplate.fromTemplate(this.template);
365
+ }
366
+ }
367
+ var _proto = BaseChain.prototype;
368
+ _proto.resolve = function resolve(name) {
369
+ return mydi(this.container, this.name, name);
370
+ };
371
+ _proto.camelize = function camelize(str) {
372
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
373
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
374
+ }).replace(/\s+/g, '');
375
+ };
376
+ _proto.snake_case = function snake_case(str) {
377
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
378
+ return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
379
+ }).replace(/\s+/g, '');
380
+ }
381
+ // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/
382
+ //! Override this method
383
+ ;
384
+ _proto.chain =
385
+ /*#__PURE__*/
386
+ function () {
387
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
388
+ var response, aiMessage;
389
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
390
+ while (1) switch (_context.prev = _context.next) {
391
+ case 0:
392
+ this.runnable = runnables.RunnableSequence.from([new runnables.RunnablePassthrough(), this.prompt, this.llm]);
393
+ if (!this.chat_model) {
394
+ _context.next = 7;
395
+ break;
396
+ }
397
+ _context.next = 4;
398
+ return this.runnable.invoke(input);
399
+ case 4:
400
+ response = _context.sent;
401
+ aiMessage = new messages.AIMessage(response);
402
+ return _context.abrupt("return", aiMessage.content);
403
+ case 7:
404
+ _context.next = 9;
405
+ return this.runnable.invoke(input);
406
+ case 9:
407
+ return _context.abrupt("return", _context.sent);
408
+ case 10:
409
+ case "end":
410
+ return _context.stop();
411
+ }
412
+ }, _callee, this);
413
+ }));
414
+ function chain(_x) {
415
+ return _chain.apply(this, arguments);
416
+ }
417
+ return chain;
418
+ }();
419
+ return BaseChain;
420
+ }();
421
+
423
422
  var BaseAgent = /*#__PURE__*/function () {
424
423
  function BaseAgent(container) {
425
424
  this.container = void 0;
@@ -430,9 +429,9 @@ var BaseAgent = /*#__PURE__*/function () {
430
429
  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 ";
431
430
  this.container = container;
432
431
  this.name = this.camelize(this.constructor.name);
433
- this.tools = this.resolve("tools");
434
- this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : prompts.PromptTemplate.fromTemplate(this.template);
435
- this.llm = this.resolve("main-llm");
432
+ this.tools = this.resolve('tools');
433
+ this.prompt = this.resolve('prompt') !== '' ? this.resolve('prompt') : prompts.PromptTemplate.fromTemplate(this.template);
434
+ this.llm = this.resolve('main-llm');
436
435
  }
437
436
  var _proto = BaseAgent.prototype;
438
437
  _proto.resolve = function resolve(name) {
@@ -445,11 +444,11 @@ var BaseAgent = /*#__PURE__*/function () {
445
444
  };
446
445
  _proto.snake_case = function snake_case(str) {
447
446
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
448
- return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
447
+ return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
449
448
  }).replace(/\s+/g, '');
450
449
  };
451
450
  _proto.run = /*#__PURE__*/function () {
452
- var _run = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
451
+ var _run = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
453
452
  var agent, agentExecutor;
454
453
  return _regeneratorRuntime().wrap(function _callee$(_context) {
455
454
  while (1) switch (_context.prev = _context.next) {
@@ -466,7 +465,7 @@ var BaseAgent = /*#__PURE__*/function () {
466
465
  agent: agent,
467
466
  tools: this.tools,
468
467
  // verbose: true,
469
- handleParsingErrors: "Please try again, paying close attention to the final answer"
468
+ handleParsingErrors: 'Please try again, paying close attention to the final answer'
470
469
  });
471
470
  _context.next = 6;
472
471
  return agentExecutor.invoke(input);
@@ -503,11 +502,11 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
503
502
  _this.description = void 0;
504
503
  _this.schema = void 0;
505
504
  _this.func = /*#__PURE__*/function () {
506
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
505
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
507
506
  return _regeneratorRuntime().wrap(function _callee$(_context) {
508
507
  while (1) switch (_context.prev = _context.next) {
509
508
  case 0:
510
- return _context.abrupt("return", "override this");
509
+ return _context.abrupt("return", 'override this');
511
510
  case 1:
512
511
  case "end":
513
512
  return _context.stop();
@@ -519,8 +518,8 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
519
518
  };
520
519
  }();
521
520
  _this.container = container;
522
- _this.name = name === "" ? _this.camelize(_this.constructor.name) : name;
523
- _this.description = description === "" ? _this.snake_case(_this.constructor.name) : description;
521
+ _this.name = name === '' ? _this.camelize(_this.constructor.name) : name;
522
+ _this.description = description === '' ? _this.snake_case(_this.constructor.name) : description;
524
523
  _this.schema = schema;
525
524
  return _this;
526
525
  }
@@ -536,7 +535,7 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
536
535
  };
537
536
  _proto.snake_case = function snake_case(str) {
538
537
  return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
539
- return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
538
+ return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
540
539
  }).replace(/\s+/g, '');
541
540
  };
542
541
  return BaseTool;