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.
Files changed (45) hide show
  1. package/README.md +3 -28
  2. package/dist/agent.d.ts +31 -0
  3. package/dist/chain.d.ts +32 -0
  4. package/dist/index.d.ts +3 -3
  5. package/dist/medpromptjs.cjs.development.js +215 -243
  6. package/dist/medpromptjs.cjs.development.js.map +1 -1
  7. package/dist/medpromptjs.cjs.production.min.js +1 -1
  8. package/dist/medpromptjs.cjs.production.min.js.map +1 -1
  9. package/dist/medpromptjs.esm.js +214 -243
  10. package/dist/medpromptjs.esm.js.map +1 -1
  11. package/dist/mydi.d.ts +17 -0
  12. package/dist/tool.d.ts +27 -0
  13. package/package.json +2 -2
  14. package/src/agent.ts +79 -0
  15. package/src/chain.ts +72 -0
  16. package/src/index.ts +3 -5
  17. package/src/mydi.ts +25 -0
  18. package/src/tool.ts +59 -0
  19. package/dist/agents/explain_agent.d.ts +0 -6
  20. package/dist/agents/index.d.ts +0 -2
  21. package/dist/bootstrap.d.ts +0 -1
  22. package/dist/chains/index.d.ts +0 -2
  23. package/dist/chains/self_gen_cot_chain.d.ts +0 -26
  24. package/dist/server/index.d.ts +0 -3
  25. package/dist/server/sample_app.d.ts +0 -3
  26. package/dist/tools/find_patient.d.ts +0 -19
  27. package/dist/tools/index.d.ts +0 -2
  28. package/dist/utils/fhir_server.d.ts +0 -4
  29. package/dist/utils/get_medical_record.d.ts +0 -8
  30. package/dist/utils/hapi_server.d.ts +0 -5
  31. package/dist/utils/index.d.ts +0 -4
  32. package/src/agents/explain_agent.ts +0 -37
  33. package/src/agents/index.ts +0 -4
  34. package/src/bootstrap.ts +0 -17
  35. package/src/chains/index.ts +0 -2
  36. package/src/chains/self_gen_cot_chain.ts +0 -82
  37. package/src/server/index.ts +0 -5
  38. package/src/server/sample_app.js +0 -47
  39. package/src/server/sample_app.ts +0 -51
  40. package/src/tools/find_patient.ts +0 -51
  41. package/src/tools/index.ts +0 -4
  42. package/src/utils/fhir_server.ts +0 -11
  43. package/src/utils/get_medical_record.ts +0 -44
  44. package/src/utils/hapi_server.ts +0 -19
  45. package/src/utils/index.ts +0 -6
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # <img src="https://github.com/dermatologist/medprompt/blob/develop/images/medprompt_m_small.png" width="32" height="32">EDPromptJS (JavaScript version of [<img src="https://github.com/dermatologist/medprompt/blob/develop/images/medprompt_m_small.png" width="32" height="32">EDPrompt](https://github.com/dermatologist/medprompt)).
1
+ # medpromptjs
2
+
3
+ A set of base classes for making GenAI application development easy.
2
4
 
