medpromptjs 0.2.2 → 0.3.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,36 @@
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
+ }
@@ -0,0 +1,12 @@
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
+ }
package/src/mydi.ts CHANGED
@@ -14,12 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- const mydi = (c:any, m:string, b:string) => {
18
- try {
19
- return c.resolve(m+"_"+b);
20
- } catch (e) {
21
- return c.resolve(b);
22
- }
23
- }
17
+ const mydi = (c: any, m: string, b: string) => {
18
+ try {
19
+ return c.resolve(m + '_' + b);
20
+ } catch (e) {
21
+ return c.resolve(b);
22
+ }
23
+ };
24
24
 
25
- export default mydi;
25
+ export default mydi;
package/src/tool.ts CHANGED
@@ -14,46 +14,55 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { DynamicStructuredTool } from "langchain/tools";
18
- import mydi from "./mydi";
17
+ import { DynamicStructuredTool } from 'langchain/tools';
18
+ import mydi from './mydi';
19
19
 
20
20
  export class BaseTool extends DynamicStructuredTool {
21
+ container: any;
22
+ name: string;
23
+ description: string;
24
+ schema: any;
25
+ constructor(
26
+ container: any,
27
+ name: string,
28
+ description: string,
29
+ schema: any,
30
+ func: any = null
31
+ ) {
32
+ super({
33
+ name: name,
34
+ description: description,
35
+ schema: schema,
36
+ func: func,
37
+ });
38
+ this.container = container;
39
+ this.name = name === '' ? this.camelize(this.constructor.name) : name;
40
+ this.description =
41
+ description === '' ? this.snake_case(this.constructor.name) : description;
42
+ this.schema = schema;
43
+ }
21
44
 
22
- container: any;
23
- name: string;
24
- description: string;
25
- schema: any;
26
- constructor(container: any, name: string, description: string, schema: any, func: any = null) {
27
- super({
28
- name: name,
29
- description: description,
30
- schema: schema,
31
- func: func
32
- });
33
- this.container = container;
34
- this.name = name === "" ? this.camelize(this.constructor.name) : name;
35
- this.description = description === "" ? this.snake_case(this.constructor.name) : description;
36
- this.schema = schema;
37
- }
45
+ func = async (args: any) => {
46
+ return 'override this';
47
+ };
38
48
 
39
- func = async (args: any) => {
40
- return "override this";
41
- }
49
+ resolve(name: string) {
50
+ return mydi(this.container, this.name, name);
51
+ }
42
52
 
43
- resolve(name: string) {
44
- return mydi(this.container, this.name, name);
45
- }
53
+ camelize(str: string) {
54
+ return str
55
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
56
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
57
+ })
58
+ .replace(/\s+/g, '');
59
+ }
46
60
 
47
- camelize(str: string) {
48
- return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
49
- return index === 0 ? word.toLowerCase() : word.toUpperCase();
50
- }).replace(/\s+/g, '');
51
- }
52
-
53
- snake_case(str: string) {
54
- return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
55
- return index === 0 ? word.toLowerCase() : "_" + word.toLowerCase();
56
- }).replace(/\s+/g, '');
57
- }
58
-
59
- }
61
+ snake_case(str: string) {
62
+ return str
63
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
64
+ return index === 0 ? word.toLowerCase() : '_' + word.toLowerCase();
65
+ })
66
+ .replace(/\s+/g, '');
67
+ }
68
+ }