medpromptjs 0.3.0 → 0.3.2

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.
@@ -3,6 +3,8 @@ import { RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables
3
3
  import { AIMessage } from '@langchain/core/messages';
4
4
  import { AgentExecutor, createStructuredChatAgent } from 'langchain/agents';
5
5
  import { DynamicStructuredTool } from 'langchain/tools';
6
+ import { CharacterTextSplitter } from '@langchain/textsplitters';
7
+ import { Logger } from 'tslog';
6
8
 
7
9
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
8
10
  try {
@@ -45,7 +47,7 @@ function _regeneratorRuntime() {
45
47
  a = o.asyncIterator || "@@asyncIterator",
46
48
  u = o.toStringTag || "@@toStringTag";
47
49
  function c(t, r, e, n) {
48
- return Object.defineProperty(t, r, {
50
+ Object.defineProperty(t, r, {
49
51
  value: e,
50
52
  enumerable: !n,
51
53
  configurable: !n,
@@ -196,7 +198,7 @@ function _regeneratorRuntime() {
196
198
  }
197
199
  throw new TypeError(typeof r + " is not iterable");
198
200
  }
199
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) {
201
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), c(GeneratorFunctionPrototype, u, GeneratorFunction.displayName = "GeneratorFunction"), r.isGeneratorFunction = function (t) {
200
202
  var r = "function" == typeof t && t.constructor;
201
203
  return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
202
204
  }, r.mark = function (t) {
@@ -537,5 +539,428 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
537
539
  return BaseTool;
538
540
  }(DynamicStructuredTool);
539
541
 
540
- export { BaseAgent, BaseChain, BaseTool };
542
+ var MapQuery = /*#__PURE__*/function (_BaseChain) {
543
+ function MapQuery() {
544
+ var _this;
545
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
546
+ args[_key] = arguments[_key];
547
+ }
548
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
549
+ _this.name = 'MapQuery';
550
+ _this.description = 'Map a CQL query to a natural language.';
551
+ _this.template = "\n You are an assistant that can convert statements to a natural language query as in the example below.\n\n\n\n Statements: Visual foot exam in the last month. Visual foot exam showed active infection.\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n Statements: {expression}\n query: ";
552
+ return _this;
553
+ }
554
+ _inheritsLoose(MapQuery, _BaseChain);
555
+ return MapQuery;
556
+ }(BaseChain);
557
+
558
+ var MapDoc = /*#__PURE__*/function (_BaseChain) {
559
+ function MapDoc() {
560
+ var _this;
561
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
562
+ args[_key] = arguments[_key];
563
+ }
564
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
565
+ _this.name = 'MapDoc';
566
+ _this.description = 'Map a set of documents to facts.';
567
+ _this.template = "\n You will be given a document and few statements.\n\n Extract facts from the document that are relevant to the statements.\n\n Do not include any irrelevant information or context.\n\n\n \n Example:\n\n document: The patient is a 45-year-old male with a history of hypertension. He presented with chest pain and was diagnosed with myocardial infarction. He was treated with aspirin and beta-blockers.\n\n statements: diagnosis of myocardial infarction. currently on beta-blockers.\n\n facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\n\n document: {document} \n\n statements: {statements}\n\n facts: ";
568
+ return _this;
569
+ }
570
+ _inheritsLoose(MapDoc, _BaseChain);
571
+ return MapDoc;
572
+ }(BaseChain);
573
+
574
+ var ReduceChain = /*#__PURE__*/function (_BaseChain) {
575
+ function ReduceChain() {
576
+ var _this;
577
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
578
+ args[_key] = arguments[_key];
579
+ }
580
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
581
+ _this.name = 'Reduce';
582
+ _this.description = 'Reduce a set of documents to binary answer.';
583
+ _this.template = "\n Say yes if the facts mentions all aspects of the query, else say no.\n\n\n Example:\n facts: Patient had a laproscopy 27 days back. The findings were normal. \n\n query: Did the patient have a laproscopy this month?\n\n answer: YES. The patient had a laproscopy 27 days back.\n\n facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \n\n query: Is the patient on heparin and metformin?\n\n answer: NO. The patient is on heparin but not on metformin.\n\n facts: A visual foot examination was performed 26 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\n\n facts: A visual foot examination was performed 126 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\n\n facts: {facts} \n\n query: {query}\n\n answer: ";
584
+ return _this;
585
+ }
586
+ _inheritsLoose(ReduceChain, _BaseChain);
587
+ return ReduceChain;
588
+ }(BaseChain);
589
+
590
+ var log = /*#__PURE__*/new Logger();
591
+ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
592
+ function LLMLoop() {
593
+ var _this;
594
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
595
+ args[_key] = arguments[_key];
596
+ }
597
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
598
+ // Implement the LLM loop logic here
599
+ _this.string_expression = '';
600
+ _this.name = 'LLMLoop';
601
+ _this.description = 'Base LLM Loop.';
602
+ _this.mapQuery = new MapQuery(_this.container, '', '');
603
+ _this.mapDoc = new MapDoc(_this.container, '', '');
604
+ _this.reduceChain = new ReduceChain(_this.container, '', '');
605
+ return _this;
606
+ }
607
+ _inheritsLoose(LLMLoop, _BaseChain);
608
+ var _proto = LLMLoop.prototype;
609
+ _proto.checkAssertion = /*#__PURE__*/function () {
610
+ var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
611
+ var _expression, _context, _content, _input, result;
612
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
613
+ while (1) switch (_context2.prev = _context2.next) {
614
+ case 0:
615
+ _expression = '';
616
+ try {
617
+ // Check if expression is a valid JSON string
618
+ _expression = this.printValues(JSON.parse(expression));
619
+ } catch (error) {
620
+ _expression = expression; // If not, use the expression as is
621
+ }
622
+ log.info("Checking assertion with expression: " + _expression);
623
+ // Initialize context and content
624
+ _context = undefined;
625
+ _content = '';
626
+ try {
627
+ _context = JSON.parse(context);
628
+ } catch (error) {
629
+ _context = context; // If not, use the context as is
630
+ log.warn("Context is not a valid JSON string: " + context);
631
+ log.warn("Using context as a string: " + _context);
632
+ }
633
+ try {
634
+ // Check if context is a valid JSON string
635
+ _context = JSON.parse(context);
636
+ _context.forEach(function (element) {
637
+ element.content.forEach(function (contentItem) {
638
+ _content += atob(contentItem.attachment.data.value);
639
+ });
640
+ });
641
+ } catch (error) {
642
+ _content = context; // If not, use the context as is
643
+ log.warn("Context is not a valid JSON : " + context);
644
+ log.warn("Using context as a string: " + _content);
645
+ }
646
+ _content = this.findDatesAndConvertToTimeElapsed(_content.replace(/(\r\n|\n|\r)/gm, ' '));
647
+ log.info("Checking assertion with context: " + _content);
648
+ _input = {
649
+ input: {
650
+ expression: _expression,
651
+ context: _content
652
+ }
653
+ };
654
+ _context2.next = 12;
655
+ return this.chain(_input);
656
+ case 12:
657
+ result = _context2.sent;
658
+ log.info("Assertion check result: " + result);
659
+ return _context2.abrupt("return", result);
660
+ case 15:
661
+ case "end":
662
+ return _context2.stop();
663
+ }
664
+ }, _callee, this);
665
+ }));
666
+ function checkAssertion(_x, _x2) {
667
+ return _checkAssertion.apply(this, arguments);
668
+ }
669
+ return checkAssertion;
670
+ }();
671
+ _proto.checkMention = /*#__PURE__*/function () {
672
+ var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(expression, context) {
673
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
674
+ while (1) switch (_context3.prev = _context3.next) {
675
+ case 0:
676
+ if (!(expression && context)) {
677
+ _context3.next = 2;
678
+ break;
679
+ }
680
+ return _context3.abrupt("return", true);
681
+ case 2:
682
+ return _context3.abrupt("return", false);
683
+ case 3:
684
+ case "end":
685
+ return _context3.stop();
686
+ }
687
+ }, _callee2);
688
+ }));
689
+ function checkMention(_x3, _x4) {
690
+ return _checkMention.apply(this, arguments);
691
+ }
692
+ return checkMention;
693
+ }();
694
+ _proto.checkNegation = /*#__PURE__*/function () {
695
+ var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(expression, context) {
696
+ return _regeneratorRuntime().wrap(function _callee3$(_context4) {
697
+ while (1) switch (_context4.prev = _context4.next) {
698
+ case 0:
699
+ if (!(expression && context)) {
700
+ _context4.next = 2;
701
+ break;
702
+ }
703
+ return _context4.abrupt("return", true);
704
+ case 2:
705
+ return _context4.abrupt("return", false);
706
+ case 3:
707
+ case "end":
708
+ return _context4.stop();
709
+ }
710
+ }, _callee3);
711
+ }));
712
+ function checkNegation(_x5, _x6) {
713
+ return _checkNegation.apply(this, arguments);
714
+ }
715
+ return checkNegation;
716
+ }();
717
+ _proto.findDatesAndConvertToTimeElapsed = function findDatesAndConvertToTimeElapsed(text) {
718
+ // Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'
719
+ var dateRegex = /(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g;
720
+ var matches;
721
+ var currentDate = new Date();
722
+ while ((matches = dateRegex.exec(text)) !== null) {
723
+ var date = new Date(matches[0]);
724
+ var timeElapsed = (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);
725
+ text = text.replace(matches[0], Math.floor(timeElapsed).toString() + ' days ago.');
726
+ }
727
+ return text;
728
+ };
729
+ _proto.camelToString = function camelToString(camelCase) {
730
+ return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
731
+ return str.toUpperCase();
732
+ });
733
+ };
734
+ _proto.stringToBoolean = function stringToBoolean(str) {
735
+ log.info("Converting string to boolean: " + str);
736
+ var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed', 'did have', 'showed', 'revealed'];
737
+ var lowerStr = str.toLowerCase();
738
+ return positiveKeywords.some(function (keyword) {
739
+ return lowerStr.includes(keyword);
740
+ });
741
+ };
742
+ _proto.textSplitter = /*#__PURE__*/function () {
743
+ var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text, chunkSize, chunkOverlap) {
744
+ var textSplitter, texts;
745
+ return _regeneratorRuntime().wrap(function _callee4$(_context5) {
746
+ while (1) switch (_context5.prev = _context5.next) {
747
+ case 0:
748
+ if (chunkSize === void 0) {
749
+ chunkSize = 3900;
750
+ }
751
+ if (chunkOverlap === void 0) {
752
+ chunkOverlap = 0;
753
+ }
754
+ textSplitter = new CharacterTextSplitter({
755
+ chunkSize: chunkSize,
756
+ chunkOverlap: chunkOverlap
757
+ });
758
+ _context5.next = 5;
759
+ return textSplitter.splitText(text);
760
+ case 5:
761
+ texts = _context5.sent;
762
+ if (!(texts.length === 0)) {
763
+ _context5.next = 9;
764
+ break;
765
+ }
766
+ log.warn('No text chunks created. Please check the input text.');
767
+ return _context5.abrupt("return", []);
768
+ case 9:
769
+ if (texts.length > 100) {
770
+ log.warn("Warning: More than 100 text chunks created (" + texts.length + "). This may affect performance.");
771
+ }
772
+ if (chunkSize < 1000) {
773
+ log.warn("Warning: Chunk size is less than 1000 characters (" + chunkSize + "). This may lead to very small chunks.");
774
+ }
775
+ log.info("Text split into " + texts.length + " chunks with size " + chunkSize + " and overlap " + chunkOverlap);
776
+ return _context5.abrupt("return", texts);
777
+ case 13:
778
+ case "end":
779
+ return _context5.stop();
780
+ }
781
+ }, _callee4);
782
+ }));
783
+ function textSplitter(_x7, _x8, _x9) {
784
+ return _textSplitter.apply(this, arguments);
785
+ }
786
+ return textSplitter;
787
+ }();
788
+ _proto.printValues = function printValues(obj) {
789
+ log.info("Processing Rule: " + obj.name + " for " + obj.context);
790
+ // For each obj.expression:arg:where
791
+ if (obj.expression && obj.expression.arg && obj.expression.arg.where) {
792
+ // for each args in obj.expression.arg.where, extract the nested key called "value"
793
+ var statements = this.extractObjectsByKey(obj.expression.arg.where, 'value');
794
+ return statements.join(' ').replace(/,/g, ' ');
795
+ }
796
+ // return statements array as a string seperated by space
797
+ return '';
798
+ };
799
+ _proto.extractObjectsByKey = function extractObjectsByKey(obj, key) {
800
+ var results = [];
801
+ function traverse(obj) {
802
+ for (var currentKey in obj) {
803
+ if (obj.hasOwnProperty(currentKey)) {
804
+ if (currentKey === key) {
805
+ results.push(obj[currentKey]);
806
+ }
807
+ if (typeof obj[currentKey] === 'object' && obj[currentKey] !== null) {
808
+ traverse(obj[currentKey]);
809
+ }
810
+ }
811
+ }
812
+ }
813
+ traverse(obj);
814
+ return results;
815
+ };
816
+ _proto._printValues = function _printValues(obj) {
817
+ var _this2 = this;
818
+ for (var key in obj) {
819
+ if (typeof obj[key] === 'object') {
820
+ this._printValues(obj[key]);
821
+ } else {
822
+ this.string_expression += obj[key] + ' ';
823
+ }
824
+ }
825
+ var _eliminate = ['true', 'false', 'null', 'undefined', 'String', 'Number', 'Object', 'Array', 'Boolean', 'value', 'Type', 'Specifier', 'Named'];
826
+ _eliminate.forEach(function (element) {
827
+ var regex = new RegExp(element, 'g');
828
+ _this2.string_expression = _this2.string_expression.replace(regex, '');
829
+ });
830
+ this.string_expression = this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
831
+ return this.camelToString(this.string_expression);
832
+ };
833
+ _proto.chain = /*#__PURE__*/function () {
834
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(input) {
835
+ var _this3 = this;
836
+ var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQueryChain, mapDocChain, parallelChain, sequence;
837
+ return _regeneratorRuntime().wrap(function _callee8$(_context9) {
838
+ while (1) switch (_context9.prev = _context9.next) {
839
+ case 0:
840
+ _context9.next = 2;
841
+ return import('@langchain/core/runnables');
842
+ case 2:
843
+ _yield$import = _context9.sent;
844
+ RunnableSequence = _yield$import.RunnableSequence;
845
+ RunnableParallel = _yield$import.RunnableParallel;
846
+ RunnablePassthrough = _yield$import.RunnablePassthrough;
847
+ mapQueryChain = RunnablePassthrough.assign({
848
+ query: function () {
849
+ var _query = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(input) {
850
+ return _regeneratorRuntime().wrap(function _callee5$(_context6) {
851
+ while (1) switch (_context6.prev = _context6.next) {
852
+ case 0:
853
+ return _context6.abrupt("return", _this3.mapQuery.chain({
854
+ input: {
855
+ expression: input.input.expression
856
+ }
857
+ }));
858
+ case 1:
859
+ case "end":
860
+ return _context6.stop();
861
+ }
862
+ }, _callee5);
863
+ }));
864
+ function query(_x1) {
865
+ return _query.apply(this, arguments);
866
+ }
867
+ return query;
868
+ }()
869
+ });
870
+ mapDocChain = RunnablePassthrough.assign({
871
+ documents: function () {
872
+ var _documents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
873
+ var textChunks;
874
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
875
+ while (1) switch (_context7.prev = _context7.next) {
876
+ case 0:
877
+ _context7.next = 2;
878
+ return _this3.textSplitter(input.input.context);
879
+ case 2:
880
+ textChunks = _context7.sent;
881
+ return _context7.abrupt("return", Promise.all(textChunks.map(function (chunk) {
882
+ return _this3.mapDoc.chain({
883
+ input: {
884
+ document: chunk,
885
+ statements: input.input.expression
886
+ }
887
+ });
888
+ })));
889
+ case 4:
890
+ case "end":
891
+ return _context7.stop();
892
+ }
893
+ }, _callee6);
894
+ }));
895
+ function documents(_x10) {
896
+ return _documents.apply(this, arguments);
897
+ }
898
+ return documents;
899
+ }()
900
+ });
901
+ parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
902
+ sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
903
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
904
+ var expression, query, documents;
905
+ return _regeneratorRuntime().wrap(function _callee7$(_context8) {
906
+ while (1) switch (_context8.prev = _context8.next) {
907
+ case 0:
908
+ /* results is an array: [{ query: ... }, { documents: [...] }]
909
+ {
910
+ "0": {
911
+ "input": {
912
+ "expression": "0 Visual foot exam showed active infection?",
913
+ "context": "Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. "
914
+ },
915
+ "query": "The text indicates a question about whether a visual foot exam revealed an active infection.\n"
916
+ },
917
+ "1": {
918
+ "input": {
919
+ "expression": "0 Visual foot exam showed active infection?",
920
+ "context": "Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. "
921
+ },
922
+ "documents": [
923
+ "26 days ago, a visual foot examination revealed no dryness, cracking, ulceration, lesions, discoloration, fungal infection, ingrown nails, cyanosis, pallor, edema, bunions, hammertoes, or Charcot foot deformities. Circulation and capillary refill were normal. However, the exam showed signs"
924
+ ]
925
+ }
926
+ }
927
+ */
928
+ log.info("Results from parallel chain: " + JSON.stringify(results));
929
+ expression = results[0].input.expression;
930
+ query = results[0].query;
931
+ documents = results[1].documents;
932
+ return _context8.abrupt("return", _this3.reduceChain.chain({
933
+ input: {
934
+ facts: documents,
935
+ query: query + ' ' + expression
936
+ }
937
+ }));
938
+ case 5:
939
+ case "end":
940
+ return _context8.stop();
941
+ }
942
+ }, _callee7);
943
+ }));
944
+ return function (_x11) {
945
+ return _ref.apply(this, arguments);
946
+ };
947
+ }()), function (result) {
948
+ return _this3.stringToBoolean(result);
949
+ }]);
950
+ return _context9.abrupt("return", sequence.invoke(input));
951
+ case 11:
952
+ case "end":
953
+ return _context9.stop();
954
+ }
955
+ }, _callee8);
956
+ }));
957
+ function chain(_x0) {
958
+ return _chain.apply(this, arguments);
959
+ }
960
+ return chain;
961
+ }();
962
+ return LLMLoop;
963
+ }(BaseChain);
964
+
965
+ export { BaseAgent, BaseChain, BaseTool, LLMLoop };
541
966
  //# sourceMappingURL=medpromptjs.esm.js.map
