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.
- package/dist/llm_loop/base.d.ts +2 -0
- package/dist/medpromptjs.cjs.development.js +86 -19
- 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 +86 -19
- package/dist/medpromptjs.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/llm_loop/base.ts +85 -16
- package/src/llm_loop/map_doc.ts +11 -4
- package/src/llm_loop/map_query.ts +5 -27
- package/src/llm_loop/reduce.ts +17 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"medpromptjs.cjs.production.min.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","this","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","aiMessage","wrap","_context","prev","next","RunnableSequence","from","RunnablePassthrough","invoke","AIMessage","sent","abrupt","content","stop","_x","apply","arguments","BaseAgent","run","_run","agentExecutor","createStructuredChatAgent","AgentExecutor","agent","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","_context2","printValues","JSON","parse","error","info","forEach","element","atob","attachment","data","value","findDatesAndConvertToTimeElapsed","_x2","checkMention","_checkMention","_callee2","_context3","_x3","_x4","checkNegation","_checkNegation","_callee3","_context4","_x5","_x6","text","matches","dateRegex","currentDate","Date","exec","date","timeElapsed","getTime","Math","floor","toString","camelToString","camelCase","stringToBoolean","lowerStr","some","keyword","includes","textSplitter","_textSplitter","_callee4","chunkSize","chunkOverlap","texts","_context5","CharacterTextSplitter","splitText","warn","_x7","_x8","_x9","obj","_this2","key","regex","RegExp","_callee8","_yield$import","RunnableParallel","mapQueryChain","mapDocChain","parallelChain","sequence","_this3","_context9","import","assign","query","_query","_callee5","_context6","_x1","documents","_documents","_callee6","_context7","Promise","all","map","chunk","document","question","_x10","_callee7","results","_context8","facts","_x11","result","_x0"],"mappings":"09MAgBA,IAAMA,EAAO,SAACC,EAAQC,EAAWC,GAC/B,IACE,OAAOF,EAAEG,QAAQF,EAAI,IAAMC,EAC5B,CAAC,MAAOE,GACP,OAAOJ,EAAEG,QAAQD,EACnB,CACF,ECIaG,EAAS,WAWpB,SAAAA,EACEC,EACAC,EACAC,EACAC,QAAmB,IAAnBA,IAAAA,EAAmB,8DAAAC,KAdrBJ,eAAS,EAAAI,KACTC,WAAK,EAAAD,KACLH,UAAI,EAAAG,KACJF,iBAAW,EAAAE,KACXE,YAAM,EAAAF,KACNG,SAAG,EAAAH,KACHD,cAAQ,EAAAC,KACRI,gBAAU,EAAAJ,KACVK,cAAQ,EAWNL,KAAKJ,UAAYA,EACjBI,KAAKH,KAAgB,KAATA,EAAcG,KAAKM,SAASN,KAAKO,YAAYV,MAAQA,EACjEG,KAAKF,YACa,KAAhBA,EAAqBE,KAAKQ,WAAWR,KAAKO,YAAYV,MAAQC,EAChEE,KAAKD,SAAWA,EAChBC,KAAKC,MAAQD,KAAKP,QAAQ,SAC1BO,KAAKG,IAAMH,KAAKP,QAAQ,YACxBO,KAAKI,YAAa,EAClB,IACEJ,KAAKI,WAAaJ,KAAKP,QAAQ,aACjC,CAAE,MAAOC,GAAI,CAEXM,KAAKE,OADHF,KAAKI,WACOK,EAAkBA,mBAACC,aAAaV,KAAKD,UAErCY,EAAcA,eAACD,aAAaV,KAAKD,SAEnD,CAAC,IAAAa,EAAAjB,EAAAkB,UAwBU,OAxBVD,EAEDnB,QAAA,SAAQI,GACN,OAAOR,EAAKW,KAAKJ,UAAWI,KAAKH,KAA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GAAY,OAAAxJ,IAAAK,MAAA,SAAAoJ,GAAA,cAAAA,EAAAlJ,KAAAkJ,EAAAjJ,MAAA,KAAA,EAGqB,OAAAiJ,EAAA1I,OAAA,SAC/BoH,EAAK7E,YAAYzD,MAAM,CAC5BM,MAAO,CACLoI,MAJUiB,EAAQ,GAAGjB,MAKrBmB,MAJcF,EAAQ,GAAGZ,cAM3B,KAAA,EAAA,IAAA,MAAA,OAAAa,EAAAxI,OAAA,GAAAsI,EACH,KAAA,OAAA,SAAAI,GAAA,OAAAxH,EAAAhB,MAAA1C,KAAA2C,UAAA,CAAA,CAXY,GAYb,SAACwI,GAAW,OAAKzB,EAAK9B,gBAAgBuD,EAAO,IAC7CxB,EAAArH,OAAA,SAEKmH,EAAStH,OAAOT,IAAM,KAAA,GAAA,IAAA,MAAA,OAAAiI,EAAAnH,OAAA,GAAA2G,EAC9B,KAjDU,OAiDV,SAjDUiC,GAAA,OAAA/J,EAAAqB,MAAA1C,KAAA2C,UAAA,CAAA,CAAA,GAAA8B,CAAA,EAtKgB9E"}
|
|
1
|
+
{"version":3,"file":"medpromptjs.cjs.production.min.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","this","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","aiMessage","wrap","_context","prev","next","RunnableSequence","from","RunnablePassthrough","invoke","AIMessage","sent","abrupt","content","stop","_x","apply","arguments","BaseAgent","run","_run","agentExecutor","createStructuredChatAgent","AgentExecutor","agent","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","_context3","_x3","_x4","checkNegation","_checkNegation","_callee3","_context4","_x5","_x6","text","matches","dateRegex","currentDate","Date","exec","date","timeElapsed","getTime","Math","floor","toString","camelToString","camelCase","stringToBoolean","lowerStr","some","keyword","includes","textSplitter","_textSplitter","_callee4","chunkSize","chunkOverlap","texts","_context5","CharacterTextSplitter","splitText","_x7","_x8","_x9","obj","arg","where","extractObjectsByKey","join","key","results","traverse","currentKey","hasOwnProperty","push","_printValues","_this2","regex","RegExp","_callee8","_yield$import","RunnableParallel","mapQueryChain","mapDocChain","parallelChain","sequence","_this3","_context9","import","assign","query","_query","_callee5","_context6","_x1","documents","_documents","_callee6","_context7","Promise","all","map","chunk","document","statements","_x10","_callee7","_context8","stringify","facts","_x11","_x0"],"mappings":"m9MAgBA,IAAMA,EAAO,SAACC,EAAQC,EAAWC,GAC/B,IACE,OAAOF,EAAEG,QAAQF,EAAI,IAAMC,EAC5B,CAAC,MAAOE,GACP,OAAOJ,EAAEG,QAAQD,EACnB,CACF,ECIaG,EAAS,WAWpB,SAAAA,EACEC,EACAC,EACAC,EACAC,QAAmB,IAAnBA,IAAAA,EAAmB,8DAAAC,KAdrBJ,eAAS,EAAAI,KACTC,WAAK,EAAAD,KACLH,UAAI,EAAAG,KACJF,iBAAW,EAAAE,KACXE,YAAM,EAAAF,KACNG,SAAG,EAAAH,KACHD,cAAQ,EAAAC,KACRI,gBAAU,EAAAJ,KACVK,cAAQ,EAWNL,KAAKJ,UAAYA,EACjBI,KAAKH,KAAgB,KAATA,EAAcG,KAAKM,SAASN,KAAKO,YAAYV,MAAQA,EACjEG,KAAKF,YACa,KAAhBA,EAAqBE,KAAKQ,WAAWR,KAAKO,YAAYV,MAAQC,EAChEE,KAAKD,SAAWA,EAChBC,KAAKC,MAAQD,KAAKP,QAAQ,SAC1BO,KAAKG,IAAMH,KAAKP,QAAQ,YACxBO,KAAKI,YAAa,EAClB,IACEJ,KAAKI,WAAaJ,KAAKP,QAAQ,aACjC,CAAE,MAAOC,GAAI,CAEXM,KAAKE,OADHF,KAAKI,WACOK,EAAkBA,mBAACC,aAAaV,KAAKD,UAErCY,EAAcA,eAACD,aAAaV,KAAKD,SAEnD,CAAC,IAAAa,EAAAjB,EAAAkB,UAwBU,OAxBVD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AAUtC,IAGlBqC,EAAAvJ,OAAA,SAC/BkI,EAAK3F,YAAYzD,MAAM,CAC5BM,MAAO,CACLqK,MAHcvC,EAAQ,GAAGyB,UAIzBL,MALUpB,EAAQ,GAAGoB,MAKN,IANApB,EAAQ,GAAG9H,MAAMsD,eAQlC,KAAA,EAAA,IAAA,MAAA,OAAA6G,EAAArJ,OAAA,GAAAoJ,EACH,KAAA,OAAA,SAAAI,GAAA,OAAAtI,EAAAhB,MAAA1C,KAAA2C,UAAA,CAAA,CAhCY,GAiCb,SAAC0C,GAAW,OAAKmF,EAAKvC,gBAAgB5C,EAAO,IAC7CoF,EAAAnI,OAAA,SAEKiI,EAASpI,OAAOT,IAAM,KAAA,GAAA,IAAA,MAAA,OAAA+I,EAAAjI,OAAA,GAAAyH,EAC9B,KAtEU,OAsEV,SAtEUgC,GAAA,OAAA5K,EAAAqB,MAAA1C,KAAA2C,UAAA,CAAA,CAAA,GAAA8B,CAAA,EAtNgB9E"}
|
package/dist/medpromptjs.esm.js
CHANGED
|
@@ -47,7 +47,7 @@ function _regeneratorRuntime() {
|
|
|
47
47
|
a = o.asyncIterator || "@@asyncIterator",
|
|
48
48
|
u = o.toStringTag || "@@toStringTag";
|
|
49
49
|
function c(t, r, e, n) {
|
|
50
|
-
|
|
50
|
+
Object.defineProperty(t, r, {
|
|
51
51
|
value: e,
|
|
52
52
|
enumerable: !n,
|
|
53
53
|
configurable: !n,
|
|
@@ -198,7 +198,7 @@ function _regeneratorRuntime() {
|
|
|
198
198
|
}
|
|
199
199
|
throw new TypeError(typeof r + " is not iterable");
|
|
200
200
|
}
|
|
201
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction),
|
|
201
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), c(GeneratorFunctionPrototype, u, GeneratorFunction.displayName = "GeneratorFunction"), r.isGeneratorFunction = function (t) {
|
|
202
202
|
var r = "function" == typeof t && t.constructor;
|
|
203
203
|
return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name));
|
|
204
204
|
}, r.mark = function (t) {
|
|
@@ -548,7 +548,7 @@ var MapQuery = /*#__PURE__*/function (_BaseChain) {
|
|
|
548
548
|
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
549
549
|
_this.name = 'MapQuery';
|
|
550
550
|
_this.description = 'Map a CQL query to a natural language.';
|
|
551
|
-
_this.template = "\n
|
|
551
|
+
_this.template = "\n You are an assistant that can convert statements to a natural language query as in the example below.\n\n\n\n Statements: Visual foot exam in the last month. Visual foot exam showed active infection.\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n Statements: {expression}\n query: ";
|
|
552
552
|
return _this;
|
|
553
553
|
}
|
|
554
554
|
_inheritsLoose(MapQuery, _BaseChain);
|
|
@@ -564,7 +564,7 @@ var MapDoc = /*#__PURE__*/function (_BaseChain) {
|
|
|
564
564
|
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
565
565
|
_this.name = 'MapDoc';
|
|
566
566
|
_this.description = 'Map a set of documents to facts.';
|
|
567
|
-
_this.template = "\n You will be given a document and
|
|
567
|
+
_this.template = "\n You will be given a document and few statements.\n\n Extract facts from the document that are relevant to the statements.\n\n Do not include any irrelevant information or context.\n\n\n \n Example:\n\n document: The patient is a 45-year-old male with a history of hypertension. He presented with chest pain and was diagnosed with myocardial infarction. He was treated with aspirin and beta-blockers.\n\n statements: diagnosis of myocardial infarction. currently on beta-blockers.\n\n facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\n\n document: {document} \n\n statements: {statements}\n\n facts: ";
|
|
568
568
|
return _this;
|
|
569
569
|
}
|
|
570
570
|
_inheritsLoose(MapDoc, _BaseChain);
|
|
@@ -580,7 +580,7 @@ var ReduceChain = /*#__PURE__*/function (_BaseChain) {
|
|
|
580
580
|
_this = _BaseChain.call.apply(_BaseChain, [this].concat(args)) || this;
|
|
581
581
|
_this.name = 'Reduce';
|
|
582
582
|
_this.description = 'Reduce a set of documents to binary answer.';
|
|
583
|
-
_this.template = "\n
|
|
583
|
+
_this.template = "\n Say yes if the facts mentions all aspects of the query, else say no.\n\n\n Example:\n facts: Patient had a laproscopy 27 days back. The findings were normal. \n\n query: Did the patient have a laproscopy this month?\n\n answer: YES. The patient had a laproscopy 27 days back.\n\n facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \n\n query: Is the patient on heparin and metformin?\n\n answer: NO. The patient is on heparin but not on metformin.\n\n facts: A visual foot examination was performed 26 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\n\n facts: A visual foot examination was performed 126 days ago to assess skin integrity, circulation, and structural abnormalities. The exam revealed normal skin condition, nail health, circulation, and absence of edema and deformities. However, there were signs of an active infection with erythema and swelling. \n\n query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n\n answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\n\n facts: {facts} \n\n query: {query}\n\n answer: ";
|
|
584
584
|
return _this;
|
|
585
585
|
}
|
|
586
586
|
_inheritsLoose(ReduceChain, _BaseChain);
|
|
@@ -608,13 +608,11 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
608
608
|
var _proto = LLMLoop.prototype;
|
|
609
609
|
_proto.checkAssertion = /*#__PURE__*/function () {
|
|
610
610
|
var _checkAssertion = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(expression, context) {
|
|
611
|
-
var _expression, _context, _content, _input;
|
|
611
|
+
var _expression, _context, _content, _input, result;
|
|
612
612
|
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
613
613
|
while (1) switch (_context2.prev = _context2.next) {
|
|
614
614
|
case 0:
|
|
615
615
|
_expression = '';
|
|
616
|
-
_context = undefined;
|
|
617
|
-
_content = '';
|
|
618
616
|
try {
|
|
619
617
|
// Check if expression is a valid JSON string
|
|
620
618
|
_expression = this.printValues(JSON.parse(expression));
|
|
@@ -622,24 +620,44 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
622
620
|
_expression = expression; // If not, use the expression as is
|
|
623
621
|
}
|
|
624
622
|
log.info("Checking assertion with expression: " + _expression);
|
|
623
|
+
// Initialize context and content
|
|
624
|
+
_context = undefined;
|
|
625
|
+
_content = '';
|
|
626
|
+
try {
|
|
627
|
+
_context = JSON.parse(context);
|
|
628
|
+
} catch (error) {
|
|
629
|
+
_context = context; // If not, use the context as is
|
|
630
|
+
log.warn("Context is not a valid JSON string: " + context);
|
|
631
|
+
log.warn("Using context as a string: " + _context);
|
|
632
|
+
}
|
|
625
633
|
try {
|
|
626
634
|
// Check if context is a valid JSON string
|
|
627
635
|
_context = JSON.parse(context);
|
|
628
636
|
_context.forEach(function (element) {
|
|
629
|
-
|
|
637
|
+
element.content.forEach(function (contentItem) {
|
|
638
|
+
_content += atob(contentItem.attachment.data.value);
|
|
639
|
+
});
|
|
630
640
|
});
|
|
631
641
|
} catch (error) {
|
|
632
642
|
_content = context; // If not, use the context as is
|
|
643
|
+
log.warn("Context is not a valid JSON : " + context);
|
|
644
|
+
log.warn("Using context as a string: " + _content);
|
|
633
645
|
}
|
|
634
646
|
_content = this.findDatesAndConvertToTimeElapsed(_content.replace(/(\r\n|\n|\r)/gm, ' '));
|
|
647
|
+
log.info("Checking assertion with context: " + _content);
|
|
635
648
|
_input = {
|
|
636
649
|
input: {
|
|
637
650
|
expression: _expression,
|
|
638
651
|
context: _content
|
|
639
652
|
}
|
|
640
653
|
};
|
|
641
|
-
|
|
642
|
-
|
|
654
|
+
_context2.next = 12;
|
|
655
|
+
return this.chain(_input);
|
|
656
|
+
case 12:
|
|
657
|
+
result = _context2.sent;
|
|
658
|
+
log.info("Assertion check result: " + result);
|
|
659
|
+
return _context2.abrupt("return", result);
|
|
660
|
+
case 15:
|
|
643
661
|
case "end":
|
|
644
662
|
return _context2.stop();
|
|
645
663
|
}
|
|
@@ -715,7 +733,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
715
733
|
};
|
|
716
734
|
_proto.stringToBoolean = function stringToBoolean(str) {
|
|
717
735
|
log.info("Converting string to boolean: " + str);
|
|
718
|
-
var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed'];
|
|
736
|
+
var positiveKeywords = ['true', 'contains', 'confirms', 'yes', 'affirmative', 'matches', 'exists', 'present', 'absolutely', 'certainly', 'definitely', 'indeed', 'did have', 'showed', 'revealed'];
|
|
719
737
|
var lowerStr = str.toLowerCase();
|
|
720
738
|
return positiveKeywords.some(function (keyword) {
|
|
721
739
|
return lowerStr.includes(keyword);
|
|
@@ -768,10 +786,38 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
768
786
|
return textSplitter;
|
|
769
787
|
}();
|
|
770
788
|
_proto.printValues = function printValues(obj) {
|
|
789
|
+
log.info("Processing Rule: " + obj.name + " for " + obj.context);
|
|
790
|
+
// For each obj.expression:arg:where
|
|
791
|
+
if (obj.expression && obj.expression.arg && obj.expression.arg.where) {
|
|
792
|
+
// for each args in obj.expression.arg.where, extract the nested key called "value"
|
|
793
|
+
var statements = this.extractObjectsByKey(obj.expression.arg.where, 'value');
|
|
794
|
+
return statements.join(' ').replace(/,/g, ' ');
|
|
795
|
+
}
|
|
796
|
+
// return statements array as a string seperated by space
|
|
797
|
+
return '';
|
|
798
|
+
};
|
|
799
|
+
_proto.extractObjectsByKey = function extractObjectsByKey(obj, key) {
|
|
800
|
+
var results = [];
|
|
801
|
+
function traverse(obj) {
|
|
802
|
+
for (var currentKey in obj) {
|
|
803
|
+
if (obj.hasOwnProperty(currentKey)) {
|
|
804
|
+
if (currentKey === key) {
|
|
805
|
+
results.push(obj[currentKey]);
|
|
806
|
+
}
|
|
807
|
+
if (typeof obj[currentKey] === 'object' && obj[currentKey] !== null) {
|
|
808
|
+
traverse(obj[currentKey]);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
traverse(obj);
|
|
814
|
+
return results;
|
|
815
|
+
};
|
|
816
|
+
_proto._printValues = function _printValues(obj) {
|
|
771
817
|
var _this2 = this;
|
|
772
818
|
for (var key in obj) {
|
|
773
819
|
if (typeof obj[key] === 'object') {
|
|
774
|
-
this.
|
|
820
|
+
this._printValues(obj[key]);
|
|
775
821
|
} else {
|
|
776
822
|
this.string_expression += obj[key] + ' ';
|
|
777
823
|
}
|
|
@@ -836,7 +882,7 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
836
882
|
return _this3.mapDoc.chain({
|
|
837
883
|
input: {
|
|
838
884
|
document: chunk,
|
|
839
|
-
|
|
885
|
+
statements: input.input.expression
|
|
840
886
|
}
|
|
841
887
|
});
|
|
842
888
|
})));
|
|
@@ -855,20 +901,41 @@ var LLMLoop = /*#__PURE__*/function (_BaseChain) {
|
|
|
855
901
|
parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
|
|
856
902
|
sequence = RunnableSequence.from([parallelChain, (/*#__PURE__*/function () {
|
|
857
903
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(results) {
|
|
858
|
-
var query, documents;
|
|
904
|
+
var expression, query, documents;
|
|
859
905
|
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
|
|
860
906
|
while (1) switch (_context8.prev = _context8.next) {
|
|
861
907
|
case 0:
|
|
862
|
-
|
|
908
|
+
/* results is an array: [{ query: ... }, { documents: [...] }]
|
|
909
|
+
{
|
|
910
|
+
"0": {
|
|
911
|
+
"input": {
|
|
912
|
+
"expression": "0 Visual foot exam showed active infection?",
|
|
913
|
+
"context": "Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. "
|
|
914
|
+
},
|
|
915
|
+
"query": "The text indicates a question about whether a visual foot exam revealed an active infection.\n"
|
|
916
|
+
},
|
|
917
|
+
"1": {
|
|
918
|
+
"input": {
|
|
919
|
+
"expression": "0 Visual foot exam showed active infection?",
|
|
920
|
+
"context": "Procedure: The patient underwent a visual foot examination on 26 days ago. to assess skin integrity, circulation, and structural abnormalities. Findings: - Skin Condition: No signs of dryness, cracking, or ulceration were observed. No abnormal lesions or discoloration present. - Nail Health: Toenails appeared intact with no evidence of fungal infection or ingrown nails. - Circulation: Normal coloration, with no signs of cyanosis or pallor. Capillary refill time within normal limits. - Edema: No visible swelling in the feet or ankles. - Deformities: No structural abnormalities such as bunions, hammertoes, or Charcot foot deformities noted. - Infections: Showed signs of active infection with erythema and swelling. - Sensation: No visible signs of neuropathy, though further testing may be required to assess sensory deficits. "
|
|
921
|
+
},
|
|
922
|
+
"documents": [
|
|
923
|
+
"26 days ago, a visual foot examination revealed no dryness, cracking, ulceration, lesions, discoloration, fungal infection, ingrown nails, cyanosis, pallor, edema, bunions, hammertoes, or Charcot foot deformities. Circulation and capillary refill were normal. However, the exam showed signs"
|
|
924
|
+
]
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
*/
|
|
928
|
+
log.info("Results from parallel chain: " + JSON.stringify(results));
|
|
929
|
+
expression = results[0].input.expression;
|
|
863
930
|
query = results[0].query;
|
|
864
931
|
documents = results[1].documents;
|
|
865
932
|
return _context8.abrupt("return", _this3.reduceChain.chain({
|
|
866
933
|
input: {
|
|
867
|
-
|
|
868
|
-
|
|
934
|
+
facts: documents,
|
|
935
|
+
query: query + ' ' + expression
|
|
869
936
|
}
|
|
870
937
|
}));
|
|
871
|
-
case
|
|
938
|
+
case 5:
|
|
872
939
|
case "end":
|
|
873
940
|
return _context8.stop();
|
|
874
941
|
}
|