medpromptjs 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/llm_loop/base.d.ts +3 -3
- package/dist/llm_loop/index.d.ts +3 -0
- package/dist/medpromptjs.cjs.development.js +359 -0
- package/dist/medpromptjs.cjs.development.js.map +1 -1
- package/dist/medpromptjs.cjs.production.min.js +1 -1
- package/dist/medpromptjs.cjs.production.min.js.map +1 -1
- package/dist/medpromptjs.esm.js +359 -1
- package/dist/medpromptjs.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +1 -0
- package/src/llm_loop/base.ts +32 -7
- package/src/llm_loop/index.ts +3 -0
package/dist/index.d.ts
CHANGED
package/dist/llm_loop/base.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare class LLMLoop extends BaseChain {
|
|
|
9
9
|
mapQuery: MapQuery;
|
|
10
10
|
mapDoc: MapDoc;
|
|
11
11
|
reduceChain: ReduceChain;
|
|
12
|
-
checkAssertion(expression: string, context:
|
|
13
|
-
checkMention(expression: string, context:
|
|
14
|
-
checkNegation(expression: string, context:
|
|
12
|
+
checkAssertion(expression: string, context: any): Promise<boolean>;
|
|
13
|
+
checkMention(expression: string, context: any): Promise<boolean>;
|
|
14
|
+
checkNegation(expression: string, context: any): Promise<boolean>;
|
|
15
15
|
findDatesAndConvertToTimeElapsed(text: string): string;
|
|
16
16
|
camelToString(camelCase: string): string;
|
|
17
17
|
stringToBoolean(str: string): boolean;
|
package/dist/llm_loop/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ var runnables = require('@langchain/core/runnables');
|
|
|
7
7
|
var messages = require('@langchain/core/messages');
|
|
8
8
|
var agents = require('langchain/agents');
|
|
9
9
|
var tools = require('langchain/tools');
|
|
10
|
+
var textsplitters = require('@langchain/textsplitters');
|
|
11
|
+
var tslog = require('tslog');
|
|
10
12
|
|
|
11
13
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
12
14
|
try {
|
|
@@ -541,7 +543,364 @@ var BaseTool = /*#__PURE__*/function (_DynamicStructuredToo) {
|
|
|
541
543
|
return BaseTool;
|
|
542
544
|
}(tools.DynamicStructuredTool);
|
|
543
545
|
|
|
546
|
+
var MapQuery = /*#__PURE__*/function (_BaseChain) {
|
|
547
|
+
function MapQuery() {
|
|
548
|
+
var _this;
|
|
549
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
550
|
+
args[_key] = arguments[_key];
|
|
551
|
+
}
|
|
552
|
+
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
553
|
+
_this.name = 'MapQuery';
|
|
554
|
+
_this.description = 'Map a CQL query to a natural language.';
|
|
555
|
+
_this.template = "\n You are an assistant that can convert 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 ";
|
|
556
|
+
return _this;
|
|
557
|
+
}
|
|
558
|
+
_inheritsLoose(MapQuery, _BaseChain);
|
|
559
|
+
return MapQuery;
|
|
560
|
+
}(BaseChain);
|
|
561
|
+
|
|
562
|
+
var MapDoc = /*#__PURE__*/function (_BaseChain) {
|
|
563
|
+
function MapDoc() {
|
|
564
|
+
var _this;
|
|
565
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
566
|
+
args[_key] = arguments[_key];
|
|
567
|
+
}
|
|
568
|
+
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
569
|
+
_this.name = 'MapDoc';
|
|
570
|
+
_this.description = 'Map a set of documents to facts.';
|
|
571
|
+
_this.template = "\n You will be given a document and 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:: ";
|
|
572
|
+
return _this;
|
|
573
|
+
}
|
|
574
|
+
_inheritsLoose(MapDoc, _BaseChain);
|
|
575
|
+
return MapDoc;
|
|
576
|
+
}(BaseChain);
|
|
577
|
+
|
|
578
|
+
var ReduceChain = /*#__PURE__*/function (_BaseChain) {
|
|
579
|
+
function ReduceChain() {
|
|
580
|
+
var _this;
|
|
581
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
582
|
+
args[_key] = arguments[_key];
|
|
583
|
+
}
|
|
584
|
+
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
585
|
+
_this.name = 'Reduce';
|
|
586
|
+
_this.description = 'Reduce a set of documents to binary answer.';
|
|
587
|
+
_this.template = "\n 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::";
|
|
588
|
+
return _this;
|
|
589
|
+
}
|
|
590
|
+
_inheritsLoose(ReduceChain, _BaseChain);
|
|
591
|
+
return ReduceChain;
|
|
592
|
+
}(BaseChain);
|
|
593
|
+
|
|
594
|
+
var log = /*#__PURE__*/new tslog.Logger();
|
|
595
|
+
var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
596
|
+
function LLMLoop() {
|
|
597
|
+
var _this;
|
|
598
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
599
|
+
args[_key] = arguments[_key];
|
|
600
|
+
}
|
|
601
|
+
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
602
|
+
// Implement the LLM loop logic here
|
|
603
|
+
_this.string_expression = '';
|
|
604
|
+
_this.name = 'LLMLoop';
|
|
605
|
+
_this.description = 'Base LLM Loop.';
|
|
606
|
+
_this.mapQuery = new MapQuery(_this.container, '', '');
|
|
607
|
+
_this.mapDoc = new MapDoc(_this.container, '', '');
|
|
608
|
+
_this.reduceChain = new ReduceChain(_this.container, '', '');
|
|
609
|
+
return _this;
|
|
610
|
+
}
|
|
611
|
+
_inheritsLoose(LLMLoop, _BaseChain);
|
|
612
|
+
var _proto = LLMLoop.prototype;
|
|
613
|
+
_proto.checkAssertion = /*#__PURE__*/function () {
|
|
614
|
+
var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
|
|
615
|
+
var _expression, _context, _content, _input;
|
|
616
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
617
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
618
|
+
case 0:
|
|
619
|
+
_expression = '';
|
|
620
|
+
_context = undefined;
|
|
621
|
+
_content = '';
|
|
622
|
+
try {
|
|
623
|
+
// Check if expression is a valid JSON string
|
|
624
|
+
_expression = this.printValues(JSON.parse(expression));
|
|
625
|
+
} catch (error) {
|
|
626
|
+
_expression = expression; // If not, use the expression as is
|
|
627
|
+
}
|
|
628
|
+
log.info("Checking assertion with expression: " + _expression);
|
|
629
|
+
try {
|
|
630
|
+
// Check if context is a valid JSON string
|
|
631
|
+
_context = JSON.parse(context);
|
|
632
|
+
_context.forEach(function (element) {
|
|
633
|
+
_content += atob(element.content[0].attachment.data.value);
|
|
634
|
+
});
|
|
635
|
+
} catch (error) {
|
|
636
|
+
_content = context; // If not, use the context as is
|
|
637
|
+
}
|
|
638
|
+
_content = this.findDatesAndConvertToTimeElapsed(_content.replace(/(\r\n|\n|\r)/gm, ' '));
|
|
639
|
+
_input = {
|
|
640
|
+
input: {
|
|
641
|
+
expression: _expression,
|
|
642
|
+
context: _content
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
return _context2.abrupt("return", this.chain(_input));
|
|
646
|
+
case 9:
|
|
647
|
+
case "end":
|
|
648
|
+
return _context2.stop();
|
|
649
|
+
}
|
|
650
|
+
}, _callee, this);
|
|
651
|
+
}));
|
|
652
|
+
function checkAssertion(_x, _x2) {
|
|
653
|
+
return _checkAssertion.apply(this, arguments);
|
|
654
|
+
}
|
|
655
|
+
return checkAssertion;
|
|
656
|
+
}();
|
|
657
|
+
_proto.checkMention = /*#__PURE__*/function () {
|
|
658
|
+
var _checkMention = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(expression, context) {
|
|
659
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
|
660
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
661
|
+
case 0:
|
|
662
|
+
if (!(expression && context)) {
|
|
663
|
+
_context3.next = 2;
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
return _context3.abrupt("return", true);
|
|
667
|
+
case 2:
|
|
668
|
+
return _context3.abrupt("return", false);
|
|
669
|
+
case 3:
|
|
670
|
+
case "end":
|
|
671
|
+
return _context3.stop();
|
|
672
|
+
}
|
|
673
|
+
}, _callee2);
|
|
674
|
+
}));
|
|
675
|
+
function checkMention(_x3, _x4) {
|
|
676
|
+
return _checkMention.apply(this, arguments);
|
|
677
|
+
}
|
|
678
|
+
return checkMention;
|
|
679
|
+
}();
|
|
680
|
+
_proto.checkNegation = /*#__PURE__*/function () {
|
|
681
|
+
var _checkNegation = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(expression, context) {
|
|
682
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
683
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
684
|
+
case 0:
|
|
685
|
+
if (!(expression && context)) {
|
|
686
|
+
_context4.next = 2;
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
return _context4.abrupt("return", true);
|
|
690
|
+
case 2:
|
|
691
|
+
return _context4.abrupt("return", false);
|
|
692
|
+
case 3:
|
|
693
|
+
case "end":
|
|
694
|
+
return _context4.stop();
|
|
695
|
+
}
|
|
696
|
+
}, _callee3);
|
|
697
|
+
}));
|
|
698
|
+
function checkNegation(_x5, _x6) {
|
|
699
|
+
return _checkNegation.apply(this, arguments);
|
|
700
|
+
}
|
|
701
|
+
return checkNegation;
|
|
702
|
+
}();
|
|
703
|
+
_proto.findDatesAndConvertToTimeElapsed = function findDatesAndConvertToTimeElapsed(text) {
|
|
704
|
+
// Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'
|
|
705
|
+
var dateRegex = /(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g;
|
|
706
|
+
var matches;
|
|
707
|
+
var currentDate = new Date();
|
|
708
|
+
while ((matches = dateRegex.exec(text)) !== null) {
|
|
709
|
+
var date = new Date(matches[0]);
|
|
710
|
+
var timeElapsed = (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);
|
|
711
|
+
text = text.replace(matches[0], Math.floor(timeElapsed).toString() + ' days ago.');
|
|
712
|
+
}
|
|
713
|
+
return text;
|
|
714
|
+
};
|
|
715
|
+
_proto.camelToString = function camelToString(camelCase) {
|
|
716
|
+
return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
|
|
717
|
+
return str.toUpperCase();
|
|
718
|
+
});
|
|
719
|
+
};
|
|
720
|
+
_proto.stringToBoolean = function stringToBoolean(str) {
|
|
721
|
+
log.info("Converting string to boolean: " + str);
|
|
722
|
+
var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed'];
|
|
723
|
+
var lowerStr = str.toLowerCase();
|
|
724
|
+
return positiveKeywords.some(function (keyword) {
|
|
725
|
+
return lowerStr.includes(keyword);
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
_proto.textSplitter = /*#__PURE__*/function () {
|
|
729
|
+
var _textSplitter = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(text, chunkSize, chunkOverlap) {
|
|
730
|
+
var textSplitter, texts;
|
|
731
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
|
|
732
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
733
|
+
case 0:
|
|
734
|
+
if (chunkSize === void 0) {
|
|
735
|
+
chunkSize = 3900;
|
|
736
|
+
}
|
|
737
|
+
if (chunkOverlap === void 0) {
|
|
738
|
+
chunkOverlap = 0;
|
|
739
|
+
}
|
|
740
|
+
textSplitter = new textsplitters.CharacterTextSplitter({
|
|
741
|
+
chunkSize: chunkSize,
|
|
742
|
+
chunkOverlap: chunkOverlap
|
|
743
|
+
});
|
|
744
|
+
_context5.next = 5;
|
|
745
|
+
return textSplitter.splitText(text);
|
|
746
|
+
case 5:
|
|
747
|
+
texts = _context5.sent;
|
|
748
|
+
if (!(texts.length === 0)) {
|
|
749
|
+
_context5.next = 9;
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
log.warn('No text chunks created. Please check the input text.');
|
|
753
|
+
return _context5.abrupt("return", []);
|
|
754
|
+
case 9:
|
|
755
|
+
if (texts.length > 100) {
|
|
756
|
+
log.warn("Warning: More than 100 text chunks created (" + texts.length + "). This may affect performance.");
|
|
757
|
+
}
|
|
758
|
+
if (chunkSize < 1000) {
|
|
759
|
+
log.warn("Warning: Chunk size is less than 1000 characters (" + chunkSize + "). This may lead to very small chunks.");
|
|
760
|
+
}
|
|
761
|
+
log.info("Text split into " + texts.length + " chunks with size " + chunkSize + " and overlap " + chunkOverlap);
|
|
762
|
+
return _context5.abrupt("return", texts);
|
|
763
|
+
case 13:
|
|
764
|
+
case "end":
|
|
765
|
+
return _context5.stop();
|
|
766
|
+
}
|
|
767
|
+
}, _callee4);
|
|
768
|
+
}));
|
|
769
|
+
function textSplitter(_x7, _x8, _x9) {
|
|
770
|
+
return _textSplitter.apply(this, arguments);
|
|
771
|
+
}
|
|
772
|
+
return textSplitter;
|
|
773
|
+
}();
|
|
774
|
+
_proto.printValues = function printValues(obj) {
|
|
775
|
+
var _this2 = this;
|
|
776
|
+
for (var key in obj) {
|
|
777
|
+
if (typeof obj[key] === 'object') {
|
|
778
|
+
this.printValues(obj[key]);
|
|
779
|
+
} else {
|
|
780
|
+
this.string_expression += obj[key] + ' ';
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
var _eliminate = ['true', 'false', 'null', 'undefined', 'String', 'Number', 'Object', 'Array', 'Boolean', 'value', 'Type', 'Specifier', 'Named'];
|
|
784
|
+
_eliminate.forEach(function (element) {
|
|
785
|
+
var regex = new RegExp(element, 'g');
|
|
786
|
+
_this2.string_expression = _this2.string_expression.replace(regex, '');
|
|
787
|
+
});
|
|
788
|
+
this.string_expression = this.string_expression.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
|
|
789
|
+
return this.camelToString(this.string_expression);
|
|
790
|
+
};
|
|
791
|
+
_proto.chain = /*#__PURE__*/function () {
|
|
792
|
+
var _chain = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(input) {
|
|
793
|
+
var _this3 = this;
|
|
794
|
+
var _yield$import, RunnableSequence, RunnableParallel, RunnablePassthrough, mapQueryChain, mapDocChain, parallelChain, sequence;
|
|
795
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
|
|
796
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
797
|
+
case 0:
|
|
798
|
+
_context9.next = 2;
|
|
799
|
+
return import('@langchain/core/runnables');
|
|
800
|
+
case 2:
|
|
801
|
+
_yield$import = _context9.sent;
|
|
802
|
+
RunnableSequence = _yield$import.RunnableSequence;
|
|
803
|
+
RunnableParallel = _yield$import.RunnableParallel;
|
|
804
|
+
RunnablePassthrough = _yield$import.RunnablePassthrough;
|
|
805
|
+
mapQueryChain = RunnablePassthrough.assign({
|
|
806
|
+
query: function () {
|
|
807
|
+
var _query = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(input) {
|
|
808
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
|
|
809
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
810
|
+
case 0:
|
|
811
|
+
return _context6.abrupt("return", _this3.mapQuery.chain({
|
|
812
|
+
input: {
|
|
813
|
+
expression: input.input.expression
|
|
814
|
+
}
|
|
815
|
+
}));
|
|
816
|
+
case 1:
|
|
817
|
+
case "end":
|
|
818
|
+
return _context6.stop();
|
|
819
|
+
}
|
|
820
|
+
}, _callee5);
|
|
821
|
+
}));
|
|
822
|
+
function query(_x1) {
|
|
823
|
+
return _query.apply(this, arguments);
|
|
824
|
+
}
|
|
825
|
+
return query;
|
|
826
|
+
}()
|
|
827
|
+
});
|
|
828
|
+
mapDocChain = RunnablePassthrough.assign({
|
|
829
|
+
documents: function () {
|
|
830
|
+
var _documents = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
|
|
831
|
+
var textChunks;
|
|
832
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
|
|
833
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
834
|
+
case 0:
|
|
835
|
+
_context7.next = 2;
|
|
836
|
+
return _this3.textSplitter(input.input.context);
|
|
837
|
+
case 2:
|
|
838
|
+
textChunks = _context7.sent;
|
|
839
|
+
return _context7.abrupt("return", Promise.all(textChunks.map(function (chunk) {
|
|
840
|
+
return _this3.mapDoc.chain({
|
|
841
|
+
input: {
|
|
842
|
+
document: chunk,
|
|
843
|
+
question: input.input.expression
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
})));
|
|
847
|
+
case 4:
|
|
848
|
+
case "end":
|
|
849
|
+
return _context7.stop();
|
|
850
|
+
}
|
|
851
|
+
}, _callee6);
|
|
852
|
+
}));
|
|
853
|
+
function documents(_x10) {
|
|
854
|
+
return _documents.apply(this, arguments);
|
|
855
|
+
}
|
|
856
|
+
return documents;
|
|
857
|
+
}()
|
|
858
|
+
});
|
|
859
|
+
parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
|
|
860
|
+
sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
|
|
861
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
|
|
862
|
+
var query, documents;
|
|
863
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
864
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
865
|
+
case 0:
|
|
866
|
+
// results is an array: [{ query: ... }, { documents: [...] }]
|
|
867
|
+
query = results[0].query;
|
|
868
|
+
documents = results[1].documents;
|
|
869
|
+
return _context8.abrupt("return", _this3.reduceChain.chain({
|
|
870
|
+
input: {
|
|
871
|
+
query: query,
|
|
872
|
+
facts: documents
|
|
873
|
+
}
|
|
874
|
+
}));
|
|
875
|
+
case 3:
|
|
876
|
+
case "end":
|
|
877
|
+
return _context8.stop();
|
|
878
|
+
}
|
|
879
|
+
}, _callee7);
|
|
880
|
+
}));
|
|
881
|
+
return function (_x11) {
|
|
882
|
+
return _ref.apply(this, arguments);
|
|
883
|
+
};
|
|
884
|
+
}()), function (result) {
|
|
885
|
+
return _this3.stringToBoolean(result);
|
|
886
|
+
}]);
|
|
887
|
+
return _context9.abrupt("return", sequence.invoke(input));
|
|
888
|
+
case 11:
|
|
889
|
+
case "end":
|
|
890
|
+
return _context9.stop();
|
|
891
|
+
}
|
|
892
|
+
}, _callee8);
|
|
893
|
+
}));
|
|
894
|
+
function chain(_x0) {
|
|
895
|
+
return _chain.apply(this, arguments);
|
|
896
|
+
}
|
|
897
|
+
return chain;
|
|
898
|
+
}();
|
|
899
|
+
return LLMLoop;
|
|
900
|
+
}(BaseChain);
|
|
901
|
+
|
|
544
902
|
exports.BaseAgent = BaseAgent;
|
|
545
903
|
exports.BaseChain = BaseChain;
|
|
546
904
|
exports.BaseTool = BaseTool;
|
|
905
|
+
exports.LLMLoop = LLMLoop;
|
|
547
906
|
//# sourceMappingURL=medpromptjs.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"medpromptjs.cjs.development.js","sources":["../src/mydi.ts","../src/chain.ts","../src/agent.ts","../src/tool.ts"],"sourcesContent":["/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst mydi = (c: any, m: string, b: string) => {\n try {\n return c.resolve(m + '_' + b);\n } catch (e) {\n return c.resolve(b);\n }\n};\n\nexport default mydi;\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\nimport {\n RunnablePassthrough,\n RunnableSequence,\n} from '@langchain/core/runnables';\nimport { AIMessage } from '@langchain/core/messages';\n\nexport class BaseChain {\n container: any;\n tools: ToolInterface[];\n name: string;\n description: string;\n prompt: any;\n llm: LLM;\n template: string;\n chat_model: boolean;\n runnable: any;\n\n constructor(\n container: any,\n name: string,\n description: string,\n template: string = `\n Summarize the following text:\n {input}\n `\n ) {\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.template = template;\n this.tools = this.resolve('tools');\n this.llm = this.resolve('main-llm');\n this.chat_model = false;\n try {\n this.chat_model = this.resolve('chat_model');\n } catch (e) {}\n if (this.chat_model) {\n this.prompt = ChatPromptTemplate.fromTemplate(this.template);\n } else {\n this.prompt = PromptTemplate.fromTemplate(this.template);\n }\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n // https://js.langchain.com/v0.1/docs/expression_language/how_to/routing/\n //! Override this method\n async chain(input: any) {\n this.runnable = RunnableSequence.from([\n new RunnablePassthrough(),\n this.prompt,\n this.llm,\n ]);\n if (this.chat_model) {\n const response: string = await this.runnable.invoke(input);\n const aiMessage = new AIMessage(response);\n return aiMessage.content;\n }\n return await this.runnable.invoke(input);\n }\n}\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate, ChatPromptTemplate } from '@langchain/core/prompts';\nimport { LLM } from '@langchain/core/language_models/llms';\nimport {\n AgentExecutor,\n createReactAgent,\n createStructuredChatAgent,\n} from 'langchain/agents';\nimport type { ToolInterface } from '@langchain/core/tools';\nimport mydi from './mydi';\n\nexport class BaseAgent {\n container: any;\n tools: ToolInterface[];\n name: string;\n prompt: PromptTemplate;\n llm: LLM;\n template: string = `\n ## Question: {question}\n ## Answer: {answer}\n Given the above question and answer, generate a chain of thought explanation for the answer.\n First, start with the model generated chain of thought explanation.\n End the chain of though explanation with:\n Therefore, the answer is {answer}.\n `;\n\n constructor(container: any) {\n this.container = container;\n this.name = this.camelize(this.constructor.name);\n this.tools = this.resolve('tools');\n this.prompt =\n this.resolve('prompt') !== ''\n ? this.resolve('prompt')\n : PromptTemplate.fromTemplate(this.template);\n this.llm = this.resolve('main-llm');\n }\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n\n async run(input: any) {\n const agent = await createStructuredChatAgent({\n llm: this.llm,\n tools: this.tools,\n prompt: this.prompt,\n });\n const agentExecutor = new AgentExecutor({\n agent: agent,\n tools: this.tools,\n // verbose: true,\n handleParsingErrors:\n 'Please try again, paying close attention to the final answer',\n });\n return await agentExecutor.invoke(input);\n }\n}\n","/**\n * Copyright 2024 Bell Eapen\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DynamicStructuredTool } from 'langchain/tools';\nimport mydi from './mydi';\n\nexport class BaseTool extends DynamicStructuredTool {\n container: any;\n name: string;\n description: string;\n schema: any;\n constructor(\n container: any,\n name: string,\n description: string,\n schema: any,\n func: any = null\n ) {\n super({\n name: name,\n description: description,\n schema: schema,\n func: func,\n });\n this.container = container;\n this.name = name === '' ? this.camelize(this.constructor.name) : name;\n this.description =\n description === '' ? this.snake_case(this.constructor.name) : description;\n this.schema = schema;\n }\n\n func = async (args: any) => {\n return 'override this';\n };\n\n resolve(name: string) {\n return mydi(this.container, this.name, name);\n }\n\n camelize(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : word.toUpperCase();\n })\n .replace(/\\s+/g, '');\n }\n\n snake_case(str: string) {\n return str\n .replace(/(?:^\\w|[A-Z]|\\b\\w)/g, function (word, index) {\n return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();\n })\n .replace(/\\s+/g, '');\n }\n}\n"],"names":["mydi","c","m","b","resolve","e","BaseChain","container","name","description","template","tools","prompt","llm","chat_model","runnable","camelize","constructor","snake_case","ChatPromptTemplate","fromTemplate","PromptTemplate","_proto","prototype","str","replace","word","index","toLowerCase","toUpperCase","chain","_chain","_asyncToGenerator","_regeneratorRuntime","mark","_callee","input","response","aiMessage","wrap","_callee$","_context","prev","next","RunnableSequence","from","RunnablePassthrough","invoke","sent","AIMessage","abrupt","content","stop","_x","apply","arguments","BaseAgent","run","_run","agent","agentExecutor","createStructuredChatAgent","AgentExecutor","handleParsingErrors","BaseTool","_DynamicStructuredToo","schema","func","_this","call","_ref","args","_inheritsLoose","DynamicStructuredTool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,WAAW,EAAE,CAAA;AACpE,KAAC,CAAC,CACDH,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;GACvB,CAAA;AAAA,EAAA,OAAAuC,QAAA,CAAA;AAAA,CAAA,CA/C2BS,2BAAqB;;;;;;"}
|
|
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$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AAA,KAAA,CAAA,CAAA;AAAA,oBAAA,KAAA,KAAA;sBAAA,OAAAgB,SAAA,CAAAnJ,IAAA,EAAA,CAAA;AAAA,mBAAA;AAAA,iBAAA,EAAAgJ,QAAA,CAAA,CAAA;eACH,CAAA,CAAA,CAAA;AAAA,cAAA,OAAA,UAAAK,IAAA,EAAA;AAAA,gBAAA,OAAAnI,IAAA,CAAAhB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,eAAA,CAAA;AAAA,aAAA,EAAA,GACD,UAACmJ,MAAW,EAAA;AAAA,cAAA,OAAKnC,MAAI,CAAC3B,eAAe,CAAC8D,MAAM,CAAC,CAAA;AAAA,aAAA,CAC9C,CAAC,CAAA;YAAA,OAAA3B,SAAA,CAAA7H,MAAA,CAAA,QAAA,EAEK2H,QAAQ,CAAC9H,MAAM,CAACX,KAAK,CAAC,CAAA,CAAA;AAAA,UAAA,KAAA,EAAA,CAAA;AAAA,UAAA,KAAA,KAAA;YAAA,OAAA2I,SAAA,CAAA3H,IAAA,EAAA,CAAA;AAAA,SAAA;AAAA,OAAA,EAAAkH,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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@langchain/core/prompts"),e=require("@langchain/core/runnables"),r=require("@langchain/core/messages"),n=require("langchain/agents"),o=require("langchain/tools");function i(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function s(t){i(a,n,o,s,u,"next",t)}function u(t){i(a,n,o,s,u,"throw",t)}s(void 0)}))}}function s(){s=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r,n){return Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n})}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function h(e,r,n,o){var i=Object.create((r&&r.prototype instanceof f?r:f).prototype);return c(i,"_invoke",function(e,r,n){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(n.method=i,n.arg=a;;){var s=n.delegate;if(s){var u=_(s,n);if(u){if(u===p)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(1===o)throw o=4,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=3;var c=l(e,r,n);if("normal"===c.type){if(o=n.done?4:2,c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o=4,n.method="throw",n.arg=c.arg)}}}(e,n,new O(o||[])),!0),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var p={};function f(){}function v(){}function m(){}var d={};c(d,i,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(P([])));w&&w!==r&&n.call(w,i)&&(d=w);var y=m.prototype=f.prototype=Object.create(d);function b(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function r(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&&n.call(h,"__await")?e.resolve(h.__await).then((function(t){r("next",t,a,s)}),(function(t){r("throw",t,a,s)})):e.resolve(h).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,s)}))}s(u.arg)}var o;c(this,"_invoke",(function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}),!0)}function _(e,r){var n=r.method,o=e.i[n];if(o===t)return r.delegate=null,"throw"===n&&e.i.return&&(r.method="return",r.arg=t,_(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),p;var i=l(o,e.i,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,p;var a=i.arg;return a?a.done?(r[e.r]=a.value,r.next=e.n,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,p):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,p)}function E(t){this.tryEntries.push(t)}function k(e){var r=e[4]||{};r.type="normal",r.arg=t,e[4]=r}function O(t){this.tryEntries=[[-1]],t.forEach(E,this),this.reset(!0)}function P(e){if(null!=e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return v.prototype=m,c(y,"constructor",m),c(m,"constructor",v),v.displayName=c(m,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,u,"GeneratorFunction")),t.prototype=Object.create(y),t},e.awrap=function(t){return{__await:t}},b(x.prototype),c(x.prototype,a,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(h(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(y),c(y,u,"Generator"),c(y,i,(function(){return this})),c(y,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},e.values=P,O.prototype={constructor:O,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(k),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=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 r=this;function n(t){a.type="throw",a.arg=e,r.next=t}for(var o=r.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 n("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,n(u),!0;if(s<c)return n(c),!1}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n[0]>-1&&n[0]<=this.prev&&this.prev<n[2]){var o=n;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 r=this.tryEntries[e];if(r[2]===t)return this.complete(r[4],r[3]),k(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r[0]===t){var n=r[4];if("throw"===n.type){var o=n.arg;k(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={i:P(e),r:r,n:n},"next"===this.method&&(this.arg=t),p}},e}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}var c=function(t,e,r){try{return t.resolve(e+"_"+r)}catch(e){return t.resolve(r)}},h=function(){function n(e,r,n,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=""===r?this.camelize(this.constructor.name):r,this.description=""===n?this.snake_case(this.constructor.name):n,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=n.prototype;return o.resolve=function(t){return c(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=a(s().mark((function t(n){var o;return s().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(n);case 4:return o=new r.AIMessage(t.sent),t.abrupt("return",o.content);case 7:return t.next=9,this.runnable.invoke(n);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)}}(),n}(),l=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 r=e.prototype;return r.resolve=function(t){return c(this.container,this.name,t)},r.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,"")},r.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,"")},r.run=function(){var t=a(s().mark((function t(e){var r;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n.createStructuredChatAgent({llm:this.llm,tools:this.tools,prompt:this.prompt});case 2:return r=new n.AgentExecutor({agent:t.sent,tools:this.tools,handleParsingErrors:"Please try again, paying close attention to the final answer"}),t.next=6,r.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}(),p=function(t){function e(e,r,n,o,i){var u;return void 0===i&&(i=null),(u=t.call(this,{name:r,description:n,schema:o,func:i})||this).container=void 0,u.name=void 0,u.description=void 0,u.schema=void 0,u.func=function(){var t=a(s().mark((function t(e){return s().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)}}(),u.container=e,u.name=""===r?u.camelize(u.constructor.name):r,u.description=""===n?u.snake_case(u.constructor.name):n,u.schema=o,u}var r,n;n=t,(r=e).prototype=Object.create(n.prototype),r.prototype.constructor=r,u(r,n);var o=e.prototype;return o.resolve=function(t){return c(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,"")},e}(o.DynamicStructuredTool);exports.BaseAgent=l,exports.BaseChain=h,exports.BaseTool=p;
|
|
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;
|
|
2
2
|
//# sourceMappingURL=medpromptjs.cjs.production.min.js.map
|