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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { BaseChain } from './chain';
2
2
  export { BaseAgent } from './agent';
3
3
  export { BaseTool } from './tool';
4
+ export { LLMLoop } from './llm_loop';
@@ -9,13 +9,15 @@ export declare class LLMLoop extends BaseChain {
9
9
  mapQuery: MapQuery;
10
10
  mapDoc: MapDoc;
11
11
  reduceChain: ReduceChain;
12
- checkAssertion(expression: string, context: string): Promise<boolean>;
13
- checkMention(expression: string, context: string): Promise<boolean>;
14
- checkNegation(expression: string, context: string): Promise<boolean>;
12
+ checkAssertion(expression: string, context: any): Promise<boolean>;
13
+ checkMention(expression: string, context: any): Promise<boolean>;
14
+ checkNegation(expression: string, context: any): Promise<boolean>;
15
15
  findDatesAndConvertToTimeElapsed(text: string): string;
16
16
  camelToString(camelCase: string): string;
17
17
  stringToBoolean(str: string): boolean;
18
18
  textSplitter(text: string, chunkSize?: number, chunkOverlap?: number): Promise<string[]>;
19
19
  printValues(obj: any): string;
20
+ extractObjectsByKey(obj: any, key: string): any[];
21
+ _printValues(obj: any): string;
20
22
  chain(input: any): Promise<boolean>;
21
23
  }
@@ -1 +1,4 @@
1
1
  export { MapQuery } from './map_query';
2
+ export { MapDoc } from './map_doc';
3
+ export { ReduceChain } from './reduce';
4
+ export { LLMLoop } from './base';
@@ -7,6 +7,8 @@ var runnables = require('@langchain/core/runnables');
7
7
  var messages = require('@langchain/core/messages');
8
8
  var agents = require('langchain/agents');
9
9
  var tools = require('langchain/tools');
10
+ var textsplitters = require('@langchain/textsplitters');
11
+ var tslog = require('tslog');
10
12
 
