@memberjunction/server 0.9.27 → 0.9.30
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.
|
@@ -37,13 +37,22 @@ let UserViewEntity_Server = class UserViewEntity_Server extends core_entities_1.
|
|
|
37
37
|
const parsed = JSON.parse(llmResponse);
|
|
38
38
|
if (parsed.whereClause && parsed.whereClause.length > 0) {
|
|
39
39
|
const trimmed = parsed.whereClause.trim();
|
|
40
|
+
let ret = '';
|
|
40
41
|
if (trimmed.toLowerCase().startsWith('where '))
|
|
41
|
-
|
|
42
|
+
ret = trimmed.substring(6);
|
|
42
43
|
else
|
|
43
|
-
|
|
44
|
+
ret = parsed.whereClause;
|
|
45
|
+
return {
|
|
46
|
+
whereClause: ret,
|
|
47
|
+
userExplanation: parsed.userExplanationMessage
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
else if (parsed.whereClause !== undefined && parsed.whereClause !== null) {
|
|
51
|
+
return {
|
|
52
|
+
whereClause: '',
|
|
53
|
+
userExplanation: parsed.userExplanationMessage
|
|
54
|
+
};
|
|
44
55
|
}
|
|
45
|
-
else if (parsed.whereClause !== undefined && parsed.whereClause !== null)
|
|
46
|
-
return '';
|
|
47
56
|
else {
|
|
48
57
|
throw new Error('Invalid response from AI, no whereClause property found in response: ' + llmResponse);
|
|
49
58
|
}
|
|
@@ -75,6 +84,7 @@ I am a bot and can only understand JSON. Your response must be parsable into thi
|
|
|
75
84
|
const returnType = {
|
|
76
85
|
whereClause: string,
|
|
77
86
|
orderByClause: string
|
|
87
|
+
userExplanationMessage: string
|
|
78
88
|
};
|
|
79
89
|
|
|
80
90
|
The view that the user is querying is called ${entityInfo.BaseView} and has these fields:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userViewEntity.server.js","sourceRoot":"","sources":["../../src/entitySubclasses/userViewEntity.server.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAAiE;AACjE,+CAAkF;AAClF,iE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AAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,aAAa,CAAC,CAAC;YAC5D,IAAI,CAAC,EAAE;gBACH,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE;oBAC3C,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;oBAChC,OAAO,KAAK,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;wBACzC,IAAI,GAAG,GAAW,GAAG,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,IAAI,GAAG,CAAC;wBAC5C,IAAI,EAAE,CAAC,aAAa,EAAE;4BAClB,GAAG,IAAI,aAAa,EAAE,CAAC,qBAAqB,GAAG,CAAC;yBACnD;wBACD,OAAO,GAAG,CAAC;oBACf,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAE,EAAE,CAAA;iBAClB;;oBAEG,OAAO,EAAE,CAAC;aACjB;;gBAEG,OAAO,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAChB,EAAE,CAAA;QAEM,OAAO,YAAY,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAgD,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG;sHACV,CAAC;IACnH,CAAC;CACJ,CAAA;AArJY,qBAAqB;IADjC,IAAA,sBAAa,EAAC,iBAAU,EAAE,YAAY,EAAE,CAAC,CAAC;GAC9B,qBAAqB,CAqJjC;AArJY,sDAAqB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/server",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.30",
|
|
4
4
|
"description": "MemberJunction: This project provides API access via GraphQL to the common data store.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@apollo/server": "^4.9.1",
|
|
23
23
|
"@graphql-tools/utils": "^10.0.1",
|
|
24
|
-
"@memberjunction/ai": "^0.9.
|
|
25
|
-
"@memberjunction/core": "^0.9.
|
|
26
|
-
"@memberjunction/core-entities": "^0.9.
|
|
27
|
-
"@memberjunction/global": "^0.9.
|
|
28
|
-
"@memberjunction/queue": "^0.9.
|
|
29
|
-
"@memberjunction/sqlserver-dataprovider": "^0.9.
|
|
24
|
+
"@memberjunction/ai": "^0.9.44",
|
|
25
|
+
"@memberjunction/core": "^0.9.47",
|
|
26
|
+
"@memberjunction/core-entities": "^0.9.20",
|
|
27
|
+
"@memberjunction/global": "^0.9.47",
|
|
28
|
+
"@memberjunction/queue": "^0.9.44",
|
|
29
|
+
"@memberjunction/sqlserver-dataprovider": "^0.9.44",
|
|
30
30
|
"@types/axios": "^0.14.0",
|
|
31
31
|
"@types/cors": "^2.8.13",
|
|
32
32
|
"@types/jsonwebtoken": "^8.5.9",
|
|
@@ -17,7 +17,7 @@ export class UserViewEntity_Server extends UserViewEntityExtended {
|
|
|
17
17
|
* to call this directly to get back a WHERE clause for other purposes you can call this method directly and provide both a prompt and the entity that the view is based on.
|
|
18
18
|
* @param prompt
|
|
19
19
|
*/
|
|
20
|
-
public async GenerateSmartFilterWhereClause(prompt: string, entityInfo: EntityInfo): Promise<string> {
|
|
20
|
+
public async GenerateSmartFilterWhereClause(prompt: string, entityInfo: EntityInfo): Promise<{whereClause: string, userExplanation: string}> {
|
|
21
21
|
try {
|
|
22
22
|
const llm = <IChat> new OpenAILLM(); // for now, hardcoded to use OpenAI
|
|
23
23
|
|
|
@@ -42,13 +42,23 @@ export class UserViewEntity_Server extends UserViewEntityExtended {
|
|
|
42
42
|
if (parsed.whereClause && parsed.whereClause.length > 0) {
|
|
43
43
|
// we have the where clause. Sometimes the LLM prefixes it with WHERE and somtimes not, we need to strip WHERE if it is there
|
|
44
44
|
const trimmed = parsed.whereClause.trim();
|
|
45
|
+
let ret: string = '';
|
|
45
46
|
if (trimmed.toLowerCase().startsWith('where '))
|
|
46
|
-
|
|
47
|
+
ret = trimmed.substring(6);
|
|
47
48
|
else
|
|
48
|
-
|
|
49
|
+
ret = parsed.whereClause;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
whereClause: ret,
|
|
53
|
+
userExplanation: parsed.userExplanationMessage
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (parsed.whereClause !== undefined && parsed.whereClause !== null) {
|
|
57
|
+
return {
|
|
58
|
+
whereClause: '', // empty string is valid, it means no where clause
|
|
59
|
+
userExplanation: parsed.userExplanationMessage
|
|
60
|
+
};
|
|
49
61
|
}
|
|
50
|
-
else if (parsed.whereClause !== undefined && parsed.whereClause !== null)
|
|
51
|
-
return ''; // empty string is valid, it means no where clause
|
|
52
62
|
else {
|
|
53
63
|
// if we get here, no whereClause property was provided by the LLM, that is an error
|
|
54
64
|
throw new Error('Invalid response from AI, no whereClause property found in response: ' + llmResponse);
|
|
@@ -82,6 +92,7 @@ I am a bot and can only understand JSON. Your response must be parsable into thi
|
|
|
82
92
|
const returnType = {
|
|
83
93
|
whereClause: string,
|
|
84
94
|
orderByClause: string
|
|
95
|
+
userExplanationMessage: string
|
|
85
96
|
};
|
|
86
97
|
|
|
87
98
|
The view that the user is querying is called ${entityInfo.BaseView} and has these fields:
|