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.
- package/dist/agent.d.ts +3 -3
- package/dist/chain.d.ts +6 -5
- package/dist/index.d.ts +1 -1
- package/dist/llm_loop/base.d.ts +21 -0
- package/dist/llm_loop/index.d.ts +1 -0
- package/dist/llm_loop/map_doc.d.ts +6 -0
- package/dist/llm_loop/map_query.d.ts +6 -0
- package/dist/llm_loop/reduce.d.ts +6 -0
- package/dist/medpromptjs.cjs.development.js +297 -298
- package/dist/medpromptjs.cjs.development.js.map +1 -1
- package/dist/medpromptjs.cjs.production.min.js +1 -1
- package/dist/medpromptjs.cjs.production.min.js.map +1 -1
- package/dist/medpromptjs.esm.js +298 -299
- package/dist/medpromptjs.esm.js.map +1 -1
- package/dist/tool.d.ts +1 -1
- package/package.json +14 -11
- package/src/agent.ts +59 -50
- package/src/chain.ts +74 -46
- package/src/index.ts +1 -1
- package/src/llm_loop/base.ts +200 -0
- package/src/llm_loop/index.ts +1 -0
- package/src/llm_loop/map_doc.ts +12 -0
- package/src/llm_loop/map_query.ts +36 -0
- package/src/llm_loop/reduce.ts +12 -0
- package/src/mydi.ts +8 -8
- package/src/tool.ts +46 -37
|
@@ -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
|
|
41
|
+
return r;
|
|
119
42
|
};
|
|
120
43
|
var t,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
n =
|
|
124
|
-
o =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
60
|
+
c({}, "");
|
|
141
61
|
} catch (t) {
|
|
142
|
-
|
|
143
|
-
return t[
|
|
62
|
+
c = function (t, r, e) {
|
|
63
|
+
return t[r] = e;
|
|
144
64
|
};
|
|
145
65
|
}
|
|
146
|
-
function
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
107
|
+
function s(t, r, e) {
|
|
155
108
|
try {
|
|
156
109
|
return {
|
|
157
110
|
type: "normal",
|
|
158
|
-
arg: t.call(
|
|
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
|
-
|
|
168
|
-
var
|
|
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
|
|
177
|
-
|
|
125
|
+
var l = {};
|
|
126
|
+
c(l, i, function () {
|
|
178
127
|
return this;
|
|
179
128
|
});
|
|
180
|
-
var
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var
|
|
184
|
-
function
|
|
185
|
-
["next", "throw", "return"].forEach(function (
|
|
186
|
-
|
|
187
|
-
return this._invoke(
|
|
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,
|
|
192
|
-
function
|
|
193
|
-
var c =
|
|
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
|
|
196
|
-
|
|
197
|
-
return
|
|
198
|
-
|
|
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
|
-
|
|
201
|
-
}) :
|
|
202
|
-
|
|
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
|
|
153
|
+
return e("throw", t, a, u);
|
|
205
154
|
});
|
|
206
155
|
}
|
|
207
|
-
|
|
156
|
+
u(c.arg);
|
|
208
157
|
}
|
|
209
|
-
var
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
function
|
|
213
|
-
|
|
214
|
-
|
|
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
|
|
259
|
-
var n =
|
|
260
|
-
o =
|
|
261
|
-
if (o === t) return
|
|
262
|
-
var i =
|
|
263
|
-
if ("throw" === i.type) return
|
|
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
|
|
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
|
|
268
|
-
|
|
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
|
|
274
|
-
var e =
|
|
275
|
-
e.type = "normal",
|
|
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
|
|
283
|
-
if (
|
|
284
|
-
var
|
|
285
|
-
if (
|
|
286
|
-
if ("function" == typeof
|
|
287
|
-
if (!isNaN(
|
|
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
|
-
|
|
290
|
-
for (; ++o <
|
|
291
|
-
return
|
|
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
|
|
198
|
+
return a.next = a;
|
|
294
199
|
}
|
|
295
200
|
}
|
|
296
|
-
throw new TypeError(typeof
|
|
201
|
+
throw new TypeError(typeof r + " is not iterable");
|
|
297
202
|
}
|
|
298
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
},
|
|
212
|
+
}, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () {
|
|
314
213
|
return this;
|
|
315
|
-
}),
|
|
214
|
+
}), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) {
|
|
316
215
|
void 0 === i && (i = Promise);
|
|
317
|
-
var a = new AsyncIterator(
|
|
318
|
-
return
|
|
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
|
-
},
|
|
220
|
+
}, g(v), c(v, u, "Generator"), c(v, i, function () {
|
|
322
221
|
return this;
|
|
323
|
-
}),
|
|
222
|
+
}), c(v, "toString", function () {
|
|
324
223
|
return "[object Generator]";
|
|
325
|
-
}),
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
for (var n in
|
|
329
|
-
return
|
|
330
|
-
for (;
|
|
331
|
-
|
|
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
|
-
},
|
|
232
|
+
}, r.values = x, Context.prototype = {
|
|
337
233
|
constructor: Context,
|
|
338
|
-
reset: function (
|
|
339
|
-
if (this.prev =
|
|
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]
|
|
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 (
|
|
348
|
-
if (this.done) throw
|
|
349
|
-
var
|
|
350
|
-
function
|
|
351
|
-
|
|
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 =
|
|
249
|
+
for (var o = e.tryEntries.length - 1; o >= 0; --o) {
|
|
354
250
|
var i = this.tryEntries[o],
|
|
355
|
-
a = i
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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,
|
|
373
|
-
for (var
|
|
374
|
-
var
|
|
375
|
-
if (
|
|
376
|
-
var
|
|
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
|
-
|
|
381
|
-
var
|
|
382
|
-
return
|
|
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,
|
|
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 &&
|
|
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
|
|
390
|
-
var
|
|
391
|
-
if (
|
|
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
|
|
396
|
-
var
|
|
397
|
-
if (
|
|
398
|
-
var n =
|
|
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
|
-
|
|
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 (
|
|
299
|
+
delegateYield: function (r, e, n) {
|
|
409
300
|
return this.delegate = {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}, "next" === this.method && (this.arg = t),
|
|
301
|
+
i: x(r),
|
|
302
|
+
r: e,
|
|
303
|
+
n: n
|
|
304
|
+
}, "next" === this.method && (this.arg = t), f;
|
|
414
305
|
}
|
|
415
|
-
},
|
|
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(
|
|
434
|
-
this.prompt = this.resolve(
|
|
435
|
-
this.llm = this.resolve(
|
|
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() :
|
|
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(
|
|
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:
|
|
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(
|
|
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",
|
|
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 ===
|
|
523
|
-
_this.description = 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() :
|
|
538
|
+
return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
|
|
540
539
|
}).replace(/\s+/g, '');
|
|
541
540
|
};
|
|
542
541
|
return BaseTool;
|