medpromptjs 0.3.1 → 0.4.0

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.
@@ -0,0 +1,357 @@
1
+ import { BaseChain } from './chain';
2
+ import { CharacterTextSplitter } from '@langchain/textsplitters';
3
+ import { Logger, ILogObj } from 'tslog';
4
+
5
+ const log: Logger<ILogObj> = new Logger();
6
+ export class LLMLoop extends BaseChain {
7
+ // Implement the LLM loop logic here
8
+ stringExpression: string = '';
9
+ _mapQueryTemplate: string = `
10
+ You are an assistant that can convert statements to a natural language query as in the example below.\n
11
+
12
+
13
+ Statements: Visual foot exam in the last month. Visual foot exam showed active infection.
14
+ query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?
15
+ Statements: {expression}
16
+ query: `;
17
+
18
+ _mapDocTemplate: string = `
19
+ You will be given a document and few statements.\n
20
+ Extract facts from the document that are relevant to the statements.\n
21
+ Do not include any irrelevant information or context.\n
22
+
23
+
24
+ Example:\n
25
+ 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
26
+ statements: diagnosis of myocardial infarction. currently on beta-blockers.\n
27
+ facts: The patient was diagnosed with myocardial infarction and is currently on beta-blockers.\n
28
+ document: {document} \n
29
+ statements: {statements}\n
30
+ facts: `;
31
+
32
+ _reduceChainTemplate: string = `
33
+ Say yes if the facts mentions all aspects of the query, else say no.\n
34
+
35
+ Example:
36
+ facts: Patient had a laproscopy 27 days back. The findings were normal. \n
37
+ query: Did the patient have a laproscopy this month?\n
38
+ answer: YES. The patient had a laproscopy 27 days back.\n
39
+ facts: The patient is a diabetic and hypertensive. He is on metformin and amlodipine. \n
40
+ query: Is the patient on heparin and metformin?\n
41
+ answer: NO. The patient is on heparin but not on metformin.\n
42
+ 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
43
+ query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n
44
+ answer: YES. The patient had a visual foot exam in the last month and there is evidence of active infection.\n
45
+ 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
46
+ query: Did the patient have a visual foot exam in the last month? Is there any evidence of active infection?\n
47
+ answer: NO. The patient did not have a visual foot exam in the last month but there is evidence of active infection.\n
48
+ facts: {facts} \n
49
+ query: {query}\n
50
+ answer: `;
51
+
52
+ // Add getters and setters for the templates if needed
53
+ get mapQueryTemplate(): string {
54
+ return this._mapQueryTemplate;
55
+ }
56
+ set mapQueryTemplate(template: string) {
57
+ this._mapQueryTemplate = template;
58
+ }
59
+ get mapDocTemplate(): string {
60
+ return this._mapDocTemplate;
61
+ }
62
+ set mapDocTemplate(template: string) {
63
+ this._mapDocTemplate = template;
64
+ }
65
+ get reduceChainTemplate(): string {
66
+ return this._reduceChainTemplate;
67
+ }
68
+ set reduceChainTemplate(template: string) {
69
+ this._reduceChainTemplate = template;
70
+ }
71
+
72
+ async checkAssertion(expression: string, context: any): Promise<boolean> {
73
+ let _expression: string = '';
74
+ try {
75
+ // Check if expression is a valid JSON string
76
+ _expression = this.printValues(JSON.parse(expression));
77
+ } catch (error) {
78
+ _expression = expression; // If not, use the expression as is
79
+ }
80
+
81
+ log.info(`Checking assertion with expression: ${_expression}`);
82
+ // Initialize context and content
83
+ let _context: any = undefined;
84
+ let _content: string = '';
85
+ try {
86
+ _context = JSON.parse(context);
87
+ } catch (error) {
88
+ _context = context; // If not, use the context as is
89
+ log.warn(`Context is not a valid JSON string: ${context}`);
90
+ log.warn(`Using context as a string: ${_context}`);
91
+ }
92
+ try {
93
+ // Check if context is a valid JSON string
94
+ _context = JSON.parse(context);
95
+ _context.forEach((element: any) => {
96
+ element.content.forEach((contentItem: any) => {
97
+ _content += atob(contentItem.attachment.data.value);
98
+ });
99
+ });
100
+ } catch (error) {
101
+ _content = context; // If not, use the context as is
102
+ log.warn(`Context is not a valid JSON : ${context}`);
103
+ log.warn(`Using context as a string: ${_content}`);
104
+ }
105
+ _content = this.findDatesAndConvertToTimeElapsed(
106
+ _content.replace(/(\r\n|\n|\r)/gm, ' ')
107
+ );
108
+ log.info(`Checking assertion with context: ${_content}`);
109
+ const _input = {
110
+ input: {
111
+ expression: _expression,
112
+ context: _content,
113
+ },
114
+ };
115
+ const result = await this.chain(_input);
116
+ log.info(`Assertion check result: ${result}`);
117
+ return result;
118
+ }
119
+
120
+ async checkMention(expression: string, context: any): Promise<boolean> {
121
+ if (expression && context) return true; // Placeholder for assertion check logic
122
+ return false;
123
+ }
124
+
125
+ async checkNegation(expression: string, context: any): Promise<boolean> {
126
+ if (expression && context) return true; // Placeholder for assertion check logic
127
+ return false;
128
+ }
129
+
130
+ findDatesAndConvertToTimeElapsed(text: string): string {
131
+ // Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'
132
+ const dateRegex = /(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g;
133
+ let matches;
134
+ let currentDate = new Date();
135
+
136
+ while ((matches = dateRegex.exec(text)) !== null) {
137
+ let date = new Date(matches[0]);
138
+ let timeElapsed =
139
+ (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);
140
+ text = text.replace(
141
+ matches[0],
142
+ Math.floor(timeElapsed).toString() + ' days ago.'
143
+ );
144
+ }
145
+ return text;
146
+ }
147
+
148
+ camelToString(camelCase: string): string {
149
+ return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
150
+ return str.toUpperCase();
151
+ });
152
+ }
153
+
154
+ stringToBoolean(str: string): boolean {
155
+ log.info(`Converting string to boolean: ${str}`);
156
+ const positiveKeywords = [
157
+ 'true',
158
+ 'contains',
159
+ 'confirms',
160
+ 'yes',
161
+ 'affirmative',
162
+ 'matches',
163
+ 'exists',
164
+ 'present',
165
+ 'absolutely',
166
+ 'certainly',
167
+ 'definitely',
168
+ 'indeed',
169
+ 'did have',
170
+ 'showed',
171
+ 'revealed',
172
+ ];
173
+ const lowerStr = str.toLowerCase();
174
+ return positiveKeywords.some((keyword) => lowerStr.includes(keyword));
175
+ }
176
+
177
+ async textSplitter(
178
+ text: string,
179
+ chunkSize: number = 3900,
180
+ chunkOverlap: number = 0
181
+ ): Promise<string[]> {
182
+ const textSplitter = new CharacterTextSplitter({
183
+ chunkSize: chunkSize,
184
+ chunkOverlap: chunkOverlap,
185
+ });
186
+ const texts = await textSplitter.splitText(text);
187
+ // Log the number of chunks created
188
+ if (texts.length === 0) {
189
+ log.warn('No text chunks created. Please check the input text.');
190
+ return [];
191
+ }
192
+ if (texts.length > 100) {
193
+ log.warn(
194
+ `Warning: More than 100 text chunks created (${texts.length}). This may affect performance.`
195
+ );
196
+ }
197
+ if (chunkSize < 1000) {
198
+ log.warn(
199
+ `Warning: Chunk size is less than 1000 characters (${chunkSize}). This may lead to very small chunks.`
200
+ );
201
+ }
202
+ log.info(
203
+ `Text split into ${texts.length} chunks with size ${chunkSize} and overlap ${chunkOverlap}`
204
+ );
205
+ return texts;
206
+ }
207
+
208
+ printValues(obj: any) {
209
+ log.info(`Processing Rule: ${obj.name} for ${obj.context}`);
210
+ // For each obj.expression:arg:where
211
+ if (obj.expression && obj.expression.arg && obj.expression.arg.where) {
212
+ // for each args in obj.expression.arg.where, extract the nested key called "value"
213
+ const statements = this.extractObjectsByKey(
214
+ obj.expression.arg.where,
215
+ 'value'
216
+ );
217
+ return statements.join(' ').replace(/,/g, ' ');
218
+ }
219
+ // return statements array as a string seperated by space
220
+ return '';
221
+ }
222
+
223
+ extractObjectsByKey(obj: any, key: string): any[] {
224
+ const results: any[] = [];
225
+
226
+ function traverse(obj: any) {
227
+ for (const currentKey in obj) {
228
+ if (obj.hasOwnProperty(currentKey)) {
229
+ if (currentKey === key) {
230
+ results.push(obj[currentKey]);
231
+ }
232
+ if (typeof obj[currentKey] === 'object' && obj[currentKey] !== null) {
233
+ traverse(obj[currentKey]);
234
+ }
235
+ }
236
+ }
237
+ }
238
+
239
+ traverse(obj);
240
+ return results;
241
+ }
242
+
243
+ _printValues(obj: any) {
244
+ for (var key in obj) {
245
+ if (typeof obj[key] === 'object') {
246
+ this._printValues(obj[key]);
247
+ } else {
248
+ this.stringExpression += obj[key] + ' ';
249
+ }
250
+ }
251
+ const _eliminate = [
252
+ 'true',
253
+ 'false',
254
+ 'null',
255
+ 'undefined',
256
+ 'String',
257
+ 'Number',
258
+ 'Object',
259
+ 'Array',
260
+ 'Boolean',
261
+ 'value',
262
+ 'Type',
263
+ 'Specifier',
264
+ 'Named',
265
+ ];
266
+ _eliminate.forEach((element) => {
267
+ const regex = new RegExp(element, 'g');
268
+ this.stringExpression = this.stringExpression.replace(regex, '');
269
+ });
270
+ this.stringExpression = this.stringExpression.replace(
271
+ /(?:https?|ftp):\/\/[\n\S]+/g,
272
+ ''
273
+ );
274
+ return this.camelToString(this.stringExpression);
275
+ }
276
+
277
+ async chain(input: any) {
278
+ // Create a chain using RunnableSequence, RunnablePassthrough and RunnableParallel
279
+ // input has two properties: expression and context
280
+ // expression goes through mapQuery and parallely
281
+ // context goes through textSplitter and mapDoc
282
+ // Finally reduceChain is called with the results of mapQuery and mapDoc
283
+ // LCEL-based implementation using RunnableSequence, RunnableParallel, and RunnablePassthrough
284
+ const { RunnableSequence, RunnableParallel, RunnablePassthrough } =
285
+ await import('@langchain/core/runnables');
286
+
287
+ const mapQuery: BaseChain = new BaseChain(this.container);
288
+ const mapDoc: BaseChain = new BaseChain(this.container);
289
+ const reduceChain: BaseChain = new BaseChain(this.container);
290
+ mapQuery.name = 'MapQuery';
291
+ mapQuery.description = 'Map the expression to a natural language query.';
292
+ mapQuery.template = this._mapQueryTemplate;
293
+ mapDoc.name = 'MapDoc';
294
+ mapDoc.description = 'Map the document to a set of facts.';
295
+ mapDoc.template = this._mapDocTemplate;
296
+ reduceChain.name = 'ReduceChain';
297
+ reduceChain.description = 'Reduce a set of documents to binary answer.';
298
+ reduceChain.template = this._reduceChainTemplate;
299
+ const mapQueryChain = RunnablePassthrough.assign({
300
+ query: async (input: any) =>
301
+ mapQuery.chain({ expression: input.input.expression }),
302
+ });
303
+
304
+ const mapDocChain = RunnablePassthrough.assign({
305
+ documents: async (input: any) => {
306
+ const textChunks = await this.textSplitter(input.input.context);
307
+ return Promise.all(
308
+ textChunks.map((chunk) =>
309
+ mapDoc.chain({
310
+ document: chunk,
311
+ statements: input.input.expression,
312
+ })
313
+ )
314
+ );
315
+ },
316
+ });
317
+
318
+ const parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
319
+
320
+ const sequence = RunnableSequence.from([
321
+ parallelChain,
322
+ async (results: any) => {
323
+ /* results is an array: [{ query: ... }, { documents: [...] }]
324
+ {
325
+ "0": {
326
+ "input": {
327
+ "expression": "0 Visual foot exam showed active infection?",
328
+ "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. "
329
+ },
330
+ "query": "The text indicates a question about whether a visual foot exam revealed an active infection.\n"
331
+ },
332
+ "1": {
333
+ "input": {
334
+ "expression": "0 Visual foot exam showed active infection?",
335
+ "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. "
336
+ },
337
+ "documents": [
338
+ "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"
339
+ ]
340
+ }
341
+ }
342
+ */
343
+ log.info(`Results from parallel chain: ${JSON.stringify(results)}`);
344
+ const expression = results[0].input.expression;
345
+ const query = results[0].query;
346
+ const documents = results[1].documents;
347
+ return reduceChain.chain({
348
+ facts: documents,
349
+ query: query + ' ' + expression,
350
+ });
351
+ },
352
+ (result: any) => this.stringToBoolean(result),
353
+ ]);
354
+
355
+ return sequence.invoke(input);
356
+ }
357
+ }
@@ -1,4 +0,0 @@
1
- export { MapQuery } from './map_query';
2
- export { MapDoc } from './map_doc';
3
- export { ReduceChain } from './reduce';
4
- export { LLMLoop } from './base';
@@ -1,6 +0,0 @@
1
- import { BaseChain } from '../chain';
2
- export declare class MapDoc extends BaseChain {
3
- name: string;
4
- description: string;
5
- template: string;
6
- }
@@ -1,6 +0,0 @@
1
- import { BaseChain } from '../chain';
2
- export declare class MapQuery extends BaseChain {
3
- name: string;
4
- description: string;
5
- template: string;
6
- }
@@ -1,6 +0,0 @@
1
- import { BaseChain } from '../chain';
2
- export declare class ReduceChain extends BaseChain {
3
- name: string;
4
- description: string;
5
- template: string;
6
- }
@@ -1,225 +0,0 @@
1
- import { BaseChain } from '../chain';
2
- import { MapQuery } from './map_query';
3
- import { CharacterTextSplitter } from '@langchain/textsplitters';
4
- import { ReduceChain } from './reduce';
5
- import { MapDoc } from './map_doc';
6
- import { Logger, ILogObj } from 'tslog';
7
-
8
- const log: Logger<ILogObj> = new Logger();
9
- export class LLMLoop extends BaseChain {
10
- // Implement the LLM loop logic here
11
- string_expression: string = '';
12
- name: string = 'LLMLoop';
13
- description: string = 'Base LLM Loop.';
14
- mapQuery: MapQuery = new MapQuery(this.container, '', '');
15
- mapDoc: MapDoc = new MapDoc(this.container, '', '');
16
- reduceChain: ReduceChain = new ReduceChain(this.container, '', '');
17
-
18
- async checkAssertion(expression: string, context: any): Promise<boolean> {
19
- let _expression: string = '';
20
- let _context: any = undefined;
21
- let _content: string = '';
22
- try {
23
- // Check if expression is a valid JSON string
24
- _expression = this.printValues(JSON.parse(expression));
25
- } catch (error) {
26
- _expression = expression; // If not, use the expression as is
27
- }
28
- log.info(`Checking assertion with expression: ${_expression}`);
29
- try {
30
- // Check if context is a valid JSON string
31
- _context = JSON.parse(context);
32
- _context.forEach(
33
- (element: {
34
- content: { attachment: { data: { value: string } } }[];
35
- }) => {
36
- _content += atob(element.content[0].attachment.data.value);
37
- }
38
- );
39
- } catch (error) {
40
- _content = context; // If not, use the context as is
41
- }
42
-
43
- _content = this.findDatesAndConvertToTimeElapsed(
44
- _content.replace(/(\r\n|\n|\r)/gm, ' ')
45
- );
46
- const _input = {
47
- input: {
48
- expression: _expression,
49
- context: _content,
50
- },
51
- };
52
-
53
- return this.chain(_input);
54
- }
55
-
56
- async checkMention(expression: string, context: any): Promise<boolean> {
57
- if (expression && context) return true; // Placeholder for assertion check logic
58
- return false;
59
- }
60
-
61
- async checkNegation(expression: string, context: any): Promise<boolean> {
62
- if (expression && context) return true; // Placeholder for assertion check logic
63
- return false;
64
- }
65
-
66
- findDatesAndConvertToTimeElapsed(text: string): string {
67
- // Regular expression to match dates in format of 'mm/dd/yyyy' or 'mm-dd-yyyy'
68
- const dateRegex = /(\d{1,2}[-/]\d{1,2}[-/]\d{4})/g;
69
- let matches;
70
- let currentDate = new Date();
71
-
72
- while ((matches = dateRegex.exec(text)) !== null) {
73
- let date = new Date(matches[0]);
74
- let timeElapsed =
75
- (currentDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);
76
- text = text.replace(
77
- matches[0],
78
- Math.floor(timeElapsed).toString() + ' days ago.'
79
- );
80
- }
81
- return text;
82
- }
83
-
84
- camelToString(camelCase: string): string {
85
- return camelCase.replace(/([A-Z])/g, ' $1').replace(/^./, function (str) {
86
- return str.toUpperCase();
87
- });
88
- }
89
-
90
- stringToBoolean(str: string): boolean {
91
- log.info(`Converting string to boolean: ${str}`);
92
- const positiveKeywords = [
93
- 'true',
94
- 'contains',
95
- 'confirms',
96
- 'yes',
97
- 'affirmative',
98
- 'matches',
99
- 'exists',
100
- 'present',
101
- 'absolutely',
102
- 'certainly',
103
- 'definitely',
104
- 'indeed',
105
- ];
106
- const lowerStr = str.toLowerCase();
107
- return positiveKeywords.some((keyword) => lowerStr.includes(keyword));
108
- }
109
-
110
- async textSplitter(
111
- text: string,
112
- chunkSize: number = 3900,
113
- chunkOverlap: number = 0
114
- ): Promise<string[]> {
115
- const textSplitter = new CharacterTextSplitter({
116
- chunkSize: chunkSize,
117
- chunkOverlap: chunkOverlap,
118
- });
119
- const texts = await textSplitter.splitText(text);
120
- // Log the number of chunks created
121
- if (texts.length === 0) {
122
- log.warn('No text chunks created. Please check the input text.');
123
- return [];
124
- }
125
- if (texts.length > 100) {
126
- log.warn(
127
- `Warning: More than 100 text chunks created (${texts.length}). This may affect performance.`
128
- );
129
- }
130
- if (chunkSize < 1000) {
131
- log.warn(
132
- `Warning: Chunk size is less than 1000 characters (${chunkSize}). This may lead to very small chunks.`
133
- );
134
- }
135
- log.info(
136
- `Text split into ${texts.length} chunks with size ${chunkSize} and overlap ${chunkOverlap}`
137
- );
138
- return texts;
139
- }
140
-
141
- printValues(obj: any) {
142
- for (var key in obj) {
143
- if (typeof obj[key] === 'object') {
144
- this.printValues(obj[key]);
145
- } else {
146
- this.string_expression += obj[key] + ' ';
147
- }
148
- }
149
- const _eliminate = [
150
- 'true',
151
- 'false',
152
- 'null',
153
- 'undefined',
154
- 'String',
155
- 'Number',
156
- 'Object',
157
- 'Array',
158
- 'Boolean',
159
- 'value',
160
- 'Type',
161
- 'Specifier',
162
- 'Named',
163
- ];
164
- _eliminate.forEach((element) => {
165
- const regex = new RegExp(element, 'g');
166
- this.string_expression = this.string_expression.replace(regex, '');
167
- });
168
- this.string_expression = this.string_expression.replace(
169
- /(?:https?|ftp):\/\/[\n\S]+/g,
170
- ''
171
- );
172
- return this.camelToString(this.string_expression);
173
- }
174
-
175
- async chain(input: any) {
176
- // Create a chain using RunnableSequence, RunnablePassthrough and RunnableParallel
177
- // input has two properties: expression and context
178
- // expression goes through mapQuery and parallely
179
- // context goes through textSplitter and mapDoc
180
- // Finally reduceChain is called with the results of mapQuery and mapDoc
181
- // LCEL-based implementation using RunnableSequence, RunnableParallel, and RunnablePassthrough
182
- const { RunnableSequence, RunnableParallel, RunnablePassthrough } =
183
- await import('@langchain/core/runnables');
184
-
185
- const mapQueryChain = RunnablePassthrough.assign({
186
- query: async (input: any) =>
187
- this.mapQuery.chain({
188
- input: { expression: input.input.expression },
189
- }),
190
- });
191
-
192
- const mapDocChain = RunnablePassthrough.assign({
193
- documents: async (input: any) => {
194
- const textChunks = await this.textSplitter(input.input.context);
195
- return Promise.all(
196
- textChunks.map((chunk) =>
197
- this.mapDoc.chain({
198
- input: { document: chunk, question: input.input.expression },
199
- })
200
- )
201
- );
202
- },
203
- });
204
-
205
- const parallelChain = RunnableParallel.from([mapQueryChain, mapDocChain]);
206
-
207
- const sequence = RunnableSequence.from([
208
- parallelChain,
209
- async (results: any) => {
210
- // results is an array: [{ query: ... }, { documents: [...] }]
211
- const query = results[0].query;
212
- const documents = results[1].documents;
213
- return this.reduceChain.chain({
214
- input: {
215
- query: query,
216
- facts: documents,
217
- },
218
- });
219
- },
220
- (result: any) => this.stringToBoolean(result),
221
- ]);
222
-
223
- return sequence.invoke(input);
224
- }
225
- }
@@ -1,4 +0,0 @@
1
- export { MapQuery } from './map_query';
2
- export { MapDoc } from './map_doc';
3
- export { ReduceChain } from './reduce';
4
- export { LLMLoop } from './base';
@@ -1,12 +0,0 @@
1
- import { BaseChain } from '../chain';
2
-
3
- export class MapDoc extends BaseChain {
4
- name: string = 'MapDoc';
5
- description: string = 'Map a set of documents to facts.';
6
- template: string = `
7
- You will be given a document and a question.\n
8
- Summarize the document chunk commenting on: {query} \n
9
- Do not include absent or negative mentions.\n
10
- document: {document} \n
11
- Summary:: `;
12
- }
@@ -1,36 +0,0 @@
1
- import { BaseChain } from '../chain';
2
-
3
- export class MapQuery extends BaseChain {
4
- name: string = 'MapQuery';
5
- description: string = 'Map a CQL query to a natural language.';
6
- template: string = `
7
- You are an assistant that can convert a CQL query to a natural language.
8
- You should give a single line answer>> as in the example below.
9
- Example:
10
-
11
- CQL: exists (
12
- [DocumentReference] D
13
- where D.allergies="Penicillin"
14
- and D.complaint="Headache"
15
- and D.complaint="Weakness" or D.complaint="Numbness"
16
- and D.findings="Intact sensation to light touch"
17
- )
18
-
19
- answer>> Penicillin allergy, Headache, Weakness, Numbness, and Intact sensation to light touch as findings?
20
-
21
- CQL: exists (
22
- [DocumentReference] D
23
- where D.diagnosis="Diverticulitis"
24
- and D.complaint="Fever"
25
- and D.procedure="Colon resection"
26
- and not D.finding="Fluid collection"
27
- )
28
-
29
- answer>> Diverticulitis diagnosis, Fever complaint, Colon resection procedure, and no Fluid collection finding?
30
-
31
- Now convert the following CQL query to a natural language.
32
- CQL: {expression}
33
-
34
- answer>>
35
- `;
36
- }
@@ -1,12 +0,0 @@
1
- import { BaseChain } from '../chain';
2
-
3
- export class ReduceChain extends BaseChain {
4
- name: string = 'Reduce';
5
- description: string = 'Reduce a set of documents to binary answer.';
6
- template: string = `
7
- You will be given facts and a question to answer with ONLY a yes or no.\n
8
- Do not include the facts in the answer.\n
9
- Say yes if the facts mentions all aspects of the question, else say no.\n
10
- facts: {facts} \n
11
- question: Does the facts mention {question} Say YES OR NO Only::`;
12
- }