3
5
  [![npm version](https://badge.fury.io/js/medpromptjs.svg)](https://www.npmjs.com/package/medpromptjs)
4
6
  [![npm](https://img.shields.io/npm/dt/medpromptjs)](https://www.npmjs.com/package/medpromptjs)
@@ -6,43 +8,16 @@
6
8
  [![Known Vulnerabilities](https://snyk.io/test/github/dermatologist/medpromptjs/badge.svg)](https://www.npmjs.com/package/medpromptjs)
7
9
  [![Documentation](https://badgen.net/badge/icon/documentation?icon=libraries&label)](https://dermatologist.github.io/medpromptjs/)
8
10
 
9
- ## About | *Work in progress*
10
-
11
- ### *Prompts, tools, chains and agents* for healthcare using *LLMs & FHIR*.
12
- This Typescript port of [MEDPrompt](https://github.com/dermatologist/medprompt) does not include all the components of the python version such as the FHIR flattening templates. Please use the [Python version](https://github.com/dermatologist/medprompt) for the full functionality. The aim of MEDPrompt is to provide a conceptual framework and a set of tools for building healthcare applications using LLMs. [Please read my Blog post](https://nuchange.ca/2023/12/medprompt-how-to-architect-llm-solutions-for-healthcare.html). User contributions are highly appreciated!
13
-
14
11
  ## Installation
15
12
  ```
16
13
  npm i --save medpromptjs
17
14
  ```
18
15
 
19
- ## Usage
20
- * [see example](examples/sample_app.js)
21
-
22
- ### Architecture
23
- [![Architecture](https://github.com/dermatologist/medprompt/blob/develop/notes/arch.drawio.svg)](https://github.com/dermatologist/medprompt/blob/develop/notes/arch.drawio.svg)
24
-
25
- ### Design principles
26
- * **Decoupled** - Each component is independent of the other with dependencies injected.
27
- * **LLM agnostic** - Each component can use any LLM. LLMs are injected into chains and agents.
28
- * **No Permanent vector storage** - No permanent storage of vectors. Vectors are generated on the fly.
29
- * **Returns** - Each component should return a LLM friendly message.
30
- * **Modular** - Each component is a separate module that can be used independently.
31
- * **Extensible** - New tools, chains and agents can be added easily.
32
- * **Reusable** - Tools, chains and agents can be reused in different contexts.
33
- * **Testable** - Each component can be tested independently.
34
- * **Documented** - Each component is documented with examples.
35
- * **Open** - Open source and open to contributions.
36
-
37
- #### Disclaimer:
38
- *This repository is not associated with the [Medprompt method of prompting](https://arxiv.org/pdf/2311.16452.pdf). In this generic repository, [I](https://nuchange.ca) will be trying to implement the method using langchain abstractions. Get in touch to share your thoughts via [GitHub discussions](https://github.com/dermatologist/medprompt/discussions). Please submit a PR with a link to the official implementation if any.*
39
-
40
16
  ## Give us a star ⭐️
41
17
  If you find this project useful, give us a star. It helps others discover the project.
42
18
 
43
19
  ## Related projects
44
20
 
45
- * [MEDprompt](https://github.com/dermatologist/medprompt)
46
21
  * [FHIRy - FHIR to pandas dataframe](https://github.com/dermatologist/fhiry)
47
22
  * [kedro-multimodal - Template for multi-modal machine learning in healthcare using Kedro](https://github.com/dermatologist/kedro-multimodal)
48
23
  * [ckblib - A library for clinical knowledge graphs](https://github.com/dermatologist/ckblib)
@@ -0,0 +1,31 @@
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 { PromptTemplate } from "@langchain/core/prompts";
17
+ import { LLM } from "langchain/llms/base";
18
+ import type { ToolInterface } from "@langchain/core/tools";
19
+ export declare class BaseAgent {
20
+ container: any;
21
+ tools: ToolInterface[];
22
+ name: string;
23
+ prompt: PromptTemplate;
24
+ llm: LLM;
25
+ template: string;
26
+ constructor(container: any);
27
+ resolve(name: string): any;
28
+ camelize(str: string): string;
29
+ snake_case(str: string): string;
30
+ run(input: any): Promise<import("@langchain/core/utils/types").ChainValues>;
31
+ }
@@ -0,0 +1,32 @@
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 { PromptTemplate } from "@langchain/core/prompts";
17
+ import { LLM } from "langchain/llms/base";
18
+ import type { ToolInterface } from "@langchain/core/tools";
19
+ export declare class BaseChain {
20
+ container: any;
21
+ tools: ToolInterface[];
22
+ name: string;
23
+ description: string;
24
+ prompt: PromptTemplate;
25
+ llm: LLM;
26
+ template: string;
27
+ constructor(container: any, name: string, description: string, template?: string);
28
+ resolve(name: string): any;
29
+ camelize(str: string): string;
30
+ snake_case(str: string): string;
31
+ chain(input: any): Promise<string>;
32
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import "./bootstrap";
2
- export { SelfGenCotChain } from "./chains/self_gen_cot_chain";
3
- export { ExplainAgent } from './agents/explain_agent';
1
+ export { BaseChain } from "./chain";
2
+ export { BaseAgent } from './agent';
3
+ export { BaseTool } from './tool';
@@ -2,15 +2,117 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- require('reflect-metadata');
6
- var tslog = require('tslog');
7
- var tsyringe = require('tsyringe');
8
- var googlevertexai = require('langchain/llms/googlevertexai');
9
- var chains = require('langchain/chains');
10
- var prompts = require('langchain/prompts');
11
- var hub = require('langchain/hub');
5
+ var prompts = require('@langchain/core/prompts');
6
+ var runnables = require('@langchain/core/runnables');
12
7
  var agents = require('langchain/agents');
8
+ var tools = require('langchain/tools');
13
9
 
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
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
89
+ try {
90
+ var i = n[a](c),
91
+ u = i.value;
92
+ } catch (n) {
93
+ return void e(n);
94
+ }
95
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
96
+ }
97
+ function _asyncToGenerator(n) {
98
+ return function () {
99
+ var t = this,
100
+ e = arguments;
101
+ return new Promise(function (r, o) {
102
+ var a = n.apply(t, e);
103
+ function _next(n) {
104
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
105
+ }
106
+ function _throw(n) {
107
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
108
+ }
109
+ _next(void 0);
110
+ });
111
+ };
112
+ }
113
+ function _inheritsLoose(t, o) {
114
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
115
+ }
14
116
  function _regeneratorRuntime() {
15
117
  _regeneratorRuntime = function () {
16
118
  return e;
@@ -119,7 +221,7 @@ function _regeneratorRuntime() {
119
221
  function makeInvokeMethod(e, r, n) {
120
222
  var o = h;
121
223
  return function (i, a) {
122
- if (o === f) throw new Error("Generator is already running");
224
+ if (o === f) throw Error("Generator is already running");
123
225
  if (o === s) {
124
226
  if ("throw" === i) throw a;
125
227
  return {
@@ -261,7 +363,7 @@ function _regeneratorRuntime() {
261
363
  } else if (c) {
262
364
  if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
263
365
  } else {
264
- if (!u) throw new Error("try statement without catch or finally");
366
+ if (!u) throw Error("try statement without catch or finally");
265
367
  if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
266
368
  }
267
369
  }
@@ -301,7 +403,7 @@ function _regeneratorRuntime() {
301
403
  return o;
302
404
  }
303
405
  }
304
- throw new Error("illegal catch attempt");
406
+ throw Error("illegal catch attempt");
305
407
  },
306
408
  delegateYield: function (e, r, n) {
307
409
  return this.delegate = {
@@ -312,252 +414,65 @@ function _regeneratorRuntime() {
312
414
  }
313
415
  }, e;
314
416
  }
315
- function _toPrimitive(t, r) {
316
- if ("object" != typeof t || !t) return t;
317
- var e = t[Symbol.toPrimitive];
318
- if (void 0 !== e) {
319
- var i = e.call(t, r || "default");
320
- if ("object" != typeof i) return i;
321
- throw new TypeError("@@toPrimitive must return a primitive value.");
322
- }
323
- return ("string" === r ? String : Number)(t);
324
- }
325
- function _toPropertyKey(t) {
326
- var i = _toPrimitive(t, "string");
327
- return "symbol" == typeof i ? i : String(i);
417
+ function _setPrototypeOf(t, e) {
418
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
419
+ return t.__proto__ = e, t;
420
+ }, _setPrototypeOf(t, e);
328
421
  }
329
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
330
- try {
331
- var info = gen[key](arg);
332
- var value = info.value;
333
- } catch (error) {
334
- reject(error);
335
- return;
336
- }
337
- if (info.done) {
338
- resolve(value);
339
- } else {
340
- Promise.resolve(value).then(_next, _throw);
341
- }
342
- }
343
- function _asyncToGenerator(fn) {
344
- return function () {
345
- var self = this,
346
- args = arguments;
347
- return new Promise(function (resolve, reject) {
348
- var gen = fn.apply(self, args);
349
- function _next(value) {
350
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
351
- }
352
- function _throw(err) {
353
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
354
- }
355
- _next(undefined);
356
- });
357
- };
358
- }
359
- function _defineProperties(target, props) {
360
- for (var i = 0; i < props.length; i++) {
361
- var descriptor = props[i];
362
- descriptor.enumerable = descriptor.enumerable || false;
363
- descriptor.configurable = true;
364
- if ("value" in descriptor) descriptor.writable = true;
365
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
366
- }
367
- }
368
- function _createClass(Constructor, protoProps, staticProps) {
369
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
370
- if (staticProps) _defineProperties(Constructor, staticProps);
371
- Object.defineProperty(Constructor, "prototype", {
372
- writable: false
373
- });
374
- return Constructor;
375
- }
376
- function _inheritsLoose(subClass, superClass) {
377
- subClass.prototype = Object.create(superClass.prototype);
378
- subClass.prototype.constructor = subClass;
379
- _setPrototypeOf(subClass, superClass);
380
- }
381
- function _setPrototypeOf(o, p) {
382
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
383
- o.__proto__ = p;
384
- return o;
385
- };
386
- return _setPrototypeOf(o, p);
387
- }
388
-
389
- var FhirServer = function FhirServer() {
390
- this.baseUrl = void 0;
391
- };
392
-
393
- var logger = /*#__PURE__*/new tslog.Logger({
394
- name: "MedpromptLogger"
395
- });
396
- var HapiFhirServer = /*#__PURE__*/function (_FhirServer) {
397
- _inheritsLoose(HapiFhirServer, _FhirServer);
398
- function HapiFhirServer() {
399
- var _this;
400
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
401
- args[_key] = arguments[_key];
402
- }
403
- _this = _FhirServer.call.apply(_FhirServer, [this].concat(args)) || this;
404
- _this.baseUrl = 'http://hapi.fhir.org/baseR4/';
405
- return _this;
406
- }
407
- var _proto = HapiFhirServer.prototype;
408
- _proto.call_fhir_server = /*#__PURE__*/function () {
409
- var _call_fhir_server = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, params) {
410
- var _url_with_params, response, data;
411
- return _regeneratorRuntime().wrap(function _callee$(_context) {
412
- while (1) switch (_context.prev = _context.next) {
413
- case 0:
414
- _url_with_params = "" + this.baseUrl + url + params;
415
- logger.info("url_with_params: " + _url_with_params);
416
- _context.next = 4;
417
- return fetch(_url_with_params);
418
- case 4:
419
- response = _context.sent;
420
- _context.next = 7;
421
- return response.json();
422
- case 7:
423
- data = _context.sent;
424
- return _context.abrupt("return", data);
425
- case 9:
426
- case "end":
427
- return _context.stop();
428
- }
429
- }, _callee, this);
430
- }));
431
- function call_fhir_server(_x, _x2) {
432
- return _call_fhir_server.apply(this, arguments);
433
- }
434
- return call_fhir_server;
435
- }();
436
- return HapiFhirServer;
437
- }(FhirServer);
438
-
439
- var google_vertex_ai = /*#__PURE__*/new googlevertexai.GoogleVertexAI({
440
- model: "text-bison",
441
- temperature: 0.2
442
- });
443
- tsyringe.container.register("main-llm", {
444
- useValue: google_vertex_ai
445
- });
446
- tsyringe.container.register("FhirServer", {
447
- useClass: HapiFhirServer
448
- });
449
422
 
450
- var SelfGenCotChain = /*#__PURE__*/function () {
451
- function SelfGenCotChain(llm, name, template, description) {
452
- this.llm = tsyringe.container.resolve("main-llm");
453
- this.name = "self generated explanation";
454
- this.description = "Generate a chain of thought explanation for the answer to a question.";
423
+ var BaseAgent = /*#__PURE__*/function () {
424
+ function BaseAgent(container) {
425
+ this.container = void 0;
426
+ this.tools = void 0;
427
+ this.name = void 0;
428
+ this.prompt = void 0;
429
+ this.llm = void 0;
455
430
  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 ";
456
- this.promptTemplate = new prompts.PromptTemplate({
457
- template: this.template,
458
- inputVariables: ["question", "answer"]
459
- });
460
- this.chain = new chains.LLMChain({
461
- llm: this.llm,
462
- prompt: this.promptTemplate,
463
- outputKey: "explanation"
464
- });
465
- if (llm) this.llm = llm;
466
- if (name) this.name = name;
467
- if (template) this.template = template;
468
- if (description) this.description = description;
431
+ this.container = container;
432
+ this.name = this.camelize(this.constructor.name);
433
+ this.tools = this.resolve("tools");
434
+ this.prompt = this.resolve("prompt") !== "" ? this.resolve("prompt") : prompts.PromptTemplate.fromTemplate(this.template);
435
+ this.llm = this.resolve("main-llm");
469
436
  }
470
- var _proto = SelfGenCotChain.prototype;
471
- _proto.call = /*#__PURE__*/function () {
472
- var _call2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
473
- var chainExecutionResult;
474
- return _regeneratorRuntime().wrap(function _callee$(_context) {
475
- while (1) switch (_context.prev = _context.next) {
476
- case 0:
477
- _context.next = 2;
478
- return this.chain.call(args);
479
- case 2:
480
- chainExecutionResult = _context.sent;
481
- return _context.abrupt("return", chainExecutionResult);
482
- case 4:
483
- case "end":
484
- return _context.stop();
485
- }
486
- }, _callee, this);
487
- }));
488
- function call(_x) {
489
- return _call2.apply(this, arguments);
490
- }
491
- return call;
492
- }();
493
- _proto._call = function _call(values, runManager) {
494
- throw new Error("Method not implemented.");
437
+ var _proto = BaseAgent.prototype;
438
+ _proto.resolve = function resolve(name) {
439
+ return mydi(this.container, this.name, name);
495
440
  };
496
- _proto._chainType = function _chainType() {
497
- return "self_gen_cot_chain";
441
+ _proto.camelize = function camelize(str) {
442
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
443
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
444
+ }).replace(/\s+/g, '');
498
445
  };
499
- _proto.getName = function getName() {
500
- return this.name;
446
+ _proto.snake_case = function snake_case(str) {
447
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
448
+ return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
449
+ }).replace(/\s+/g, '');
501
450
  };
502
- _proto.getTemplate = function getTemplate() {
503
- return this.template;
504
- };
505
- _proto.getDescription = function getDescription() {
506
- return this.description;
507
- };
508
- _createClass(SelfGenCotChain, [{
509
- key: "inputKeys",
510
- get: function get() {
511
- return ["question", "answer"];
512
- }
513
- }, {
514
- key: "outputKeys",
515
- get: function get() {
516
- return ["explanation"];
517
- }
518
- }]);
519
- return SelfGenCotChain;
520
- }();
521
-
522
- var ExplainAgent = /*#__PURE__*/function () {
523
- function ExplainAgent(tools) {
524
- if (tools === void 0) {
525
- tools = [new SelfGenCotChain()];
526
- }
527
- this.tools = void 0;
528
- this.tools = tools;
529
- }
530
- var _proto = ExplainAgent.prototype;
531
451
  _proto.run = /*#__PURE__*/function () {
532
452
  var _run = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
533
- var promptWithChat, llm, tools, agentWithChat, agentExecutorWithChat, result2;
453
+ var agent, agentExecutor;
534
454
  return _regeneratorRuntime().wrap(function _callee$(_context) {
535
455
  while (1) switch (_context.prev = _context.next) {
536
456
  case 0:
537
457
  _context.next = 2;
538
- return hub.pull("hwchase17/react-chat");
458
+ return agents.createStructuredChatAgent({
459
+ llm: this.llm,
460
+ tools: this.tools,
461
+ prompt: this.prompt
462
+ });
539
463
  case 2:
540
- promptWithChat = _context.sent;
541
- llm = tsyringe.container.resolve("main-llm");
542
- tools = this.tools;
543
- _context.next = 7;
544
- return agents.createReactAgent({
545
- llm: llm,
546
- tools: tools,
547
- prompt: promptWithChat
464
+ agent = _context.sent;
465
+ agentExecutor = new agents.AgentExecutor({
466
+ agent: agent,
467
+ tools: this.tools,
468
+ // verbose: true,
469
+ handleParsingErrors: "Please try again, paying close attention to the final answer"
548
470
  });
471
+ _context.next = 6;
472
+ return agentExecutor.invoke(input);
473
+ case 6:
474
+ return _context.abrupt("return", _context.sent);
549
475
  case 7:
550
- agentWithChat = _context.sent;
551
- agentExecutorWithChat = new agents.AgentExecutor({
552
- agent: agentWithChat,
553
- tools: tools
554
- });
555
- _context.next = 11;
556
- return agentExecutorWithChat.invoke(input);
557
- case 11:
558
- result2 = _context.sent;
559
- return _context.abrupt("return", result2);
560
- case 13:
561
476
  case "end":
562
477
  return _context.stop();
563
478
  }
@@ -568,9 +483,66 @@ var ExplainAgent = /*#__PURE__*/function () {
568
483
  }
569
484
  return run;
570
485
  }();
571
- return ExplainAgent;
486
+ return BaseAgent;
572
487
  }();
573
488
 
574
- exports.ExplainAgent = ExplainAgent;
575
- exports.SelfGenCotChain = SelfGenCotChain;
489
+ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
490
+ function BaseTool(container, name, description, schema, func) {
491
+ var _this;
492
+ if (func === void 0) {
493
+ func = null;
494
+ }
495
+ _this = _DynamicStructuredToo.call(this, {
496
+ name: name,
497
+ description: description,
498
+ schema: schema,
499
+ func: func
500
+ }) || this;
501
+ _this.container = void 0;
502
+ _this.name = void 0;
503
+ _this.description = void 0;
504
+ _this.schema = void 0;
505
+ _this.func = /*#__PURE__*/function () {
506
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
507
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
508
+ while (1) switch (_context.prev = _context.next) {
509
+ case 0:
510
+ return _context.abrupt("return", "override this");
511
+ case 1:
512
+ case "end":
513
+ return _context.stop();
514
+ }
515
+ }, _callee);
516
+ }));
517
+ return function (_x) {
518
+ return _ref.apply(this, arguments);
519
+ };
520
+ }();
521
+ _this.container = container;
522
+ _this.name = name === "" ? _this.camelize(_this.constructor.name) : name;
523
+ _this.description = description === "" ? _this.snake_case(_this.constructor.name) : description;
524
+ _this.schema = schema;
525
+ return _this;
526
+ }
527
+ _inheritsLoose(BaseTool, _DynamicStructuredToo);
528
+ var _proto = BaseTool.prototype;
529
+ _proto.resolve = function resolve(name) {
530
+ return mydi(this.container, this.name, name);
531
+ };
532
+ _proto.camelize = function camelize(str) {
533
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
534
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
535
+ }).replace(/\s+/g, '');
536
+ };
537
+ _proto.snake_case = function snake_case(str) {
538
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
539
+ return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
540
+ }).replace(/\s+/g, '');
541
+ };
542
+ return BaseTool;
543
+ }(tools.DynamicStructuredTool);
544
+
545
+ exports.BaseAgent = BaseAgent;
546
+ exports.BaseChain = BaseChain;
547
+ exports.BaseTool = BaseTool;
576
548
  //# sourceMappingURL=medpromptjs.cjs.development.js.map