medpromptjs 0.3.1 → 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.
@@ -17,5 +17,7 @@ export declare class LLMLoop extends BaseChain {
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
  }
@@ -51,7 +51,7 @@ function _regeneratorRuntime() {
51
51
  a = o.asyncIterator || "@@asyncIterator",
52
52
  u = o.toStringTag || "@@toStringTag";
53
53
  function c(t, r, e, n) {
54
- return Object.defineProperty(t, r, {
54
+ Object.defineProperty(t, r, {
55
55
  value: e,
56
56
  enumerable: !n,
57
57
  configurable: !n,
@@ -202,7 +202,7 @@ function _regeneratorRuntime() {
202
202
  }
203
203
  throw new TypeError(typeof r + " is not iterable");
204
204
  }
205
- 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) {
206
206
  var r = "function" == typeof t && t.constructor;
207
207
  return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
208
208
  }, r.mark = function (t) {
@@ -552,7 +552,7 @@ var MapQuery = /*#__PURE__*/function (_BaseChain) {
552
552
  _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
553
553
  _this.name = 'MapQuery';
554
554
  _this.description = 'Map a CQL query to a natural language.';
555
- _this.template = "\n You are an assistant that can convert a CQL query to a natural language.\nYou should give a single line answer>> as in the example below.\nExample:\n\nCQL: exists (\n [DocumentReference] D\n where D.allergies=\"Penicillin\"\n and D.complaint=\"Headache\"\n and D.complaint=\"Weakness\" or D.complaint=\"Numbness\"\n and D.findings=\"Intact sensation to light touch\"\n )\n\nanswer>> Penicillin allergy, Headache, Weakness, Numbness, and Intact sensation to light touch as findings?\n\nCQL: exists (\n [DocumentReference] D\n where D.diagnosis=\"Diverticulitis\"\n and D.complaint=\"Fever\"\n and D.procedure=\"Colon resection\"\n and not D.finding=\"Fluid collection\"\n )\n\nanswer>> Diverticulitis diagnosis, Fever complaint, Colon resection procedure, and no Fluid collection finding?\n\nNow convert the following CQL query to a natural language.\nCQL: {expression}\n\nanswer>>\n ";
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
556
  return _this;
557
557
  }
558
558
  _inheritsLoose(MapQuery, _BaseChain);
@@ -568,7 +568,7 @@ var MapDoc = /*#__PURE__*/function (_BaseChain) {
568
568
  _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
569
569
  _this.name = 'MapDoc';
570
570
  _this.description = 'Map a set of documents to facts.';
571
- _this.template = "\n You will be given a document and a question.\n\n Summarize the document chunk commenting on: {query} \n\n Do not include absent or negative mentions.\n\n document: {document} \n\n Summary:: ";
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
572
  return _this;
573
573
  }
574
574
  _inheritsLoose(MapDoc, _BaseChain);
@@ -584,7 +584,7 @@ var ReduceChain = /*#__PURE__*/function (_BaseChain) {
584
584
  _this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
585
585
  _this.name = 'Reduce';
586
586
  _this.description = 'Reduce a set of documents to binary answer.';
587
- _this.template = "\n You will be given facts and a question to answer with ONLY a yes or no.\n\n Do not include the facts in the answer.\n\n Say yes if the facts mentions all aspects of the question, else say no.\n\n facts: {facts} \n\n question: Does the facts mention {question} Say YES OR NO Only::";
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
588
  return _this;
589
589
  }
590
590
  _inheritsLoose(ReduceChain, _BaseChain);
@@ -612,13 +612,11 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
612
612
  var _proto = LLMLoop.prototype;
613
613
  _proto.checkAssertion = /*#__PURE__*/function () {
614
614
  var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
615
- var _expression, _context, _content, _input;
615
+ var _expression, _context, _content, _input, result;
616
616
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
617
617
  while (1) switch (_context2.prev = _context2.next) {
618
618
  case 0:
619
619
  _expression = '';
620
- _context = undefined;
621
- _content = '';
622
620
  try {
623
621
  // Check if expression is a valid JSON string
624
622
  _expression = this.printValues(JSON.parse(expression));
@@ -626,24 +624,44 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
626
624
  _expression = expression; // If not, use the expression as is
627
625
  }
628
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
+ }
629
637
  try {
630
638
  // Check if context is a valid JSON string
631
639
  _context = JSON.parse(context);
632
640
  _context.forEach(function (element) {
633
- _content += atob(element.content[0].attachment.data.value);
641
+ element.content.forEach(function (contentItem) {
642
+ _content += atob(contentItem.attachment.data.value);
643
+ });
634
644
  });
635
645
  } catch (error) {
636
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);
637
649
  }
638
650
  _content = this.findDatesAndConvertToTimeElapsed(_content.replace(/(\r\n|\n|\r)/gm, ' '));
651
+ log.info("Checking assertion with context: " + _content);
639
652
  _input = {
640
653
  input: {
641
654
  expression: _expression,
642
655
  context: _content
643
656
  }
644
657
  };
645
- return _context2.abrupt("return", this.chain(_input));
646
- case 9:
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:
647
665
  case "end":
648
666
  return _context2.stop();
649
667
  }
@@ -719,7 +737,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
719
737
  };
720
738
  _proto.stringToBoolean = function stringToBoolean(str) {
721
739
  log.info("Converting string to boolean: " + str);
722
- var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed'];
740
+ var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed', 'did have', 'showed', 'revealed'];
723
741
  var lowerStr = str.toLowerCase();
724
742
  return positiveKeywords.some(function (keyword) {
725
743
  return lowerStr.includes(keyword);
@@ -772,10 +790,38 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
772
790
  return textSplitter;
773
791
  }();
774
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) {
775
821
  var _this2 = this;
776
822
  for (var key in obj) {
777
823
  if (typeof obj[key] === 'object') {
778
- this.printValues(obj[key]);
824
+ this._printValues(obj[key]);
779
825
  } else {
780
826
  this.string_expression += obj[key] + ' ';
781
827
  }
@@ -840,7 +886,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
840
886
  return _this3.mapDoc.chain({
841
887
  input: {
842
888
  document: chunk,
843
- question: input.input.expression
889
+ statements: input.input.expression
844
890
  }
845
891
  });
846
892
  })));
@@ -859,20 +905,41 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
859
905
  parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
860
906
  sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
861
907
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
862
- var query, documents;
908
+ var expression, query, documents;
863
909
  return _regeneratorRuntime().wrap(function _callee7$(_context8) {
864
910
  while (1) switch (_context8.prev = _context8.next) {
865
911
  case 0:
866
- // results is an array: [{ query: ... }, { documents: [...] }]
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;
867
934
  query = results[0].query;
868
935
  documents = results[1].documents;
869
936
  return _context8.abrupt("return", _this3.reduceChain.chain({
870
937
  input: {
871
- query: query,
872
- facts: documents
938
+ facts: documents,
939
+ query: query + ' ' + expression
873
940
  }
874
941
  }));
875
- case 3:
942
+ case 5:
876
943
  case "end":
877
944
  return _context8.stop();
878
945
  }
@@ -1 +1 @@
1
- {"version":3,"file":"medpromptjs.cjs.development.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 a CQL query to a natural language.\nYou should give a single line answer>> as in the example below.\nExample:\n\nCQL: exists (\n [DocumentReference] D\n where D.allergies=\"Penicillin\"\n and D.complaint=\"Headache\"\n and D.complaint=\"Weakness\" or D.complaint=\"Numbness\"\n and D.findings=\"Intact sensation to light touch\"\n )\n\nanswer>> Penicillin allergy, Headache, Weakness, Numbness, and Intact sensation to light touch as findings?\n\nCQL: exists (\n [DocumentReference] D\n where D.diagnosis=\"Diverticulitis\"\n and D.complaint=\"Fever\"\n and D.procedure=\"Colon resection\"\n and not D.finding=\"Fluid collection\"\n )\n\nanswer>> Diverticulitis diagnosis, Fever complaint, Colon resection procedure, and no Fluid collection finding?\n\nNow convert the following CQL query to a natural language.\nCQL: {expression}\n\nanswer>>\n `;\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 a question.\\n\n Summarize the document chunk commenting on: {query} \\n\n Do not include absent or negative mentions.\\n\n document: {document} \\n\n Summary:: `;\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 You will be given facts and a question to answer with ONLY a yes or no.\\n\n Do not include the facts in the answer.\\n\n Say yes if the facts mentions all aspects of the question, else say no.\\n\n facts: {facts} \\n\n question: Does the facts mention {question} Say YES OR NO Only::`;\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 let _context: any = undefined;\n let _content: 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 log.info(`Checking assertion with expression: ${_expression}`);\n try {\n // Check if context is a valid JSON string\n _context = JSON.parse(context);\n _context.forEach(\n (element: {\n content: { attachment: { data: { value: string } } }[];\n }) => {\n _content += atob(element.content[0].attachment.data.value);\n }\n );\n } catch (error) {\n _content = context; // If not, use the context as is\n }\n\n _content = this.findDatesAndConvertToTimeElapsed(\n _content.replace(/(\\r\\n|\\n|\\r)/gm, ' ')\n );\n const _input = {\n input: {\n expression: _expression,\n context: _content,\n },\n };\n\n return this.chain(_input);\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 ];\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 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, question: 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 const query = results[0].query;\n const documents = results[1].documents;\n return this.reduceChain.chain({\n input: {\n query: query,\n facts: documents,\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","_context2","undefined","printValues","JSON","parse","error","info","forEach","element","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","warn","_x7","_x8","_x9","obj","_this2","key","_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","question","_x10","_callee7","results","_callee7$","_context8","facts","_x11","result","_x0"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;AAcG;AAEH,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAIC,CAAM,EAAEC,CAAS,EAAEC,CAAS,EAAI;EAC5C,IAAI;IACF,OAAOF,CAAC,CAACG,OAAO,CAACF,CAAC,GAAG,GAAG,GAAGC,CAAC,CAAC,CAAA;GAC9B,CAAC,OAAOE,CAAC,EAAE;AACV,IAAA,OAAOJ,CAAC,CAACG,OAAO,CA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AAkH,QAAA,CAAA,CAAA;KAC9B,CAAA,CAAA,CAAA;IAAA,SAjDKxI,KAAKA,CAAA6K,GAAA,EAAA;AAAA,MAAA,OAAA5K,MAAA,CAAAuB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAALzB,KAAK,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAAuD,OAAA,CAAA;AAAA,CAAA,CAtKgB/E,SAAS;;;;;;;"}
1
+ {"version":3,"file":"medpromptjs.cjs.development.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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GlG,UAAAA;AACtB,yBAAA;AACF,uBAAA,CAAC,CAAA,CAAA;AAAA,oBAAA,KAAA,CAAA,CAAA;AAAA,oBAAA,KAAA,KAAA;sBAAA,OAAAsH,SAAA,CAAA9J,IAAA,EAAA,CAAA;AAAA,mBAAA;AAAA,iBAAA,EAAA4J,QAAA,CAAA,CAAA;eACH,CAAA,CAAA,CAAA;AAAA,cAAA,OAAA,UAAAK,IAAA,EAAA;AAAA,gBAAA,OAAA/I,IAAA,CAAAhB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,eAAA,CAAA;AAAA,aAAA,EAAA,GACD,UAAC0C,MAAW,EAAA;AAAA,cAAA,OAAKmF,MAAI,CAACrC,eAAe,CAAC9C,MAAM,CAAC,CAAA;AAAA,aAAA,CAC9C,CAAC,CAAA;YAAA,OAAA2F,SAAA,CAAA1I,MAAA,CAAA,QAAA,EAEKwI,QAAQ,CAAC3I,MAAM,CAACX,KAAK,CAAC,CAAA,CAAA;AAAA,UAAA,KAAA,EAAA,CAAA;AAAA,UAAA,KAAA,KAAA;YAAA,OAAAwJ,SAAA,CAAAxI,IAAA,EAAA,CAAA;AAAA,SAAA;AAAA,OAAA,EAAA+H,QAAA,CAAA,CAAA;KAC9B,CAAA,CAAA,CAAA;IAAA,SAtEKrJ,KAAKA,CAAAwL,GAAA,EAAA;AAAA,MAAA,OAAAvL,MAAA,CAAAuB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAALzB,KAAK,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAAuD,OAAA,CAAA;AAAA,CAAA,CAtNgB/E,SAAS;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@langchain/core/prompts"),e=require("@langchain/core/runnables"),n=require("@langchain/core/messages"),r=require("langchain/agents"),o=require("langchain/tools"),i=require("@langchain/textsplitters"),a=require("tslog");function s(t,e,n,r,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void n(t)}s.done?e(u):Promise.resolve(u).then(r,o)}function u(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var i=t.apply(e,n);function a(t){s(i,r,o,a,u,"next",t)}function u(t){s(i,r,o,a,u,"throw",t)}a(void 0)}))}}function c(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,l(t,e)}function h(){h=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function u(t,e,n,r){return Object.defineProperty(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r})}try{u({},"")}catch(t){u=function(t,e,n){return t[e]=n}}function c(e,n,r,o){var i=Object.create((n&&n.prototype instanceof f?n:f).prototype);return u(i,"_invoke",function(e,n,r){var o=1;return function(i,a){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw a;return{value:t,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var u=k(s,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(1===o)throw o=4,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=3;var c=l(e,n,r);if("normal"===c.type){if(o=r.done?4:2,c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(o=4,r.method="throw",r.arg=c.arg)}}}(e,r,new E(o||[])),!0),i}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var p={};function f(){}function m(){}function d(){}var v={};u(v,i,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(T([])));w&&w!==n&&r.call(w,i)&&(v=w);var y=d.prototype=f.prototype=Object.create(v);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function n(o,i,a,s){var u=l(t[o],t,i);if("throw"!==u.type){var c=u.arg,h=c.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):e.resolve(h).then((function(t){c.value=t,a(c)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}var o;u(this,"_invoke",(function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}),!0)}function k(e,n){var r=n.method,o=e.i[r];if(o===t)return n.delegate=null,"throw"===r&&e.i.return&&(n.method="return",n.arg=t,k(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=l(o,e.i,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,p;var a=i.arg;return a?a.done?(n[e.r]=a.value,n.next=e.n,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,p):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,p)}function _(t){this.tryEntries.push(t)}function C(e){var n=e[4]||{};n.type="normal",n.arg=t,e[4]=n}function E(t){this.tryEntries=[[-1]],t.forEach(_,this),this.reset(!0)}function T(e){if(null!=e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=d,u(y,"constructor",d),u(d,"constructor",m),m.displayName=u(d,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,s,"GeneratorFunction")),t.prototype=Object.create(y),t},e.awrap=function(t){return{__await:t}},x(b.prototype),u(b.prototype,a,(function(){return this})),e.AsyncIterator=b,e.async=function(t,n,r,o,i){void 0===i&&(i=Promise);var a=new b(c(t,n,r,o),i);return e.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(y),u(y,s,"Generator"),u(y,i,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.unshift(r);return function t(){for(;n.length;)if((r=n.pop())in e)return t.value=r,t.done=!1,t;return t.done=!0,t}},e.values=T,E.prototype={constructor:E,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(C),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function r(t){a.type="throw",a.arg=e,n.next=t}for(var o=n.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i[4],s=this.prev,u=i[1],c=i[2];if(-1===i[0])return r("end"),!1;if(!u&&!c)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=s){if(s<u)return this.method="next",this.arg=t,r(u),!0;if(s<c)return r(c),!1}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r[0]>-1&&r[0]<=this.prev&&this.prev<r[2]){var o=r;break}}o&&("break"===t||"continue"===t)&&o[0]<=e&&e<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o[2],p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n[2]===t)return this.complete(n[4],n[3]),C(n),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n[0]===t){var r=n[4];if("throw"===r.type){var o=r.arg;C(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={i:T(e),r:n,n:r},"next"===this.method&&(this.arg=t),p}},e}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},l(t,e)}var p=function(t,e,n){try{return t.resolve(e+"_"+n)}catch(e){return t.resolve(n)}},f=function(){function r(e,n,r,o){void 0===o&&(o="\n Summarize the following text:\n {input}\n "),this.container=void 0,this.tools=void 0,this.name=void 0,this.description=void 0,this.prompt=void 0,this.llm=void 0,this.template=void 0,this.chat_model=void 0,this.runnable=void 0,this.container=e,this.name=""===n?this.camelize(this.constructor.name):n,this.description=""===r?this.snake_case(this.constructor.name):r,this.template=o,this.tools=this.resolve("tools"),this.llm=this.resolve("main-llm"),this.chat_model=!1;try{this.chat_model=this.resolve("chat_model")}catch(t){}this.prompt=this.chat_model?t.ChatPromptTemplate.fromTemplate(this.template):t.PromptTemplate.fromTemplate(this.template)}var o=r.prototype;return o.resolve=function(t){return p(this.container,this.name,t)},o.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},o.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},o.chain=function(){var t=u(h().mark((function t(r){var o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.runnable=e.RunnableSequence.from([new e.RunnablePassthrough,this.prompt,this.llm]),!this.chat_model){t.next=7;break}return t.next=4,this.runnable.invoke(r);case 4:return o=new n.AIMessage(t.sent),t.abrupt("return",o.content);case 7:return t.next=9,this.runnable.invoke(r);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}(),m=function(){function e(e){this.container=void 0,this.tools=void 0,this.name=void 0,this.prompt=void 0,this.llm=void 0,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 ",this.container=e,this.name=this.camelize(this.constructor.name),this.tools=this.resolve("tools"),this.prompt=""!==this.resolve("prompt")?this.resolve("prompt"):t.PromptTemplate.fromTemplate(this.template),this.llm=this.resolve("main-llm")}var n=e.prototype;return n.resolve=function(t){return p(this.container,this.name,t)},n.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},n.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},n.run=function(){var t=u(h().mark((function t(e){var n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.createStructuredChatAgent({llm:this.llm,tools:this.tools,prompt:this.prompt});case 2:return n=new r.AgentExecutor({agent:t.sent,tools:this.tools,handleParsingErrors:"Please try again, paying close attention to the final answer"}),t.next=6,n.invoke(e);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e}(),d=function(t){function e(e,n,r,o,i){var a;return void 0===i&&(i=null),(a=t.call(this,{name:n,description:r,schema:o,func:i})||this).container=void 0,a.name=void 0,a.description=void 0,a.schema=void 0,a.func=function(){var t=u(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return","override this");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),a.container=e,a.name=""===n?a.camelize(a.constructor.name):n,a.description=""===r?a.snake_case(a.constructor.name):r,a.schema=o,a}c(e,t);var n=e.prototype;return n.resolve=function(t){return p(this.container,this.name,t)},n.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},n.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},e}(o.DynamicStructuredTool),v=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).name="MapQuery",e.description="Map a CQL query to a natural language.",e.template='\n You are an assistant that can convert a CQL query to a natural language.\nYou should give a single line answer>> as in the example below.\nExample:\n\nCQL: exists (\n [DocumentReference] D\n where D.allergies="Penicillin"\n and D.complaint="Headache"\n and D.complaint="Weakness" or D.complaint="Numbness"\n and D.findings="Intact sensation to light touch"\n )\n\nanswer>> Penicillin allergy, Headache, Weakness, Numbness, and Intact sensation to light touch as findings?\n\nCQL: exists (\n [DocumentReference] D\n where D.diagnosis="Diverticulitis"\n and D.complaint="Fever"\n and D.procedure="Colon resection"\n and not D.finding="Fluid collection"\n )\n\nanswer>> Diverticulitis diagnosis, Fever complaint, Colon resection procedure, and no Fluid collection finding?\n\nNow convert the following CQL query to a natural language.\nCQL: {expression}\n\nanswer>>\n ',e}return c(e,t),e}(f),g=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).name="MapDoc",e.description="Map a set of documents to facts.",e.template="\n You will be given a document and a question.\n\n Summarize the document chunk commenting on: {query} \n\n Do not include absent or negative mentions.\n\n document: {document} \n\n Summary:: ",e}return c(e,t),e}(f),w=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).name="Reduce",e.description="Reduce a set of documents to binary answer.",e.template="\n You will be given facts and a question to answer with ONLY a yes or no.\n\n Do not include the facts in the answer.\n\n Say yes if the facts mentions all aspects of the question, else say no.\n\n facts: {facts} \n\n question: Does the facts mention {question} Say YES OR NO Only::",e}return c(e,t),e}(f),y=new a.Logger,x=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t.call.apply(t,[this].concat(r))||this).string_expression="",e.name="LLMLoop",e.description="Base LLM Loop.",e.mapQuery=new v(e.container,"",""),e.mapDoc=new g(e.container,"",""),e.reduceChain=new w(e.container,"",""),e}c(e,t);var n=e.prototype;return n.checkAssertion=function(){var t=u(h().mark((function t(e,n){var r,o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r="",o="";try{r=this.printValues(JSON.parse(e))}catch(t){r=e}y.info("Checking assertion with expression: "+r);try{JSON.parse(n).forEach((function(t){o+=atob(t.content[0].attachment.data.value)}))}catch(t){o=n}return o=this.findDatesAndConvertToTimeElapsed(o.replace(/(\r\n|\n|\r)/gm," ")),t.abrupt("return",this.chain({input:{expression:r,context:o}}));case 9:case"end":return t.stop()}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),n.checkMention=function(){var t=u(h().mark((function t(e,n){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||!n){t.next=2;break}return t.abrupt("return",!0);case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}(),n.checkNegation=function(){var t=u(h().mark((function t(e,n){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||!n){t.next=2;break}return t.abrupt("return",!0);case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}(),n.findDatesAndConvertToTimeElapsed=function(t){for(var e,n=/(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g,r=new Date;null!==(e=n.exec(t));){var o=new Date(e[0]),i=(r.getTime()-o.getTime())/864e5;t=t.replace(e[0],Math.floor(i).toString()+" days ago.")}return t},n.camelToString=function(t){return t.replace(/([A-Z])/g," $1").replace(/^./,(function(t){return t.toUpperCase()}))},n.stringToBoolean=function(t){y.info("Converting string to boolean: "+t);var e=t.toLowerCase();return["true","contains","confirms","yes","affirmative","matches","exists","present","absolutely","certainly","definitely","indeed"].some((function(t){return e.includes(t)}))},n.textSplitter=function(){var t=u(h().mark((function t(e,n,r){var o,a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=3900),void 0===r&&(r=0),o=new i.CharacterTextSplitter({chunkSize:n,chunkOverlap:r}),t.next=5,o.splitText(e);case 5:if(0!==(a=t.sent).length){t.next=9;break}return y.warn("No text chunks created. Please check the input text."),t.abrupt("return",[]);case 9:return a.length>100&&y.warn("Warning: More than 100 text chunks created ("+a.length+"). This may affect performance."),n<1e3&&y.warn("Warning: Chunk size is less than 1000 characters ("+n+"). This may lead to very small chunks."),y.info("Text split into "+a.length+" chunks with size "+n+" and overlap "+r),t.abrupt("return",a);case 13:case"end":return t.stop()}}),t)})));return function(e,n,r){return t.apply(this,arguments)}}(),n.printValues=function(t){var e=this;for(var n in t)"object"==typeof t[n]?this.printValues(t[n]):this.string_expression+=t[n]+" ";return["true","false","null","undefined","String","Number","Object","Array","Boolean","value","Type","Specifier","Named"].forEach((function(t){var n=new RegExp(t,"g");e.string_expression=e.string_expression.replace(n,"")})),this.string_expression=this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g,""),this.camelToString(this.string_expression)},n.chain=function(){var t=u(h().mark((function t(e){var n,r,o,i,a,s,c,l,p=this;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,import("@langchain/core/runnables");case 2:return r=(n=t.sent).RunnableSequence,o=n.RunnableParallel,a=(i=n.RunnablePassthrough).assign({query:function(){var t=u(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",p.mapQuery.chain({input:{expression:e.input.expression}}));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}),s=i.assign({documents:function(){var t=u(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,p.textSplitter(e.input.context);case 2:return t.abrupt("return",Promise.all(t.sent.map((function(t){return p.mapDoc.chain({input:{document:t,question:e.input.expression}})}))));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}),c=o.from([a,s]),l=r.from([c,function(){var t=u(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",p.reduceChain.chain({input:{query:e[0].query,facts:e[1].documents}}));case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),function(t){return p.stringToBoolean(t)}]),t.abrupt("return",l.invoke(e));case 11:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e}(f);exports.BaseAgent=m,exports.BaseChain=f,exports.BaseTool=d,exports.LLMLoop=x;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@langchain/core/prompts"),e=require("@langchain/core/runnables"),n=require("@langchain/core/messages"),r=require("langchain/agents"),a=require("langchain/tools"),i=require("@langchain/textsplitters"),o=require("tslog");function s(t,e,n,r,a,i,o){try{var s=t[i](o),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(r,a)}function c(t){return function(){var e=this,n=arguments;return new Promise((function(r,a){var i=t.apply(e,n);function o(t){s(i,r,a,o,c,"next",t)}function c(t){s(i,r,a,o,c,"throw",t)}o(void 0)}))}}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,l(t,e)}function h(){h=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",o=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function c(t,e,n,r){Object.defineProperty(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r})}try{c({},"")}catch(t){c=function(t,e,n){return t[e]=n}}function u(e,n,r,a){var i=Object.create((n&&n.prototype instanceof f?n:f).prototype);return c(i,"_invoke",function(e,n,r){var a=1;return function(i,o){if(3===a)throw Error("Generator is already running");if(4===a){if("throw"===i)throw o;return{value:t,done:!0}}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var c=k(s,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(1===a)throw a=4,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);a=3;var u=l(e,n,r);if("normal"===u.type){if(a=r.done?4:2,u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(a=4,r.method="throw",r.arg=u.arg)}}}(e,r,new E(a||[])),!0),i}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=u;var p={};function f(){}function m(){}function d(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(O([])));g&&g!==n&&r.call(g,i)&&(v=g);var w=d.prototype=f.prototype=Object.create(v);function x(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function n(a,i,o,s){var c=l(t[a],t,i);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,o,s)}),(function(t){n("throw",t,o,s)})):e.resolve(h).then((function(t){u.value=t,o(u)}),(function(t){return n("throw",t,o,s)}))}s(c.arg)}var a;c(this,"_invoke",(function(t,r){function i(){return new e((function(e,a){n(t,r,e,a)}))}return a=a?a.then(i,i):i()}),!0)}function k(e,n){var r=n.method,a=e.i[r];if(a===t)return n.delegate=null,"throw"===r&&e.i.return&&(n.method="return",n.arg=t,k(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=l(a,e.i,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,p;var o=i.arg;return o?o.done?(n[e.r]=o.value,n.next=e.n,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,p):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,p)}function _(t){this.tryEntries.push(t)}function T(e){var n=e[4]||{};n.type="normal",n.arg=t,e[4]=n}function E(t){this.tryEntries=[[-1]],t.forEach(_,this),this.reset(!0)}function O(e){if(null!=e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var a=-1,o=function n(){for(;++a<e.length;)if(r.call(e,a))return n.value=e[a],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(typeof e+" is not iterable")}return m.prototype=d,c(w,"constructor",d),c(d,"constructor",m),c(d,s,m.displayName="GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},e.awrap=function(t){return{__await:t}},x(b.prototype),c(b.prototype,o,(function(){return this})),e.AsyncIterator=b,e.async=function(t,n,r,a,i){void 0===i&&(i=Promise);var o=new b(u(t,n,r,a),i);return e.isGeneratorFunction(n)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},x(w),c(w,s,"Generator"),c(w,i,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.unshift(r);return function t(){for(;n.length;)if((r=n.pop())in e)return t.value=r,t.done=!1,t;return t.done=!0,t}},e.values=O,E.prototype={constructor:E,reset:function(e){if(this.prev=this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(T),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0][4];if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function r(t){o.type="throw",o.arg=e,n.next=t}for(var a=n.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i[4],s=this.prev,c=i[1],u=i[2];if(-1===i[0])return r("end"),!1;if(!c&&!u)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=s){if(s<c)return this.method="next",this.arg=t,r(c),!0;if(s<u)return r(u),!1}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r[0]>-1&&r[0]<=this.prev&&this.prev<r[2]){var a=r;break}}a&&("break"===t||"continue"===t)&&a[0]<=e&&e<=a[2]&&(a=null);var i=a?a[4]:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a[2],p):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n[2]===t)return this.complete(n[4],n[3]),T(n),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n[0]===t){var r=n[4];if("throw"===r.type){var a=r.arg;T(n)}return a}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={i:O(e),r:n,n:r},"next"===this.method&&(this.arg=t),p}},e}function l(t,e){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},l(t,e)}var p=function(t,e,n){try{return t.resolve(e+"_"+n)}catch(e){return t.resolve(n)}},f=function(){function r(e,n,r,a){void 0===a&&(a="\n Summarize the following text:\n {input}\n "),this.container=void 0,this.tools=void 0,this.name=void 0,this.description=void 0,this.prompt=void 0,this.llm=void 0,this.template=void 0,this.chat_model=void 0,this.runnable=void 0,this.container=e,this.name=""===n?this.camelize(this.constructor.name):n,this.description=""===r?this.snake_case(this.constructor.name):r,this.template=a,this.tools=this.resolve("tools"),this.llm=this.resolve("main-llm"),this.chat_model=!1;try{this.chat_model=this.resolve("chat_model")}catch(t){}this.prompt=this.chat_model?t.ChatPromptTemplate.fromTemplate(this.template):t.PromptTemplate.fromTemplate(this.template)}var a=r.prototype;return a.resolve=function(t){return p(this.container,this.name,t)},a.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},a.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},a.chain=function(){var t=c(h().mark((function t(r){var a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.runnable=e.RunnableSequence.from([new e.RunnablePassthrough,this.prompt,this.llm]),!this.chat_model){t.next=7;break}return t.next=4,this.runnable.invoke(r);case 4:return a=new n.AIMessage(t.sent),t.abrupt("return",a.content);case 7:return t.next=9,this.runnable.invoke(r);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}(),m=function(){function e(e){this.container=void 0,this.tools=void 0,this.name=void 0,this.prompt=void 0,this.llm=void 0,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 ",this.container=e,this.name=this.camelize(this.constructor.name),this.tools=this.resolve("tools"),this.prompt=""!==this.resolve("prompt")?this.resolve("prompt"):t.PromptTemplate.fromTemplate(this.template),this.llm=this.resolve("main-llm")}var n=e.prototype;return n.resolve=function(t){return p(this.container,this.name,t)},n.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},n.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},n.run=function(){var t=c(h().mark((function t(e){var n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.createStructuredChatAgent({llm:this.llm,tools:this.tools,prompt:this.prompt});case 2:return n=new r.AgentExecutor({agent:t.sent,tools:this.tools,handleParsingErrors:"Please try again, paying close attention to the final answer"}),t.next=6,n.invoke(e);case 6:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e}(),d=function(t){function e(e,n,r,a,i){var o;return void 0===i&&(i=null),(o=t.call(this,{name:n,description:r,schema:a,func:i})||this).container=void 0,o.name=void 0,o.description=void 0,o.schema=void 0,o.func=function(){var t=c(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return","override this");case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),o.container=e,o.name=""===n?o.camelize(o.constructor.name):n,o.description=""===r?o.snake_case(o.constructor.name):r,o.schema=a,o}u(e,t);var n=e.prototype;return n.resolve=function(t){return p(this.container,this.name,t)},n.camelize=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():t.toUpperCase()})).replace(/\s+/g,"")},n.snake_case=function(t){return t.replace(/(?:^\w|[A-Z]|\b\w)/g,(function(t,e){return 0===e?t.toLowerCase():"_"+t.toLowerCase()})).replace(/\s+/g,"")},e}(a.DynamicStructuredTool),v=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return(e=t.call.apply(t,[this].concat(r))||this).name="MapQuery",e.description="Map a CQL query to a natural language.",e.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: ",e}return u(e,t),e}(f),y=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return(e=t.call.apply(t,[this].concat(r))||this).name="MapDoc",e.description="Map a set of documents to facts.",e.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: ",e}return u(e,t),e}(f),g=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return(e=t.call.apply(t,[this].concat(r))||this).name="Reduce",e.description="Reduce a set of documents to binary answer.",e.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: ",e}return u(e,t),e}(f),w=new o.Logger,x=function(t){function e(){for(var e,n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return(e=t.call.apply(t,[this].concat(r))||this).string_expression="",e.name="LLMLoop",e.description="Base LLM Loop.",e.mapQuery=new v(e.container,"",""),e.mapDoc=new y(e.container,"",""),e.reduceChain=new g(e.container,"",""),e}u(e,t);var n=e.prototype;return n.checkAssertion=function(){var t=c(h().mark((function t(e,n){var r,a,i,o,s;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r="";try{r=this.printValues(JSON.parse(e))}catch(t){r=e}w.info("Checking assertion with expression: "+r),a=void 0,i="";try{a=JSON.parse(n)}catch(t){a=n,w.warn("Context is not a valid JSON string: "+n),w.warn("Using context as a string: "+a)}try{(a=JSON.parse(n)).forEach((function(t){t.content.forEach((function(t){i+=atob(t.attachment.data.value)}))}))}catch(t){i=n,w.warn("Context is not a valid JSON : "+n),w.warn("Using context as a string: "+i)}return i=this.findDatesAndConvertToTimeElapsed(i.replace(/(\r\n|\n|\r)/gm," ")),w.info("Checking assertion with context: "+i),o={input:{expression:r,context:i}},t.next=12,this.chain(o);case 12:return w.info("Assertion check result: "+(s=t.sent)),t.abrupt("return",s);case 15:case"end":return t.stop()}}),t,this)})));return function(e,n){return t.apply(this,arguments)}}(),n.checkMention=function(){var t=c(h().mark((function t(e,n){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||!n){t.next=2;break}return t.abrupt("return",!0);case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}(),n.checkNegation=function(){var t=c(h().mark((function t(e,n){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e||!n){t.next=2;break}return t.abrupt("return",!0);case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}(),n.findDatesAndConvertToTimeElapsed=function(t){for(var e,n=/(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g,r=new Date;null!==(e=n.exec(t));){var a=new Date(e[0]),i=(r.getTime()-a.getTime())/864e5;t=t.replace(e[0],Math.floor(i).toString()+" days ago.")}return t},n.camelToString=function(t){return t.replace(/([A-Z])/g," $1").replace(/^./,(function(t){return t.toUpperCase()}))},n.stringToBoolean=function(t){w.info("Converting string to boolean: "+t);var e=t.toLowerCase();return["true","contains","confirms","yes","affirmative","matches","exists","present","absolutely","certainly","definitely","indeed","did have","showed","revealed"].some((function(t){return e.includes(t)}))},n.textSplitter=function(){var t=c(h().mark((function t(e,n,r){var a,o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===n&&(n=3900),void 0===r&&(r=0),a=new i.CharacterTextSplitter({chunkSize:n,chunkOverlap:r}),t.next=5,a.splitText(e);case 5:if(0!==(o=t.sent).length){t.next=9;break}return w.warn("No text chunks created. Please check the input text."),t.abrupt("return",[]);case 9:return o.length>100&&w.warn("Warning: More than 100 text chunks created ("+o.length+"). This may affect performance."),n<1e3&&w.warn("Warning: Chunk size is less than 1000 characters ("+n+"). This may lead to very small chunks."),w.info("Text split into "+o.length+" chunks with size "+n+" and overlap "+r),t.abrupt("return",o);case 13:case"end":return t.stop()}}),t)})));return function(e,n,r){return t.apply(this,arguments)}}(),n.printValues=function(t){return w.info("Processing Rule: "+t.name+" for "+t.context),t.expression&&t.expression.arg&&t.expression.arg.where?this.extractObjectsByKey(t.expression.arg.where,"value").join(" ").replace(/,/g," "):""},n.extractObjectsByKey=function(t,e){var n=[];return function t(r){for(var a in r)r.hasOwnProperty(a)&&(a===e&&n.push(r[a]),"object"==typeof r[a]&&null!==r[a]&&t(r[a]))}(t),n},n._printValues=function(t){var e=this;for(var n in t)"object"==typeof t[n]?this._printValues(t[n]):this.string_expression+=t[n]+" ";return["true","false","null","undefined","String","Number","Object","Array","Boolean","value","Type","Specifier","Named"].forEach((function(t){var n=new RegExp(t,"g");e.string_expression=e.string_expression.replace(n,"")})),this.string_expression=this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g,""),this.camelToString(this.string_expression)},n.chain=function(){var t=c(h().mark((function t(e){var n,r,a,i,o,s,u,l,p=this;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,import("@langchain/core/runnables");case 2:return r=(n=t.sent).RunnableSequence,a=n.RunnableParallel,o=(i=n.RunnablePassthrough).assign({query:function(){var t=c(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",p.mapQuery.chain({input:{expression:e.input.expression}}));case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}),s=i.assign({documents:function(){var t=c(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,p.textSplitter(e.input.context);case 2:return t.abrupt("return",Promise.all(t.sent.map((function(t){return p.mapDoc.chain({input:{document:t,statements:e.input.expression}})}))));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()}),u=a.from([o,s]),l=r.from([u,function(){var t=c(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return w.info("Results from parallel chain: "+JSON.stringify(e)),t.abrupt("return",p.reduceChain.chain({input:{facts:e[1].documents,query:e[0].query+" "+e[0].input.expression}}));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),function(t){return p.stringToBoolean(t)}]),t.abrupt("return",l.invoke(e));case 11:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),e}(f);exports.BaseAgent=m,exports.BaseChain=f,exports.BaseTool=d,exports.LLMLoop=x;
2
2
  //# sourceMappingURL=medpromptjs.cjs.production.min.js.map