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