@memberjunction/server 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/server",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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,18 +21,18 @@
21
21
  "dependencies": {
22
22
  "@apollo/server": "^4.9.1",
23
23
  "@graphql-tools/utils": "^10.0.1",
24
- "@memberjunction/ai": "^1.0.3",
25
- "@memberjunction/ai-openai": "^1.0.3",
26
- "@memberjunction/aiengine": "^1.0.3",
27
- "@memberjunction/core": "^1.0.3",
28
- "@memberjunction/core-entities": "^1.0.3",
29
- "@memberjunction/data-context": "^1.0.3",
30
- "@memberjunction/data-context-server": "^1.0.3",
31
- "@memberjunction/global": "^1.0.3",
32
- "@memberjunction/storage": "^1.0.3",
33
- "@memberjunction/queue": "^1.0.3",
34
- "@memberjunction/sqlserver-dataprovider": "^1.0.3",
35
- "@memberjunction/skip-types": "^1.0.3",
24
+ "@memberjunction/ai": "^1.0.4",
25
+ "@memberjunction/ai-openai": "^1.0.4",
26
+ "@memberjunction/aiengine": "^1.0.4",
27
+ "@memberjunction/core": "^1.0.4",
28
+ "@memberjunction/core-entities": "^1.0.4",
29
+ "@memberjunction/data-context": "^1.0.4",
30
+ "@memberjunction/data-context-server": "^1.0.4",
31
+ "@memberjunction/global": "^1.0.4",
32
+ "@memberjunction/storage": "^1.0.4",
33
+ "@memberjunction/queue": "^1.0.4",
34
+ "@memberjunction/sqlserver-dataprovider": "^1.0.4",
35
+ "@memberjunction/skip-types": "^1.0.4",
36
36
  "@types/cors": "^2.8.13",
37
37
  "@types/jsonwebtoken": "^8.5.9",
38
38
  "@types/node": "^18.11.14",
@@ -1,6 +1,6 @@
1
1
  import { CleanJSON, MJGlobal, RegisterClass } from "@memberjunction/global";
2
2
  import { BaseEntity, EntityInfo, LogError, Metadata } from "@memberjunction/core";
3
- import { AIModelEntity, UserViewEntityExtended } from '@memberjunction/core-entities'
3
+ import { AIModelEntity, AIModelEntityExtended, UserViewEntityExtended } from '@memberjunction/core-entities'
4
4
  import { BaseLLM, ChatParams, GetAIAPIKey } from "@memberjunction/ai";
5
5
  import { AIEngine } from "@memberjunction/aiengine";
6
6
  import { LoadOpenAILLM } from "@memberjunction/ai-openai";
@@ -16,21 +16,24 @@ export class UserViewEntity_Server extends UserViewEntityExtended {
16
16
  }
17
17
 
18
18
  /**
19
- * Default implementation simply returns 'gpt-4'. If you want to override this to use a different model you can override this method in your subclass and return the model you want to use.
19
+ * Default implementation simply returns 'OpenAI' - override this in your subclass if you are using a different AI vendor.
20
20
  * @returns
21
21
  */
22
- protected get AIModelName(): string {
23
- return 'gpt-4';
22
+ protected get AIVendorName(): string {
23
+ return 'OpenAI';
24
24
  }
25
25
 
26
26
  /**
27
27
  * Default implementation simply grabs the first AI model that matches GetAIModelName().
28
28
  * @returns
29
29
  */
30
- protected async GetAIModel(): Promise<AIModelEntity> {
30
+ protected async GetAIModel(): Promise<AIModelEntityExtended> {
31
31
  await AIEngine.LoadAIMetadata(this.ContextCurrentUser); // most of the time this is already loaded, but just in case it isn't we will load it here
32
- const model = AIEngine.Models.find(m => m.Name.trim().toLowerCase() === this.AIModelName.trim().toLowerCase())
33
- return model;
32
+ const models = AIEngine.Models.filter(m => m.AIModelType.trim().toLowerCase() === 'llm' &&
33
+ m.Vendor.trim().toLowerCase() === this.AIVendorName.trim().toLowerCase())
34
+ // next, sort the models by the PowerRank field so that the highest power rank model is the first array element
35
+ models.sort((a, b) => b.PowerRank - a.PowerRank); // highest power rank first
36
+ return models[0];
34
37
  }
35
38
 
36
39
  /**
@@ -44,7 +47,7 @@ export class UserViewEntity_Server extends UserViewEntityExtended {
44
47
  const llm = MJGlobal.Instance.ClassFactory.CreateInstance<BaseLLM>(BaseLLM, model.DriverClass, GetAIAPIKey(model.DriverClass));
45
48
 
46
49
  const chatParams: ChatParams = {
47
- model: this.AIModelName,
50
+ model: model.APINameOrName,
48
51
  messages: [
49
52
  {
50
53
  role: 'system',
@@ -65,7 +68,7 @@ export class UserViewEntity_Server extends UserViewEntityExtended {
65
68
  const cleansed = CleanJSON(llmResponse);
66
69
  if (!cleansed)
67
70
  throw new Error('Invalid JSON response from AI: ' + llmResponse);
68
-
71
+
69
72
  const parsed = JSON.parse(cleansed);
70
73
  if (parsed.whereClause && parsed.whereClause.length > 0) {
71
74
  // we have the where clause. Sometimes the LLM prefixes it with WHERE and somtimes not, we need to strip WHERE if it is there