11
13
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
12
14
  try {
@@ -49,7 +51,7 @@ function _regeneratorRuntime() {
49
51
  a = o.asyncIterator || "@@asyncIterator",
50
52
  u = o.toStringTag || "@@toStringTag";
51
53
  function c(t, r, e, n) {
52
- return Object.defineProperty(t, r, {
54
+ Object.defineProperty(t, r, {
53
55
  value: e,
54
56
  enumerable: !n,
55
57
  configurable: !n,
@@ -200,7 +202,7 @@ function _regeneratorRuntime() {
200
202
  }
201
203
  throw new TypeError(typeof r + " is not iterable");
202
204
  }
203
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) {
205
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), c(GeneratorFunctionPrototype, u, GeneratorFunction.displayName = "GeneratorFunction"), r.isGeneratorFunction = function (t) {
204
206
  var r = "function" == typeof t && t.constructor;
205
207
  return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
206
208
  }, r.mark = function (t) {
@@ -541,7 +543,431 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
541
543
  return BaseTool;
542
544
  }(tools.DynamicStructuredTool);
543
545
 
546
+ var MapQuery = /*#__PURE__*/function (_BaseChain) {
547
+ function MapQuery() {
548
+ var _this;
549
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
550
+ args[_key] = arguments[_key];
551
+ }
552
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
553
+ _this.name = 'MapQuery';
554
+ _this.description = 'Map a CQL query to a natural language.';
555
+ _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: ";
556
+ return _this;
557
+ }
558
+ _inheritsLoose(MapQuery, _BaseChain);
559
+ return MapQuery;
560
+ }(BaseChain);
561
+
562
+ var MapDoc = /*#__PURE__*/function (_BaseChain) {
563
+ function MapDoc() {
564
+ var _this;
565
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
566
+ args[_key] = arguments[_key];
567
+ }
568
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
569
+ _this.name = 'MapDoc';
570
+ _this.description = 'Map a set of documents to facts.';
571
+ _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: ";
572
+ return _this;
573
+ }
574
+ _inheritsLoose(MapDoc, _BaseChain);
575
+ return MapDoc;
576
+ }(BaseChain);
577
+
578
+ var ReduceChain = /*#__PURE__*/function (_BaseChain) {
579
+ function ReduceChain() {
580
+ var _this;
581
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
582
+ args[_key] = arguments[_key];
583
+ }
584
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
585
+ _this.name = 'Reduce';
586
+ _this.description = 'Reduce a set of documents to binary answer.';
587
+ _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: ";
588
+ return _this;
589
+ }
590
+ _inheritsLoose(ReduceChain, _BaseChain);
591
+ return ReduceChain;
592
+ }(BaseChain);
593
+
594
+ var log = /*#__PURE__*/new tslog.Logger();
595
+ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
596
+ function LLMLoop() {
597
+ var _this;
598
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
599
+ args[_key] = arguments[_key];
600
+ }
601
+ _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
602
+ // Implement the LLM loop logic here
603
+ _this.string_expression = '';
604
+ _this.name = 'LLMLoop';
605
+ _this.description = 'Base LLM Loop.';
606
+ _this.mapQuery = new MapQuery(_this.container, '', '');
607
+ _this.mapDoc = new MapDoc(_this.container, '', '');
608
+ _this.reduceChain = new ReduceChain(_this.container, '', '');
609
+ return _this;
610
+ }
611
+ _inheritsLoose(LLMLoop, _BaseChain);
612
+ var _proto = LLMLoop.prototype;
613
+ _proto.checkAssertion = /*#__PURE__*/function () {
614
+ var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
615
+ var _expression, _context, _content, _input, result;
616
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
617
+ while (1) switch (_context2.prev = _context2.next) {
618
+ case 0:
619
+ _expression = '';
620
+ try {
621
+ // Check if expression is a valid JSON string
622
+ _expression = this.printValues(JSON.parse(expression));
623
+ } catch (error) {
624
+ _expression = expression; // If not, use the expression as is
625
+ }
626
+ log.info("Checking assertion with expression: " + _expression);
627
+ // Initialize context and content
628
+ _context = undefined;
629
+ _content = '';
630
+ try {
631
+ _context = JSON.parse(context);
632
+ } catch (error) {
633
+ _context = context; // If not, use the context as is
634
+ log.warn("Context is not a valid JSON string: " + context);
635
+ log.warn("Using context as a string: " + _context);
636
+ }
637
+ try {
638
+ // Check if context is a valid JSON string
639
+ _context = JSON.parse(context);
640
+ _context.forEach(function (element) {
641
+ element.content.forEach(function (contentItem) {
642
+ _content += atob(contentItem.attachment.data.value);
643
+ });
644
+ });
645
+ } catch (error) {
646
+ _content = context; // If not, use the context as is
647
+ log.warn("Context is not a valid JSON : " + context);
648
+ log.warn("Using context as a string: " + _content);
649
+ }
650
+ _content = this.findDatesAndConvertToTimeElapsed(_content.replace(/(\r\n|\n|\r)/gm, ' '));
651
+ log.info("Checking assertion with context: " + _content);
652
+ _input = {
653
+ input: {
654
+ expression: _expression,
655
+ context: _content
656
+ }
657
+ };
658
+ _context2.next = 12;
659
+ return this.chain(_input);
660
+ case 12:
661
+ result = _context2.sent;
662
+ log.info("Assertion check result: " + result);
663
+ return _context2.abrupt("return", result);
664
+ case 15:
665
+ case "end":
666
+ return _context2.stop();
667
+ }
668
+ }, _callee, this);
669
+ }));
670
+ function checkAssertion(_x, _x2) {
671
+ return _checkAssertion.apply(this, arguments);
672
+ }
673
+ return checkAssertion;
674
+ }();
675
+ _proto.checkMention = /*#__PURE__*/function () {
676
+ var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(expression, context) {
677
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
678
+ while (1) switch (_context3.prev = _context3.next) {
679
+ case 0:
680
+ if (!(expression && context)) {
681
+ _context3.next = 2;
682
+ break;
683
+ }
684
+ return _context3.abrupt("return", true);
685
+ case 2:
686
+ return _context3.abrupt("return", false);
687
+ case 3:
688
+ case "end":
689
+ return _context3.stop();
690
+ }
691
+ }, _callee2);
692
+ }));
693
+ function checkMention(_x3, _x4) {
694
+ return _checkMention.apply(this, arguments);
695
+ }
696
+ return checkMention;
697
+ }();
698
+ _proto.checkNegation = /*#__PURE__*/function () {
699
+ var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(expression, context) {
700
+ return _regeneratorRuntime().wrap(function _callee3$(_context4) {
701
+ while (1) switch (_context4.prev = _context4.next) {
702
+ case 0:
703
+ if (!(expression && context)) {
704
+ _context4.next = 2;
705
+ break;
706
+ }
707
+ return _context4.abrupt("return", true);
708
+ case 2:
709
+ return _context4.abrupt("return", false);
710
+ case 3:
711
+ case "end":
712
+ return _context4.stop();
713
+ }
714
+ }, _callee3);
715
+ }));
716
+ function checkNegation(_x5, _x6) {
717
+ return _checkNegation.apply(this, arguments);
718
+ }
719
+ return checkNegation;
720
+ }();
721
+ _proto.findDatesAndConvertToTimeElapsed = function findDatesAndConvertToTimeElapsed(text) {
722
+ // Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'
723
+ var dateRegex = /(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g;
724
+ var matches;
725
+ var currentDate = new Date();
726
+ while ((matches = dateRegex.exec(text)) !== null) {
727
+ var date = new Date(matches[0]);
728
+ var timeElapsed = (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);
729
+ text = text.replace(matches[0], Math.floor(timeElapsed).toString() + ' days ago.');
730
+ }
731
+ return text;
732
+ };
733
+ _proto.camelToString = function camelToString(camelCase) {
734
+ return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
735
+ return str.toUpperCase();
736
+ });
737
+ };
738
+ _proto.stringToBoolean = function stringToBoolean(str) {
739
+ log.info("Converting string to boolean: " + str);
740
+ var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed', 'did have', 'showed', 'revealed'];
741
+ var lowerStr = str.toLowerCase();
742
+ return positiveKeywords.some(function (keyword) {
743
+ return lowerStr.includes(keyword);
744
+ });
745
+ };
746
+ _proto.textSplitter = /*#__PURE__*/function () {
747
+ var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text, chunkSize, chunkOverlap) {
748
+ var textSplitter, texts;
749
+ return _regeneratorRuntime().wrap(function _callee4$(_context5) {
750
+ while (1) switch (_context5.prev = _context5.next) {
751
+ case 0:
752
+ if (chunkSize === void 0) {
753
+ chunkSize = 3900;
754
+ }
755
+ if (chunkOverlap === void 0) {
756
+ chunkOverlap = 0;
757
+ }
758
+ textSplitter = new textsplitters.CharacterTextSplitter({
759
+ chunkSize: chunkSize,
760
+ chunkOverlap: chunkOverlap
761
+ });
762
+ _context5.next = 5;
763
+ return textSplitter.splitText(text);
764
+ case 5:
765
+ texts = _context5.sent;
766
+ if (!(texts.length === 0)) {
767
+ _context5.next = 9;
768
+ break;
769
+ }
770
+ log.warn('No text chunks created. Please check the input text.');
771
+ return _context5.abrupt("return", []);
772
+ case 9:
773
+ if (texts.length > 100) {
774
+ log.warn("Warning: More than 100 text chunks created (" + texts.length + "). This may affect performance.");
775
+ }
776
+ if (chunkSize < 1000) {
777
+ log.warn("Warning: Chunk size is less than 1000 characters (" + chunkSize + "). This may lead to very small chunks.");
778
+ }
779
+ log.info("Text split into " + texts.length + " chunks with size " + chunkSize + " and overlap " + chunkOverlap);
780
+ return _context5.abrupt("return", texts);
781
+ case 13:
782
+ case "end":
783
+ return _context5.stop();
784
+ }
785
+ }, _callee4);
786
+ }));
787
+ function textSplitter(_x7, _x8, _x9) {
788
+ return _textSplitter.apply(this, arguments);
789
+ }
790
+ return textSplitter;
791
+ }();
792
+ _proto.printValues = function printValues(obj) {
793
+ log.info("Processing Rule: " + obj.name + " for " + obj.context);
794
+ // For each obj.expression:arg:where
795
+ if (obj.expression && obj.expression.arg && obj.expression.arg.where) {
796
+ // for each args in obj.expression.arg.where, extract the nested key called "value"
797
+ var statements = this.extractObjectsByKey(obj.expression.arg.where, 'value');
798
+ return statements.join(' ').replace(/,/g, ' ');
799
+ }
800
+ // return statements array as a string seperated by space
801
+ return '';
802
+ };
803
+ _proto.extractObjectsByKey = function extractObjectsByKey(obj, key) {
804
+ var results = [];
805
+ function traverse(obj) {
806
+ for (var currentKey in obj) {
807
+ if (obj.hasOwnProperty(currentKey)) {
808
+ if (currentKey === key) {
809
+ results.push(obj[currentKey]);
810
+ }
811
+ if (typeof obj[currentKey] === 'object' && obj[currentKey] !== null) {
812
+ traverse(obj[currentKey]);
813
+ }
814
+ }
815
+ }
816
+ }
817
+ traverse(obj);
818
+ return results;
819
+ };
820
+ _proto._printValues = function _printValues(obj) {
821
+ var _this2 = this;
822
+ for (var key in obj) {
823
+ if (typeof obj[key] === 'object') {
824
+ this._printValues(obj[key]);
825
+ } else {
826
+ this.string_expression += obj[key] + ' ';
827
+ }
828
+ }
829
+ var _eliminate = ['true', 'false', 'null', 'undefined', 'String', 'Number', 'Object', 'Array', 'Boolean', 'value', 'Type', 'Specifier', 'Named'];
830
+ _eliminate.forEach(function (element) {
831
+ var regex = new RegExp(element, 'g');
832
+ _this2.string_expression = _this2.string_expression.replace(regex, '');
833
+ });
834
+ this.string_expression = this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
835
+ return this.camelToString(this.string_expression);
836
+ };
837
+ _proto.chain = /*#__PURE__*/function () {
838
+ var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(input) {
839
+ var _this3 = this;
840
+ var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQueryChain, mapDocChain, parallelChain, sequence;
841
+ return _regeneratorRuntime().wrap(function _callee8$(_context9) {
842
+ while (1) switch (_context9.prev = _context9.next) {
843
+ case 0:
844
+ _context9.next = 2;
845
+ return import('@langchain/core/runnables');
846
+ case 2:
847
+ _yield$import = _context9.sent;
848
+ RunnableSequence = _yield$import.RunnableSequence;
849
+ RunnableParallel = _yield$import.RunnableParallel;
850
+ RunnablePassthrough = _yield$import.RunnablePassthrough;
851
+ mapQueryChain = RunnablePassthrough.assign({
852
+ query: function () {
853
+ var _query = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(input) {
854
+ return _regeneratorRuntime().wrap(function _callee5$(_context6) {
855
+ while (1) switch (_context6.prev = _context6.next) {
856
+ case 0:
857
+ return _context6.abrupt("return", _this3.mapQuery.chain({
858
+ input: {
859
+ expression: input.input.expression
860
+ }
861
+ }));
862
+ case 1:
863
+ case "end":
864
+ return _context6.stop();
865
+ }
866
+ }, _callee5);
867
+ }));
868
+ function query(_x1) {
869
+ return _query.apply(this, arguments);
870
+ }
871
+ return query;
872
+ }()
873
+ });
874
+ mapDocChain = RunnablePassthrough.assign({
875
+ documents: function () {
876
+ var _documents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
877
+ var textChunks;
878
+ return _regeneratorRuntime().wrap(function _callee6$(_context7) {
879
+ while (1) switch (_context7.prev = _context7.next) {
880
+ case 0:
881
+ _context7.next = 2;
882
+ return _this3.textSplitter(input.input.context);
883
+ case 2:
884
+ textChunks = _context7.sent;
885
+ return _context7.abrupt("return", Promise.all(textChunks.map(function (chunk) {
886
+ return _this3.mapDoc.chain({
887
+ input: {
888
+ document: chunk,
889
+ statements: input.input.expression
890
+ }
891
+ });
892
+ })));
893
+ case 4:
894
+ case "end":
895
+ return _context7.stop();
896
+ }
897
+ }, _callee6);
898
+ }));
899
+ function documents(_x10) {
900
+ return _documents.apply(this, arguments);
901
+ }
902
+ return documents;
903
+ }()
904
+ });
905
+ parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
906
+ sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
907
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
908
+ var expression, query, documents;
909
+ return _regeneratorRuntime().wrap(function _callee7$(_context8) {
910
+ while (1) switch (_context8.prev = _context8.next) {
911
+ case 0:
912
+ /* results is an array: [{ query: ... }, { documents: [...] }]
913
+ {
914
+ "0": {
915
+ "input": {
916
+ "expression": "0 Visual foot exam showed active infection?",
917
+ "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. "
918
+ },
919
+ "query": "The text indicates a question about whether a visual foot exam revealed an active infection.\n"
920
+ },
921
+ "1": {
922
+ "input": {
923
+ "expression": "0 Visual foot exam showed active infection?",
924
+ "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. "
925
+ },
926
+ "documents": [
927
+ "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"
928
+ ]
929
+ }
930
+ }
931
+ */
932
+ log.info("Results from parallel chain: " + JSON.stringify(results));
933
+ expression = results[0].input.expression;
934
+ query = results[0].query;
935
+ documents = results[1].documents;
936
+ return _context8.abrupt("return", _this3.reduceChain.chain({
937
+ input: {
938
+ facts: documents,
939
+ query: query + ' ' + expression
940
+ }
941
+ }));
942
+ case 5:
943
+ case "end":
944
+ return _context8.stop();
945
+ }
946
+ }, _callee7);
947
+ }));
948
+ return function (_x11) {
949
+ return _ref.apply(this, arguments);
950
+ };
951
+ }()), function (result) {
952
+ return _this3.stringToBoolean(result);
953
+ }]);
954
+ return _context9.abrupt("return", sequence.invoke(input));
955
+ case 11:
956
+ case "end":
957
+ return _context9.stop();
958
+ }
959
+ }, _callee8);
960
+ }));
961
+ function chain(_x0) {
962
+ return _chain.apply(this, arguments);
963
+ }
964
+ return chain;
965
+ }();
966
+ return LLMLoop;
967
+ }(BaseChain);
968
+
544
969
  exports.BaseAgent = BaseAgent;
545
970
  exports.BaseChain = BaseChain;
546
971
  exports.BaseTool = BaseTool;
972
+ exports.LLMLoop = LLMLoop;
547
973
  //# sourceMappingURL=medpromptjs.cjs.development.js.map