@@ -1 +1 @@
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","/**\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/core/language_models/llms';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\nimport {\n RunnablePassthrough,\n RunnableSequence,\n} from '@langchain/core/runnables';\nimport { AIMessage } from '@langchain/core/messages';\n\nexport class BaseChain {\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: any;\n llm: LLM;\n template: string;\n chat_model: boolean;\n runnable: any;\n\n constructor(\n container: any,\n name: string,\n description: string,\n template: string = `\n Summarize the following text:\n {input}\n `\n ) {\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.template = template;\n this.tools = this.resolve('tools');\n this.llm = this.resolve('main-llm');\n this.chat_model = false;\n try {\n this.chat_model = this.resolve('chat_model');\n } catch (e) {}\n if (this.chat_model) {\n this.prompt = ChatPromptTemplate.fromTemplate(this.template);\n } else {\n this.prompt = PromptTemplate.fromTemplate(this.template);\n }\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n async chain(input: any) {\n this.runnable = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm,\n ]);\n if (this.chat_model) {\n const response: string = await this.runnable.invoke(input);\n const aiMessage = new AIMessage(response);\n return aiMessage.content;\n }\n return await this.runnable.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 { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport {\n AgentExecutor,\n createReactAgent,\n createStructuredChatAgent,\n} from 'langchain/agents';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\n\nexport class BaseAgent {\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 =\n this.resolve('prompt') !== ''\n ? this.resolve('prompt')\n : 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\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\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 container: any;\n name: string;\n description: string;\n schema: any;\n constructor(\n container: any,\n name: string,\n description: string,\n schema: any,\n func: any = null\n ) {\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 =\n 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\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n}\n"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","chat_model","runnable","camelize","constructor","snake_case","ChatPromptTemplate","fromTemplate","PromptTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","_chain","_asyncToGenerator","_regeneratorRuntime","mark","_callee","input","response","aiMessage","wrap","_callee$","_context","prev","next","RunnableSequence","from","RunnablePassthrough","invoke","sent","AIMessage","abrupt","content","stop","_x","apply","arguments","BaseAgent","run","_run","agent","agentExecutor","createStructuredChatAgent","AgentExecutor","handleParsingErrors","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;AAcG;AAEH,IAAMA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AA,CAAAR,QAAA,EAAAC,qBAAA,CAAA,CAAA;AAAA,EAAA,IAAA3C,MAAA,GAAA0C,QAAA,CAAAzC,SAAA,CAAA;AAAAD,EAAAA,MAAA,CAMDlB,OAAO,GAAP,SAAAA,OAAOA,CAACI,IAAY,EAAA;IAClB,OAAOR,IAAI,CAAC,IAAI,CAACO,SAAS,EAAE,IAAI,CAACC,IAAI,EAAEA,IAAI,CAAC,CAAA;GAC7C,CAAA;AAAAc,EAAAA,MAAA,CAEDN,QAAQ,GAAR,SAAAA,QAAQA,CAACQ,GAAW,EAAA;IAClB,OAAOA,GAAG,CACPC,OAAO,CAAC,qBAAqB,EAAE,UAAUC,IAAI,EAAEC,KAAK,EAAA;AACnD,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAGF,IAAI,CAACG,WAAW,EAAE,CAAA;AAC9D,KAAC,CAAC,CACDJ,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACvB,CAAA;AAAAH,EAAAA,MAAA,CAEDJ,UAAU,GAAV,SAAAA,UAAUA,CAACM,GAAW,EAAA;IACpB,OAAOA,GAAG,CACPC,OAAO,CAAC,qBAAqB,EAAE,UAAUC,IAAI,EAAEC,KAAK,EAAA;AACnD,MAAA,OAAOA,KAAK,KAAK,CAAC,GAAGD,IAAI,CAACE,WAAW,EAAE,GAAG,GAAG,GAAGF,IAAI,CAACE,WAAW,EAAE,CAAA;AACpE,KAAC,CAAC,CACDH,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACvB,CAAA;AAAA,EAAA,OAAAuC,QAAA,CAAA;AAAA,CAAA,CA/C2BS,qBAAqB;;;;"}
1
+ {"version":3,"file":"medpromptjs.esm.js","sources":["../src/mydi.ts","../src/chain.ts","../src/agent.ts","../src/tool.ts","../src/llm_loop/map_query.ts","../src/llm_loop/map_doc.ts","../src/llm_loop/reduce.ts","../src/llm_loop/base.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","/**\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/core/language_models/llms';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\nimport {\n RunnablePassthrough,\n RunnableSequence,\n} from '@langchain/core/runnables';\nimport { AIMessage } from '@langchain/core/messages';\n\nexport class BaseChain {\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: any;\n llm: LLM;\n template: string;\n chat_model: boolean;\n runnable: any;\n\n constructor(\n container: any,\n name: string,\n description: string,\n template: string = `\n Summarize the following text:\n {input}\n `\n ) {\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.template = template;\n this.tools = this.resolve('tools');\n this.llm = this.resolve('main-llm');\n this.chat_model = false;\n try {\n this.chat_model = this.resolve('chat_model');\n } catch (e) {}\n if (this.chat_model) {\n this.prompt = ChatPromptTemplate.fromTemplate(this.template);\n } else {\n this.prompt = PromptTemplate.fromTemplate(this.template);\n }\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n async chain(input: any) {\n this.runnable = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm,\n ]);\n if (this.chat_model) {\n const response: string = await this.runnable.invoke(input);\n const aiMessage = new AIMessage(response);\n return aiMessage.content;\n }\n return await this.runnable.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 { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport {\n AgentExecutor,\n createReactAgent,\n createStructuredChatAgent,\n} from 'langchain/agents';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\n\nexport class BaseAgent {\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 =\n this.resolve('prompt') !== ''\n ? this.resolve('prompt')\n : 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\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\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 container: any;\n name: string;\n description: string;\n schema: any;\n constructor(\n container: any,\n name: string,\n description: string,\n schema: any,\n func: any = null\n ) {\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 =\n 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\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n}\n","import { BaseChain } from '../chain';\n\nexport class MapQuery extends BaseChain {\n name: string = 'MapQuery';\n description: string = 'Map a CQL query to a natural language.';\n template: string = `\n You are an assistant that can convert statements to a natural language query as in the example below.\\n\n\n\n Statements: Visual foot exam in the last month. Visual foot exam showed active infection.\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n Statements: {expression}\n query: `;\n}\n","import { BaseChain } from '../chain';\n\nexport class MapDoc extends BaseChain {\n name: string = 'MapDoc';\n description: string = 'Map a set of documents to facts.';\n template: string = `\n You will be given a document and few statements.\\n\n Extract facts from the document that are relevant to the statements.\\n\n Do not include any irrelevant information or context.\\n\n\n \n Example:\\n\n document: The patient is a 45-year-old male with a history of hypertension. He presented with chest pain and was diagnosed with myocardial infarction. He was treated with aspirin and beta-blockers.\\n\n statements: diagnosis of myocardial infarction. currently on beta-blockers.\\n\n facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\\n\n document: {document} \\n\n statements: {statements}\\n\n facts: `;\n}\n","import { BaseChain } from '../chain';\n\nexport class ReduceChain extends BaseChain {\n name: string = 'Reduce';\n description: string = 'Reduce a set of documents to binary answer.';\n template: string = `\n Say yes if the facts mentions all aspects of the query, else say no.\\n\n\n Example:\n facts: Patient had a laproscopy 27 days back. The findings were normal. \\n\n query: Did the patient have a laproscopy this month?\\n\n answer: YES. The patient had a laproscopy 27 days back.\\n\n facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \\n\n query: Is the patient on heparin and metformin?\\n\n answer: NO. The patient is on heparin but not on metformin.\\n\n facts: A visual foot examination was performed 26 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \\n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\\n\n answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\\n\n facts: A visual foot examination was performed 126 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \\n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\\n\n answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\\n\n facts: {facts} \\n\n query: {query}\\n\n answer: `;\n}\n","import { BaseChain } from '../chain';\nimport { MapQuery } from './map_query';\nimport { CharacterTextSplitter } from '@langchain/textsplitters';\nimport { ReduceChain } from './reduce';\nimport { MapDoc } from './map_doc';\nimport { Logger, ILogObj } from 'tslog';\n\nconst log: Logger<ILogObj> = new Logger();\nexport class LLMLoop extends BaseChain {\n // Implement the LLM loop logic here\n string_expression: string = '';\n name: string = 'LLMLoop';\n description: string = 'Base LLM Loop.';\n mapQuery: MapQuery = new MapQuery(this.container, '', '');\n mapDoc: MapDoc = new MapDoc(this.container, '', '');\n reduceChain: ReduceChain = new ReduceChain(this.container, '', '');\n\n async checkAssertion(expression: string, context: any): Promise<boolean> {\n let _expression: string = '';\n try {\n // Check if expression is a valid JSON string\n _expression = this.printValues(JSON.parse(expression));\n } catch (error) {\n _expression = expression; // If not, use the expression as is\n }\n\n log.info(`Checking assertion with expression: ${_expression}`);\n // Initialize context and content\n let _context: any = undefined;\n let _content: string = '';\n try {\n _context = JSON.parse(context);\n } catch (error) {\n _context = context; // If not, use the context as is\n log.warn(`Context is not a valid JSON string: ${context}`);\n log.warn(`Using context as a string: ${_context}`);\n }\n try {\n // Check if context is a valid JSON string\n _context = JSON.parse(context);\n _context.forEach((element: any) => {\n element.content.forEach((contentItem: any) => {\n _content += atob(contentItem.attachment.data.value);\n });\n });\n } catch (error) {\n _content = context; // If not, use the context as is\n log.warn(`Context is not a valid JSON : ${context}`);\n log.warn(`Using context as a string: ${_content}`);\n }\n _content = this.findDatesAndConvertToTimeElapsed(\n _content.replace(/(\\r\\n|\\n|\\r)/gm, ' ')\n );\n log.info(`Checking assertion with context: ${_content}`);\n const _input = {\n input: {\n expression: _expression,\n context: _content,\n },\n };\n const result = await this.chain(_input);\n log.info(`Assertion check result: ${result}`);\n return result;\n }\n\n async checkMention(expression: string, context: any): Promise<boolean> {\n if (expression && context) return true; // Placeholder for assertion check logic\n return false;\n }\n\n async checkNegation(expression: string, context: any): Promise<boolean> {\n if (expression && context) return true; // Placeholder for assertion check logic\n return false;\n }\n\n findDatesAndConvertToTimeElapsed(text: string): string {\n // Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'\n const dateRegex = /(\\d{1,2}[-/]\\d{1,2}[-/]\\d{4})/g;\n let matches;\n let currentDate = new Date();\n\n while ((matches = dateRegex.exec(text)) !== null) {\n let date = new Date(matches[0]);\n let timeElapsed =\n (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);\n text = text.replace(\n matches[0],\n Math.floor(timeElapsed).toString() + ' days ago.'\n );\n }\n return text;\n }\n\n camelToString(camelCase: string): string {\n return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {\n return str.toUpperCase();\n });\n }\n\n stringToBoolean(str: string): boolean {\n log.info(`Converting string to boolean: ${str}`);\n const positiveKeywords = [\n 'true',\n 'contains',\n 'confirms',\n 'yes',\n 'affirmative',\n 'matches',\n 'exists',\n 'present',\n 'absolutely',\n 'certainly',\n 'definitely',\n 'indeed',\n 'did have',\n 'showed',\n 'revealed',\n ];\n const lowerStr = str.toLowerCase();\n return positiveKeywords.some((keyword) => lowerStr.includes(keyword));\n }\n\n async textSplitter(\n text: string,\n chunkSize: number = 3900,\n chunkOverlap: number = 0\n ): Promise<string[]> {\n const textSplitter = new CharacterTextSplitter({\n chunkSize: chunkSize,\n chunkOverlap: chunkOverlap,\n });\n const texts = await textSplitter.splitText(text);\n // Log the number of chunks created\n if (texts.length === 0) {\n log.warn('No text chunks created. Please check the input text.');\n return [];\n }\n if (texts.length > 100) {\n log.warn(\n `Warning: More than 100 text chunks created (${texts.length}). This may affect performance.`\n );\n }\n if (chunkSize < 1000) {\n log.warn(\n `Warning: Chunk size is less than 1000 characters (${chunkSize}). This may lead to very small chunks.`\n );\n }\n log.info(\n `Text split into ${texts.length} chunks with size ${chunkSize} and overlap ${chunkOverlap}`\n );\n return texts;\n }\n\n printValues(obj: any) {\n log.info(`Processing Rule: ${obj.name} for ${obj.context}`);\n // For each obj.expression:arg:where\n if (obj.expression && obj.expression.arg && obj.expression.arg.where) {\n // for each args in obj.expression.arg.where, extract the nested key called \"value\"\n const statements = this.extractObjectsByKey(\n obj.expression.arg.where,\n 'value'\n );\n return statements.join(' ').replace(/,/g, ' ');\n }\n // return statements array as a string seperated by space\n return '';\n }\n\n extractObjectsByKey(obj: any, key: string): any[] {\n const results: any[] = [];\n\n function traverse(obj: any) {\n for (const currentKey in obj) {\n if (obj.hasOwnProperty(currentKey)) {\n if (currentKey === key) {\n results.push(obj[currentKey]);\n }\n if (typeof obj[currentKey] === 'object' && obj[currentKey] !== null) {\n traverse(obj[currentKey]);\n }\n }\n }\n }\n\n traverse(obj);\n return results;\n }\n\n _printValues(obj: any) {\n for (var key in obj) {\n if (typeof obj[key] === 'object') {\n this._printValues(obj[key]);\n } else {\n this.string_expression += obj[key] + ' ';\n }\n }\n const _eliminate = [\n 'true',\n 'false',\n 'null',\n 'undefined',\n 'String',\n 'Number',\n 'Object',\n 'Array',\n 'Boolean',\n 'value',\n 'Type',\n 'Specifier',\n 'Named',\n ];\n _eliminate.forEach((element) => {\n const regex = new RegExp(element, 'g');\n this.string_expression = this.string_expression.replace(regex, '');\n });\n this.string_expression = this.string_expression.replace(\n /(?:https?|ftp):\\/\\/[\\n\\S]+/g,\n ''\n );\n return this.camelToString(this.string_expression);\n }\n\n async chain(input: any) {\n // Create a chain using RunnableSequence, RunnablePassthrough and RunnableParallel\n // input has two properties: expression and context\n // expression goes through mapQuery and parallely\n // context goes through textSplitter and mapDoc\n // Finally reduceChain is called with the results of mapQuery and mapDoc\n // LCEL-based implementation using RunnableSequence, RunnableParallel, and RunnablePassthrough\n const { RunnableSequence, RunnableParallel, RunnablePassthrough } =\n await import('@langchain/core/runnables');\n\n const mapQueryChain = RunnablePassthrough.assign({\n query: async (input: any) =>\n this.mapQuery.chain({\n input: { expression: input.input.expression },\n }),\n });\n\n const mapDocChain = RunnablePassthrough.assign({\n documents: async (input: any) => {\n const textChunks = await this.textSplitter(input.input.context);\n return Promise.all(\n textChunks.map((chunk) =>\n this.mapDoc.chain({\n input: { document: chunk, statements: input.input.expression },\n })\n )\n );\n },\n });\n\n const parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);\n\n const sequence = RunnableSequence.from([\n parallelChain,\n async (results: any) => {\n /* results is an array: [{ query: ... }, { documents: [...] }]\n{\n \"0\": {\n \"input\": {\n \"expression\": \"0 Visual foot exam showed active infection?\",\n \"context\": \"Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. \"\n },\n \"query\": \"The text indicates a question about whether a visual foot exam revealed an active infection.\\n\"\n },\n \"1\": {\n \"input\": {\n \"expression\": \"0 Visual foot exam showed active infection?\",\n \"context\": \"Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. \"\n },\n \"documents\": [\n \"26 days ago, a visual foot examination revealed no dryness, cracking, ulceration, lesions, discoloration, fungal infection, ingrown nails, cyanosis, pallor, edema, bunions, hammertoes, or Charcot foot deformities. Circulation and capillary refill were normal. However, the exam showed signs\"\n ]\n }\n}\n */\n log.info(`Results from parallel chain: ${JSON.stringify(results)}`);\n const expression = results[0].input.expression;\n const query = results[0].query;\n const documents = results[1].documents;\n return this.reduceChain.chain({\n input: {\n facts: documents,\n query: query + ' ' + expression,\n },\n });\n },\n (result: any) => this.stringToBoolean(result),\n ]);\n\n return sequence.invoke(input);\n }\n}\n"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","chat_model","runnable","camelize","constructor","snake_case","ChatPromptTemplate","fromTemplate","PromptTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","_chain","_asyncToGenerator","_regeneratorRuntime","mark","_callee","input","response","aiMessage","wrap","_callee$","_context","prev","next","RunnableSequence","from","RunnablePassthrough","invoke","sent","AIMessage","abrupt","content","stop","_x","apply","arguments","BaseAgent","run","_run","agent","agentExecutor","createStructuredChatAgent","AgentExecutor","handleParsingErrors","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool","MapQuery","_BaseChain","_len","length","Array","_key","concat","MapDoc","ReduceChain","log","Logger","LLMLoop","string_expression","mapQuery","mapDoc","reduceChain","checkAssertion","_checkAssertion","expression","context","_expression","_content","_input","result","_context2","printValues","JSON","parse","error","info","undefined","warn","forEach","element","contentItem","atob","attachment","data","value","findDatesAndConvertToTimeElapsed","_x2","checkMention","_checkMention","_callee2","_callee2$","_context3","_x3","_x4","checkNegation","_checkNegation","_callee3","_callee3$","_context4","_x5","_x6","text","dateRegex","matches","currentDate","Date","exec","date","timeElapsed","getTime","Math","floor","toString","camelToString","camelCase","stringToBoolean","positiveKeywords","lowerStr","some","keyword","includes","textSplitter","_textSplitter","_callee4","chunkSize","chunkOverlap","texts","_callee4$","_context5","CharacterTextSplitter","splitText","_x7","_x8","_x9","obj","arg","where","statements","extractObjectsByKey","join","key","results","traverse","currentKey","hasOwnProperty","push","_printValues","_this2","_eliminate","regex","RegExp","_callee8","_this3","_yield$import","RunnableParallel","mapQueryChain","mapDocChain","parallelChain","sequence","_callee8$","_context9","assign","query","_query","_callee5","_callee5$","_context6","_x1","documents","_documents","_callee6","textChunks","_callee6$","_context7","Promise","all","map","chunk","document","_x10","_callee7","_callee7$","_context8","stringify","facts","_x11","_x0"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;AAcG;AAEH,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAIC,CAAM,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