medpromptjs 0.1.1 → 0.2.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/README.md +3 -28
- package/dist/agent.d.ts +31 -0
- package/dist/chain.d.ts +32 -0
- package/dist/index.d.ts +3 -3
- package/dist/medpromptjs.cjs.development.js +215 -243
- 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 +214 -243
- package/dist/medpromptjs.esm.js.map +1 -1
- package/dist/mydi.d.ts +17 -0
- package/dist/tool.d.ts +27 -0
- package/package.json +2 -2
- package/src/agent.ts +79 -0
- package/src/chain.ts +72 -0
- package/src/index.ts +3 -5
- package/src/mydi.ts +25 -0
- package/src/tool.ts +59 -0
- package/dist/agents/explain_agent.d.ts +0 -6
- package/dist/agents/index.d.ts +0 -2
- package/dist/bootstrap.d.ts +0 -1
- package/dist/chains/index.d.ts +0 -2
- package/dist/chains/self_gen_cot_chain.d.ts +0 -26
- package/dist/server/index.d.ts +0 -3
- package/dist/server/sample_app.d.ts +0 -3
- package/dist/tools/find_patient.d.ts +0 -19
- package/dist/tools/index.d.ts +0 -2
- package/dist/utils/fhir_server.d.ts +0 -4
- package/dist/utils/get_medical_record.d.ts +0 -8
- package/dist/utils/hapi_server.d.ts +0 -5
- package/dist/utils/index.d.ts +0 -4
- package/src/agents/explain_agent.ts +0 -37
- package/src/agents/index.ts +0 -4
- package/src/bootstrap.ts +0 -17
- package/src/chains/index.ts +0 -2
- package/src/chains/self_gen_cot_chain.ts +0 -82
- package/src/server/index.ts +0 -5
- package/src/server/sample_app.js +0 -47
- package/src/server/sample_app.ts +0 -51
- package/src/tools/find_patient.ts +0 -51
- package/src/tools/index.ts +0 -4
- package/src/utils/fhir_server.ts +0 -11
- package/src/utils/get_medical_record.ts +0 -44
- package/src/utils/hapi_server.ts +0 -19
- package/src/utils/index.ts +0 -6
package/dist/medpromptjs.esm.js
CHANGED
|
@@ -1,12 +1,114 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { LLMChain } from 'langchain/chains';
|
|
6
|
-
import { PromptTemplate } from 'langchain/prompts';
|
|
7
|
-
import { pull } from 'langchain/hub';
|
|
8
|
-
import { AgentExecutor, createReactAgent } from 'langchain/agents';
|
|
1
|
+
import { PromptTemplate } from '@langchain/core/prompts';
|
|
2
|
+
import { RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables';
|
|
3
|
+
import { AgentExecutor, createStructuredChatAgent } from 'langchain/agents';
|
|
4
|
+
import { DynamicStructuredTool } from 'langchain/tools';
|
|
9
5
|
|
|
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
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
85
|
+
try {
|
|
86
|
+
var i = n[a](c),
|
|
87
|
+
u = i.value;
|
|
88
|
+
} catch (n) {
|
|
89
|
+
return void e(n);
|
|
90
|
+
}
|
|
91
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
92
|
+
}
|
|
93
|
+
function _asyncToGenerator(n) {
|
|
94
|
+
return function () {
|
|
95
|
+
var t = this,
|
|
96
|
+
e = arguments;
|
|
97
|
+
return new Promise(function (r, o) {
|
|
98
|
+
var a = n.apply(t, e);
|
|
99
|
+
function _next(n) {
|
|
100
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
101
|
+
}
|
|
102
|
+
function _throw(n) {
|
|
103
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
104
|
+
}
|
|
105
|
+
_next(void 0);
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function _inheritsLoose(t, o) {
|
|
110
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
111
|
+
}
|
|
10
112
|
function _regeneratorRuntime() {
|
|
11
113
|
_regeneratorRuntime = function () {
|
|
12
114
|
return e;
|
|
@@ -115,7 +217,7 @@ function _regeneratorRuntime() {
|
|
|
115
217
|
function makeInvokeMethod(e, r, n) {
|
|
116
218
|
var o = h;
|
|
117
219
|
return function (i, a) {
|
|
118
|
-
if (o === f) throw
|
|
220
|
+
if (o === f) throw Error("Generator is already running");
|
|
119
221
|
if (o === s) {
|
|
120
222
|
if ("throw" === i) throw a;
|
|
121
223
|
return {
|
|
@@ -257,7 +359,7 @@ function _regeneratorRuntime() {
|
|
|
257
359
|
} else if (c) {
|
|
258
360
|
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
259
361
|
} else {
|
|
260
|
-
if (!u) throw
|
|
362
|
+
if (!u) throw Error("try statement without catch or finally");
|
|
261
363
|
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
262
364
|
}
|
|
263
365
|
}
|
|
@@ -297,7 +399,7 @@ function _regeneratorRuntime() {
|
|
|
297
399
|
return o;
|
|
298
400
|
}
|
|
299
401
|
}
|
|
300
|
-
throw
|
|
402
|
+
throw Error("illegal catch attempt");
|
|
301
403
|
},
|
|
302
404
|
delegateYield: function (e, r, n) {
|
|
303
405
|
return this.delegate = {
|
|
@@ -308,252 +410,65 @@ function _regeneratorRuntime() {
|
|
|
308
410
|
}
|
|
309
411
|
}, e;
|
|
310
412
|
}
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
var i = e.call(t, r || "default");
|
|
316
|
-
if ("object" != typeof i) return i;
|
|
317
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
318
|
-
}
|
|
319
|
-
return ("string" === r ? String : Number)(t);
|
|
320
|
-
}
|
|
321
|
-
function _toPropertyKey(t) {
|
|
322
|
-
var i = _toPrimitive(t, "string");
|
|
323
|
-
return "symbol" == typeof i ? i : String(i);
|
|
413
|
+
function _setPrototypeOf(t, e) {
|
|
414
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
415
|
+
return t.__proto__ = e, t;
|
|
416
|
+
}, _setPrototypeOf(t, e);
|
|
324
417
|
}
|
|
325
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
326
|
-
try {
|
|
327
|
-
var info = gen[key](arg);
|
|
328
|
-
var value = info.value;
|
|
329
|
-
} catch (error) {
|
|
330
|
-
reject(error);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
if (info.done) {
|
|
334
|
-
resolve(value);
|
|
335
|
-
} else {
|
|
336
|
-
Promise.resolve(value).then(_next, _throw);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function _asyncToGenerator(fn) {
|
|
340
|
-
return function () {
|
|
341
|
-
var self = this,
|
|
342
|
-
args = arguments;
|
|
343
|
-
return new Promise(function (resolve, reject) {
|
|
344
|
-
var gen = fn.apply(self, args);
|
|
345
|
-
function _next(value) {
|
|
346
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
347
|
-
}
|
|
348
|
-
function _throw(err) {
|
|
349
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
350
|
-
}
|
|
351
|
-
_next(undefined);
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function _defineProperties(target, props) {
|
|
356
|
-
for (var i = 0; i < props.length; i++) {
|
|
357
|
-
var descriptor = props[i];
|
|
358
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
359
|
-
descriptor.configurable = true;
|
|
360
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
361
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
365
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
366
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
367
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
368
|
-
writable: false
|
|
369
|
-
});
|
|
370
|
-
return Constructor;
|
|
371
|
-
}
|
|
372
|
-
function _inheritsLoose(subClass, superClass) {
|
|
373
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
374
|
-
subClass.prototype.constructor = subClass;
|
|
375
|
-
_setPrototypeOf(subClass, superClass);
|
|
376
|
-
}
|
|
377
|
-
function _setPrototypeOf(o, p) {
|
|
378
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
379
|
-
o.__proto__ = p;
|
|
380
|
-
return o;
|
|
381
|
-
};
|
|
382
|
-
return _setPrototypeOf(o, p);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
var FhirServer = function FhirServer() {
|
|
386
|
-
this.baseUrl = void 0;
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
var logger = /*#__PURE__*/new Logger({
|
|
390
|
-
name: "MedpromptLogger"
|
|
391
|
-
});
|
|
392
|
-
var HapiFhirServer = /*#__PURE__*/function (_FhirServer) {
|
|
393
|
-
_inheritsLoose(HapiFhirServer, _FhirServer);
|
|
394
|
-
function HapiFhirServer() {
|
|
395
|
-
var _this;
|
|
396
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
397
|
-
args[_key] = arguments[_key];
|
|
398
|
-
}
|
|
399
|
-
_this = _FhirServer.call.apply(_FhirServer, [this].concat(args)) || this;
|
|
400
|
-
_this.baseUrl = 'http://hapi.fhir.org/baseR4/';
|
|
401
|
-
return _this;
|
|
402
|
-
}
|
|
403
|
-
var _proto = HapiFhirServer.prototype;
|
|
404
|
-
_proto.call_fhir_server = /*#__PURE__*/function () {
|
|
405
|
-
var _call_fhir_server = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, params) {
|
|
406
|
-
var _url_with_params, response, data;
|
|
407
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
408
|
-
while (1) switch (_context.prev = _context.next) {
|
|
409
|
-
case 0:
|
|
410
|
-
_url_with_params = "" + this.baseUrl + url + params;
|
|
411
|
-
logger.info("url_with_params: " + _url_with_params);
|
|
412
|
-
_context.next = 4;
|
|
413
|
-
return fetch(_url_with_params);
|
|
414
|
-
case 4:
|
|
415
|
-
response = _context.sent;
|
|
416
|
-
_context.next = 7;
|
|
417
|
-
return response.json();
|
|
418
|
-
case 7:
|
|
419
|
-
data = _context.sent;
|
|
420
|
-
return _context.abrupt("return", data);
|
|
421
|
-
case 9:
|
|
422
|
-
case "end":
|
|
423
|
-
return _context.stop();
|
|
424
|
-
}
|
|
425
|
-
}, _callee, this);
|
|
426
|
-
}));
|
|
427
|
-
function call_fhir_server(_x, _x2) {
|
|
428
|
-
return _call_fhir_server.apply(this, arguments);
|
|
429
|
-
}
|
|
430
|
-
return call_fhir_server;
|
|
431
|
-
}();
|
|
432
|
-
return HapiFhirServer;
|
|
433
|
-
}(FhirServer);
|
|
434
|
-
|
|
435
|
-
var google_vertex_ai = /*#__PURE__*/new GoogleVertexAI({
|
|
436
|
-
model: "text-bison",
|
|
437
|
-
temperature: 0.2
|
|
438
|
-
});
|
|
439
|
-
container.register("main-llm", {
|
|
440
|
-
useValue: google_vertex_ai
|
|
441
|
-
});
|
|
442
|
-
container.register("FhirServer", {
|
|
443
|
-
useClass: HapiFhirServer
|
|
444
|
-
});
|
|
445
418
|
|
|
446
|
-
var
|
|
447
|
-
function
|
|
448
|
-
this.
|
|
449
|
-
this.
|
|
450
|
-
this.
|
|
419
|
+
var BaseAgent = /*#__PURE__*/function () {
|
|
420
|
+
function BaseAgent(container) {
|
|
421
|
+
this.container = void 0;
|
|
422
|
+
this.tools = void 0;
|
|
423
|
+
this.name = void 0;
|
|
424
|
+
this.prompt = void 0;
|
|
425
|
+
this.llm = void 0;
|
|
451
426
|
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 ";
|
|
452
|
-
this.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
this.
|
|
457
|
-
llm: this.llm,
|
|
458
|
-
prompt: this.promptTemplate,
|
|
459
|
-
outputKey: "explanation"
|
|
460
|
-
});
|
|
461
|
-
if (llm) this.llm = llm;
|
|
462
|
-
if (name) this.name = name;
|
|
463
|
-
if (template) this.template = template;
|
|
464
|
-
if (description) this.description = description;
|
|
427
|
+
this.container = container;
|
|
428
|
+
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");
|
|
465
432
|
}
|
|
466
|
-
var _proto =
|
|
467
|
-
_proto.
|
|
468
|
-
|
|
469
|
-
var chainExecutionResult;
|
|
470
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
471
|
-
while (1) switch (_context.prev = _context.next) {
|
|
472
|
-
case 0:
|
|
473
|
-
_context.next = 2;
|
|
474
|
-
return this.chain.call(args);
|
|
475
|
-
case 2:
|
|
476
|
-
chainExecutionResult = _context.sent;
|
|
477
|
-
return _context.abrupt("return", chainExecutionResult);
|
|
478
|
-
case 4:
|
|
479
|
-
case "end":
|
|
480
|
-
return _context.stop();
|
|
481
|
-
}
|
|
482
|
-
}, _callee, this);
|
|
483
|
-
}));
|
|
484
|
-
function call(_x) {
|
|
485
|
-
return _call2.apply(this, arguments);
|
|
486
|
-
}
|
|
487
|
-
return call;
|
|
488
|
-
}();
|
|
489
|
-
_proto._call = function _call(values, runManager) {
|
|
490
|
-
throw new Error("Method not implemented.");
|
|
433
|
+
var _proto = BaseAgent.prototype;
|
|
434
|
+
_proto.resolve = function resolve(name) {
|
|
435
|
+
return mydi(this.container, this.name, name);
|
|
491
436
|
};
|
|
492
|
-
_proto.
|
|
493
|
-
return
|
|
437
|
+
_proto.camelize = function camelize(str) {
|
|
438
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
439
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
440
|
+
}).replace(/\s+/g, '');
|
|
494
441
|
};
|
|
495
|
-
_proto.
|
|
496
|
-
return
|
|
442
|
+
_proto.snake_case = function snake_case(str) {
|
|
443
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
444
|
+
return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
|
|
445
|
+
}).replace(/\s+/g, '');
|
|
497
446
|
};
|
|
498
|
-
_proto.getTemplate = function getTemplate() {
|
|
499
|
-
return this.template;
|
|
500
|
-
};
|
|
501
|
-
_proto.getDescription = function getDescription() {
|
|
502
|
-
return this.description;
|
|
503
|
-
};
|
|
504
|
-
_createClass(SelfGenCotChain, [{
|
|
505
|
-
key: "inputKeys",
|
|
506
|
-
get: function get() {
|
|
507
|
-
return ["question", "answer"];
|
|
508
|
-
}
|
|
509
|
-
}, {
|
|
510
|
-
key: "outputKeys",
|
|
511
|
-
get: function get() {
|
|
512
|
-
return ["explanation"];
|
|
513
|
-
}
|
|
514
|
-
}]);
|
|
515
|
-
return SelfGenCotChain;
|
|
516
|
-
}();
|
|
517
|
-
|
|
518
|
-
var ExplainAgent = /*#__PURE__*/function () {
|
|
519
|
-
function ExplainAgent(tools) {
|
|
520
|
-
if (tools === void 0) {
|
|
521
|
-
tools = [new SelfGenCotChain()];
|
|
522
|
-
}
|
|
523
|
-
this.tools = void 0;
|
|
524
|
-
this.tools = tools;
|
|
525
|
-
}
|
|
526
|
-
var _proto = ExplainAgent.prototype;
|
|
527
447
|
_proto.run = /*#__PURE__*/function () {
|
|
528
448
|
var _run = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
529
|
-
var
|
|
449
|
+
var agent, agentExecutor;
|
|
530
450
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
531
451
|
while (1) switch (_context.prev = _context.next) {
|
|
532
452
|
case 0:
|
|
533
453
|
_context.next = 2;
|
|
534
|
-
return
|
|
454
|
+
return createStructuredChatAgent({
|
|
455
|
+
llm: this.llm,
|
|
456
|
+
tools: this.tools,
|
|
457
|
+
prompt: this.prompt
|
|
458
|
+
});
|
|
535
459
|
case 2:
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
tools: tools,
|
|
543
|
-
prompt: promptWithChat
|
|
460
|
+
agent = _context.sent;
|
|
461
|
+
agentExecutor = new AgentExecutor({
|
|
462
|
+
agent: agent,
|
|
463
|
+
tools: this.tools,
|
|
464
|
+
// verbose: true,
|
|
465
|
+
handleParsingErrors: "Please try again, paying close attention to the final answer"
|
|
544
466
|
});
|
|
467
|
+
_context.next = 6;
|
|
468
|
+
return agentExecutor.invoke(input);
|
|
469
|
+
case 6:
|
|
470
|
+
return _context.abrupt("return", _context.sent);
|
|
545
471
|
case 7:
|
|
546
|
-
agentWithChat = _context.sent;
|
|
547
|
-
agentExecutorWithChat = new AgentExecutor({
|
|
548
|
-
agent: agentWithChat,
|
|
549
|
-
tools: tools
|
|
550
|
-
});
|
|
551
|
-
_context.next = 11;
|
|
552
|
-
return agentExecutorWithChat.invoke(input);
|
|
553
|
-
case 11:
|
|
554
|
-
result2 = _context.sent;
|
|
555
|
-
return _context.abrupt("return", result2);
|
|
556
|
-
case 13:
|
|
557
472
|
case "end":
|
|
558
473
|
return _context.stop();
|
|
559
474
|
}
|
|
@@ -564,8 +479,64 @@ var ExplainAgent = /*#__PURE__*/function () {
|
|
|
564
479
|
}
|
|
565
480
|
return run;
|
|
566
481
|
}();
|
|
567
|
-
return
|
|
482
|
+
return BaseAgent;
|
|
568
483
|
}();
|
|
569
484
|
|
|
570
|
-
|
|
485
|
+
var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
|
|
486
|
+
function BaseTool(container, name, description, schema, func) {
|
|
487
|
+
var _this;
|
|
488
|
+
if (func === void 0) {
|
|
489
|
+
func = null;
|
|
490
|
+
}
|
|
491
|
+
_this = _DynamicStructuredToo.call(this, {
|
|
492
|
+
name: name,
|
|
493
|
+
description: description,
|
|
494
|
+
schema: schema,
|
|
495
|
+
func: func
|
|
496
|
+
}) || this;
|
|
497
|
+
_this.container = void 0;
|
|
498
|
+
_this.name = void 0;
|
|
499
|
+
_this.description = void 0;
|
|
500
|
+
_this.schema = void 0;
|
|
501
|
+
_this.func = /*#__PURE__*/function () {
|
|
502
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
|
|
503
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
504
|
+
while (1) switch (_context.prev = _context.next) {
|
|
505
|
+
case 0:
|
|
506
|
+
return _context.abrupt("return", "override this");
|
|
507
|
+
case 1:
|
|
508
|
+
case "end":
|
|
509
|
+
return _context.stop();
|
|
510
|
+
}
|
|
511
|
+
}, _callee);
|
|
512
|
+
}));
|
|
513
|
+
return function (_x) {
|
|
514
|
+
return _ref.apply(this, arguments);
|
|
515
|
+
};
|
|
516
|
+
}();
|
|
517
|
+
_this.container = container;
|
|
518
|
+
_this.name = name === "" ? _this.camelize(_this.constructor.name) : name;
|
|
519
|
+
_this.description = description === "" ? _this.snake_case(_this.constructor.name) : description;
|
|
520
|
+
_this.schema = schema;
|
|
521
|
+
return _this;
|
|
522
|
+
}
|
|
523
|
+
_inheritsLoose(BaseTool, _DynamicStructuredToo);
|
|
524
|
+
var _proto = BaseTool.prototype;
|
|
525
|
+
_proto.resolve = function resolve(name) {
|
|
526
|
+
return mydi(this.container, this.name, name);
|
|
527
|
+
};
|
|
528
|
+
_proto.camelize = function camelize(str) {
|
|
529
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
530
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
531
|
+
}).replace(/\s+/g, '');
|
|
532
|
+
};
|
|
533
|
+
_proto.snake_case = function snake_case(str) {
|
|
534
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
535
|
+
return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
|
|
536
|
+
}).replace(/\s+/g, '');
|
|
537
|
+
};
|
|
538
|
+
return BaseTool;
|
|
539
|
+
}(DynamicStructuredTool);
|
|
540
|
+
|
|
541
|
+
export { BaseAgent, BaseChain, BaseTool };
|
|
571
542
|
//# sourceMappingURL=medpromptjs.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"medpromptjs.esm.js","sources":["../src/utils/fhir_server.ts","../src/utils/hapi_server.ts","../src/bootstrap.ts","../src/chains/self_gen_cot_chain.ts","../src/agents/explain_agent.ts"],"sourcesContent":["\nexport abstract class FhirServer {\n\n baseUrl: string | undefined;\n\n abstract call_fhir_server(\n url: string,\n params: string,\n ): Promise<any>;\n}\n\n","import { FhirServer } from \"./fhir_server\";\nimport { Logger } from \"tslog\";\n\nconst logger = new Logger({ name: \"MedpromptLogger\" });\n\nexport class HapiFhirServer extends FhirServer {\n\n baseUrl: string = 'http://hapi.fhir.org/baseR4/';\n\n async call_fhir_server(url: string, params: string) {\n const _url_with_params = `${this.baseUrl}${url}${params}`\n logger.info(`url_with_params: ${_url_with_params}`)\n const response = await fetch(\n _url_with_params,\n );\n const data = await response.json();\n return data;\n }\n}","import \"reflect-metadata\";\nimport { HapiFhirServer } from \"./utils/hapi_server\";\nimport { container } from \"tsyringe\";\nimport { GoogleVertexAI } from \"langchain/llms/googlevertexai\";\n\nconst google_vertex_ai = new GoogleVertexAI({\n model: \"text-bison\",\n temperature: 0.2,\n});\n\ncontainer.register(\"main-llm\", {\n useValue: google_vertex_ai,\n});\n\ncontainer.register(\"FhirServer\", {\n useClass: HapiFhirServer,\n});\n","import \"../bootstrap\";\nimport { SequentialChain, LLMChain, BaseChain } from \"langchain/chains\";\nimport { container } from \"tsyringe\";\nimport { PromptTemplate } from \"langchain/prompts\";\nimport { LLM } from \"langchain/llms/base\";\nimport { BaseCache, ChainValues } from \"langchain/dist/schema\";\nimport { CallbackManagerForChainRun } from \"langchain/dist/callbacks\";\n\n\nexport class SelfGenCotChain {\n\n private llm: LLM = container.resolve(\"main-llm\");\n name: string = \"self generated explanation\";\n description: string = \"Generate a chain of thought explanation for the answer to a question.\";\n private template: string = `\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 `;\n\n constructor(\n llm?: LLM,\n name?: string,\n template?: string,\n description?: string,\n ) {\n if (llm)\n this.llm = llm;\n if (name)\n this.name = name;\n if (template)\n this.template = template;\n if (description)\n this.description = description;\n }\n\n promptTemplate: PromptTemplate = new PromptTemplate({\n template: this.template,\n inputVariables: [\"question\", \"answer\"],\n });\n\n chain: LLMChain = new LLMChain({\n llm: this.llm,\n prompt: this.promptTemplate,\n outputKey: \"explanation\",\n });\n\n async call(args: { question: string, answer: string }) {\n const chainExecutionResult = await this.chain.call(args);\n return chainExecutionResult;\n }\n\n _call(values: ChainValues, runManager?: CallbackManagerForChainRun | undefined): Promise<ChainValues> {\n throw new Error(\"Method not implemented.\");\n }\n _chainType(): string {\n return \"self_gen_cot_chain\";\n }\n get inputKeys(): string[] {\n return [\"question\", \"answer\"];\n }\n get outputKeys(): string[] {\n return [\"explanation\"];\n }\n\n public getName() {\n return this.name;\n }\n\n public getTemplate() {\n return this.template;\n }\n\n public getDescription() {\n return this.description;\n }\n\n}\n\n","import \"../bootstrap\";\nimport { SelfGenCotChain } from \"../chains/self_gen_cot_chain\";\nimport { pull } from \"langchain/hub\";\nimport type { PromptTemplate } from \"@langchain/core/prompts\";\nimport { SequentialChain, LLMChain } from \"langchain/chains\";\nimport { container } from \"tsyringe\";\nimport { LLM } from \"langchain/llms/base\";\nimport { AgentExecutor, createReactAgent } from \"langchain/agents\";\nimport { Tool } from \"langchain/tools\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\n\nexport class ExplainAgent {\n\n tools: any[];\n\n constructor(tools: any[] = [new SelfGenCotChain()]) {\n this.tools = tools;\n }\n\n\n async run(input: any){\n const promptWithChat = await pull<PromptTemplate>(\"hwchase17/react-chat\");\n const llm: LLM = container.resolve(\"main-llm\");\n const tools: ToolInterface[] = this.tools;\n const agentWithChat = await createReactAgent({\n llm,\n tools,\n prompt: promptWithChat,\n });\n const agentExecutorWithChat = new AgentExecutor({\n agent: agentWithChat,\n tools,\n });\n const result2 = await agentExecutorWithChat.invoke(input);\n return result2;\n }\n}"],"names":["FhirServer","baseUrl","logger","Logger","name","HapiFhirServer","_FhirServer","_inheritsLoose","_this","_len","arguments","length","args","Array","_key","call","apply","concat","_proto","prototype","call_fhir_server","_call_fhir_server","_asyncToGenerator","_regeneratorRuntime","mark","_callee","url","params","_url_with_params","response","data","wrap","_callee$","_context","prev","next","info","fetch","sent","json","abrupt","stop","_x","_x2","google_vertex_ai","GoogleVertexAI","model","temperature","container","register","useValue","useClass","SelfGenCotChain","llm","template","description","resolve","promptTemplate","PromptTemplate","inputVariables","chain","LLMChain","prompt","outputKey","_call2","chainExecutionResult","_call","values","runManager","Error","_chainType","getName","getTemplate","getDescription","_createClass","key","get","ExplainAgent","tools","run","_run","input","promptWithChat","agentWithChat","agentExecutorWithChat","result2","pull","createReactAgent","AgentExecutor","agent","invoke"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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GAAA,EAAA,CAAA;AAAA,YAAA,OACoBiD,qBAAqB,CAACM,MAAM,CAACT,KAAK,CAAC,CAAA;AAAA,UAAA,KAAA,EAAA;YAAnDI,OAAO,GAAApD,QAAA,CAAAK,IAAA,CAAA;AAAA,YAAA,OAAAL,QAAA,CAAAO,MAAA,CAAA,QAAA,EACN6C,OAAO,CAAA,CAAA;AAAA,UAAA,KAAA,EAAA,CAAA;AAAA,UAAA,KAAA,KAAA;YAAA,OAAApD,QAAA,CAAAQ,IAAA,EAAA,CAAA;AAAA,SAAA;AAAA,OAAA,EAAAhB,OAAA,EAAA,IAAA,CAAA,CAAA;KACjB,CAAA,CAAA,CAAA;AAAA,IAAA,SAAAsD,IAAArC,EAAA,EAAA;AAAA,MAAA,OAAAsC,IAAA,CAAAhE,KAAA,CAAA,IAAA,EAAAN,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAAAqE,GAAA,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAAF,YAAA,CAAA;AAAA,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"medpromptjs.esm.js","sources":["../src/mydi.ts","../src/chain.ts","../src/agent.ts","../src/tool.ts"],"sourcesContent":["/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mydi = (c:any, m:string, b:string) => {\n try {\n return c.resolve(m+\"_\"+b);\n } catch (e) {\n return c.resolve(b);\n }\n}\n\nexport default mydi;","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { LLM } from \"langchain/llms/base\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport mydi from \"./mydi\";\nimport { RunnablePassthrough, RunnableSequence } from \"@langchain/core/runnables\";\n\nexport class BaseChain {\n\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n Summarize the following text:\n {input}\n `\n\n constructor(container: any, name: string, description: string, template: string=\"\") {\n this.container = container;\n this.name = name === \"\" ? this.camelize(this.constructor.name) : name;\n this.description = description === \"\" ? this.snake_case(this.constructor.name) : description;\n this.tools = this.resolve(\"tools\")\n this.prompt = this.resolve(\"prompt\") !== \"\" ? this.resolve(\"prompt\") : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve(\"main-llm\");\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n chain(input: any) {\n const _chain = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm\n ])\n return _chain.invoke(input);\n }\n}","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from \"@langchain/core/prompts\";\nimport { LLM } from \"langchain/llms/base\";\nimport { AgentExecutor, createReactAgent, createStructuredChatAgent } from \"langchain/agents\";\nimport type { ToolInterface } from \"@langchain/core/tools\";\nimport mydi from \"./mydi\";\n\nexport class BaseAgent {\n\n container: any;\n tools: ToolInterface[];\n name: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\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 `\n\n constructor(container: any) {\n this.container = container;\n this.name = this.camelize(this.constructor.name);\n this.tools = this.resolve(\"tools\")\n this.prompt = this.resolve(\"prompt\") !== \"\" ? this.resolve(\"prompt\") : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve(\"main-llm\");\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n async run(input: any) {\n const agent = await createStructuredChatAgent({\n llm: this.llm,\n tools: this.tools,\n prompt: this.prompt,\n });\n const agentExecutor = new AgentExecutor({\n agent: agent,\n tools: this.tools,\n // verbose: true,\n handleParsingErrors:\n \"Please try again, paying close attention to the final answer\",\n });\n return await agentExecutor.invoke(input);\n }\n\n}","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DynamicStructuredTool } from \"langchain/tools\";\nimport mydi from \"./mydi\";\n\nexport class BaseTool extends DynamicStructuredTool {\n\n container: any;\n name: string;\n description: string;\n schema: any;\n constructor(container: any, name: string, description: string, schema: any, func: any = null) {\n super({\n name: name,\n description: description,\n schema: schema,\n func: func\n });\n this.container = container;\n this.name = name === \"\" ? this.camelize(this.constructor.name) : name;\n this.description = description === \"\" ? this.snake_case(this.constructor.name) : description;\n this.schema = schema;\n }\n\n func = async (args: any) => {\n return \"override this\";\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n }).replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str.replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function(word, index) {\n return index === 0 ? word.toLowerCase() : \"_\" + word.toLowerCase();\n }).replace(/\\s+/g, '');\n }\n\n}"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","camelize","constructor","snake_case","PromptTemplate","fromTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","input","_chain","RunnableSequence","from","RunnablePassthrough","invoke","BaseAgent","run","_run","_asyncToGenerator","_regeneratorRuntime","mark","_callee","agent","agentExecutor","wrap","_callee$","_context","prev","next","createStructuredChatAgent","sent","AgentExecutor","handleParsingErrors","abrupt","stop","_x","apply","arguments","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool"],"mappings":";;;;;AAAA;;;;;;;;;;;;;;AAcG;AAEH,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAIC,CAAK,EAAEC,CAAQ,EAAEC,CAAQ,EAAI;EACvC,IAAI;IACA,OAAOF,CAAC,CAACG,OAAO,CAACF,CAAC,GAAC,GAAG,GAACC,CAAC,CAAC,CAAA;GAC5B,CAAC,OAAOE,CAAC,EAAE;AACR,IAAA,OAAOJ,CAAC,CAACG,OAAO,CAACD,CAAC,CAAC,CAAA;AACvB,GAAA;AACJ,CAAC;;ACtBD;;;;;;;;;;;;;;AAcG;AAQH,IAAaG,SAAS,gBAAA,YAAA;EAalB,SAAAA,SAAAA,CAAYC,SAAc,EAAEC,IAAY,EAAEC,WAAmB,EAAEC,UAAmB;AAAA,IAAA,IAAA,CAXlFH,SAAS,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACTI,KAAK,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACLH,IAAI,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACJC,WAAW,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACXG,MAAM,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACNC,GAAG,GAAA,KAAA,CAAA,CAAA;AAAA,IAAA,IAAA,CACHH,QAAQ,GAAA,wEAAA,CAAA;IAMJ,IAAI,CAACH,SAAS,GAAGA,SAAS,CAAA;AAC1B,IAAA,IAAI,CAACC,IAAI,GAAGA,IAAI,KAAK,EAAE,GAAG,IAAI,CAACM,QAAQ,CAAC,IAAI,CAACC,WAAW,CAACP,IAAI,CAAC,GAAGA,IAAI,CAAA;AACrE,IAAA,IAAI,CAACC,WAAW,GAAGA,WAAW,KAAK,EAAE,GAAG,IAAI,CAACO,UAAU,CAAC,IAAI,CAAC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AA;AAAA,EAAA,IAAAvC,MAAA,GAAAsC,QAAA,CAAArC,SAAA,CAAA;AAAAD,EAAAA,MAAA,CAMDf,OAAO,GAAP,SAAAA,OAAAA,CAAQI,IAAY,EAAA;IAChB,OAAOR,IAAI,CAAC,IAAI,CAACO,SAAS,EAAE,IAAI,CAACC,IAAI,EAAEA,IAAI,CAAC,CAAA;GAC/C,CAAA;AAAAW,EAAAA,MAAA,CAEDL,QAAQ,GAAR,SAAAA,QAAAA,CAASO,GAAW,EAAA;IAChB,OAAOA,GAAG,CAACC,OAAO,CAAC,qBAAqB,EAAE,UAASC,IAAI,EAAEC,KAAK,EAAA;AAC1D,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAGF,IAAI,CAACG,WAAW,EAAE,CAAA;AAChE,KAAC,CAAC,CAACJ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACzB,CAAA;AAAAH,EAAAA,MAAA,CAEDH,UAAU,GAAV,SAAAA,UAAAA,CAAWK,GAAW,EAAA;IAClB,OAAOA,GAAG,CAACC,OAAO,CAAC,qBAAqB,EAAE,UAASC,IAAI,EAAEC,KAAK,EAAA;AAC1D,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAG,GAAG,GAAGF,IAAI,CAACE,WAAW,EAAE,CAAA;AACtE,KAAC,CAAC,CAACH,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACzB,CAAA;AAAA,EAAA,OAAAmC,QAAA,CAAA;AAAA,CAAA,CArCyBS,qBAAqB;;;;"}
|
package/dist/mydi.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Bell Eapen
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
declare const mydi: (c: any, m: string, b: string) => any;
|
|
17
|
+
export default mydi;
|
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Bell Eapen
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { DynamicStructuredTool } from "langchain/tools";
|
|
17
|
+
export declare class BaseTool extends DynamicStructuredTool {
|
|
18
|
+
container: any;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
schema: any;
|
|
22
|
+
constructor(container: any, name: string, description: string, schema: any, func?: any);
|
|
23
|
+
func: (args: any) => Promise<string>;
|
|
24
|
+
resolve(name: string): any;
|
|
25
|
+
camelize(str: string): string;
|
|
26
|
+
snake_case(str: string): string;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "medpromptjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Bell Eapen",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"cors": "^2.8.5",
|
|
69
69
|
"dotenv": "^16.3.1",
|
|
70
70
|
"express": "^4.18.2",
|
|
71
|
-
"langchain": "^0.
|
|
71
|
+
"langchain": "^0.1.37",
|
|
72
72
|
"reflect-metadata": "^0.2.1",
|
|
73
73
|
"tslog": "^4.9.2",
|
|
74
74
|
"tsyringe": "^4.8.0"
|