@aj-archipelago/cortex 1.0.3 → 1.0.5

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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/config/default.example.json +18 -0
  3. package/config.js +25 -5
  4. package/graphql/pathwayPrompter.js +8 -0
  5. package/graphql/pathwayResolver.js +9 -1
  6. package/graphql/plugins/azureTranslatePlugin.js +22 -0
  7. package/graphql/plugins/modelPlugin.js +15 -42
  8. package/graphql/plugins/openAiChatPlugin.js +85 -2
  9. package/graphql/plugins/openAiCompletionPlugin.js +32 -2
  10. package/graphql/plugins/openAiWhisperPlugin.js +49 -13
  11. package/graphql/plugins/palmChatPlugin.js +229 -0
  12. package/graphql/plugins/palmCompletionPlugin.js +134 -0
  13. package/graphql/prompt.js +11 -4
  14. package/helper_apps/MediaFileChunker/Dockerfile +20 -0
  15. package/helper_apps/MediaFileChunker/fileChunker.js +50 -6
  16. package/helper_apps/MediaFileChunker/helper.js +13 -1
  17. package/helper_apps/MediaFileChunker/index.js +2 -4
  18. package/helper_apps/MediaFileChunker/package-lock.json +73 -18
  19. package/helper_apps/MediaFileChunker/package.json +2 -1
  20. package/lib/gcpAuthTokenHelper.js +37 -0
  21. package/package.json +3 -1
  22. package/pathways/completions.js +17 -0
  23. package/pathways/index.js +4 -2
  24. package/pathways/{lc_test.mjs → test_langchain.mjs} +1 -1
  25. package/pathways/test_oai_chat.js +18 -0
  26. package/pathways/test_oai_cmpl.js +13 -0
  27. package/pathways/test_palm_chat.js +31 -0
  28. package/pathways/transcribe.js +1 -0
  29. package/pathways/translate.js +2 -1
  30. package/tests/chunking.test.js +8 -6
  31. package/tests/modelPlugin.test.js +2 -14
  32. package/tests/openAiChatPlugin.test.js +125 -0
  33. package/tests/palmChatPlugin.test.js +256 -0
  34. package/tests/palmCompletionPlugin.test.js +87 -0
@@ -11,13 +11,14 @@
11
11
  "@azure/storage-blob": "^12.13.0",
12
12
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
13
13
  "@ffprobe-installer/ffprobe": "^2.0.0",
14
+ "axios": "^1.3.6",
14
15
  "busboy": "^1.6.0",
15
16
  "express": "^4.18.2",
16
17
  "fluent-ffmpeg": "^2.1.2",
17
18
  "ioredis": "^5.3.1",
18
19
  "public-ip": "^6.0.1",
19
20
  "uuid": "^9.0.0",
20
- "ytdl-core": "git+ssh://git@github.com:khlevon/node-ytdl-core.git#v4.11.3-patch.1"
21
+ "ytdl-core": "github:khlevon/node-ytdl-core#v4.11.4-patch.2"
21
22
  }
22
23
  },
23
24
  "node_modules/@azure/abort-controller": {
@@ -44,9 +45,9 @@
44
45
  }
45
46
  },
46
47
  "node_modules/@azure/core-http": {
47
- "version": "3.0.0",
48
- "resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-3.0.0.tgz",
49
- "integrity": "sha512-BxI2SlGFPPz6J1XyZNIVUf0QZLBKFX+ViFjKOkzqD18J1zOINIQ8JSBKKr+i+v8+MB6LacL6Nn/sP/TE13+s2Q==",
48
+ "version": "3.0.1",
49
+ "resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-3.0.1.tgz",
50
+ "integrity": "sha512-A3x+um3cAPgQe42Lu7Iv/x8/fNjhL/nIoEfqFxfn30EyxK6zC13n+OUxzZBRC0IzQqssqIbt4INf5YG7lYYFtw==",
50
51
  "dependencies": {
51
52
  "@azure/abort-controller": "^1.0.0",
52
53
  "@azure/core-auth": "^1.3.0",
@@ -61,7 +62,7 @@
61
62
  "tslib": "^2.2.0",
62
63
  "tunnel": "^0.0.6",
63
64
  "uuid": "^8.3.0",
64
- "xml2js": "^0.4.19"
65
+ "xml2js": "^0.5.0"
65
66
  },
66
67
  "engines": {
67
68
  "node": ">=14.0.0"
@@ -511,6 +512,16 @@
511
512
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
512
513
  "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
513
514
  },
515
+ "node_modules/axios": {
516
+ "version": "1.3.6",
517
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.6.tgz",
518
+ "integrity": "sha512-PEcdkk7JcdPiMDkvM4K6ZBRYq9keuVJsToxm2zQIM70Qqo2WHTdJZMXcG9X+RmRp2VPNUQC8W1RAGbgt6b1yMg==",
519
+ "dependencies": {
520
+ "follow-redirects": "^1.15.0",
521
+ "form-data": "^4.0.0",
522
+ "proxy-from-env": "^1.1.0"
523
+ }
524
+ },
514
525
  "node_modules/body-parser": {
515
526
  "version": "1.20.1",
516
527
  "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
@@ -913,6 +924,25 @@
913
924
  "node": ">=0.8.0"
914
925
  }
915
926
  },
927
+ "node_modules/follow-redirects": {
928
+ "version": "1.15.2",
929
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
930
+ "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
931
+ "funding": [
932
+ {
933
+ "type": "individual",
934
+ "url": "https://github.com/sponsors/RubenVerborgh"
935
+ }
936
+ ],
937
+ "engines": {
938
+ "node": ">=4.0"
939
+ },
940
+ "peerDependenciesMeta": {
941
+ "debug": {
942
+ "optional": true
943
+ }
944
+ }
945
+ },
916
946
  "node_modules/form-data": {
917
947
  "version": "4.0.0",
918
948
  "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@@ -1364,6 +1394,11 @@
1364
1394
  "node": ">= 0.10"
1365
1395
  }
1366
1396
  },
1397
+ "node_modules/proxy-from-env": {
1398
+ "version": "1.1.0",
1399
+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
1400
+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
1401
+ },
1367
1402
  "node_modules/public-ip": {
1368
1403
  "version": "6.0.1",
1369
1404
  "resolved": "https://registry.npmjs.org/public-ip/-/public-ip-6.0.1.tgz",
@@ -1685,9 +1720,9 @@
1685
1720
  }
1686
1721
  },
1687
1722
  "node_modules/xml2js": {
1688
- "version": "0.4.23",
1689
- "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
1690
- "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
1723
+ "version": "0.5.0",
1724
+ "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz",
1725
+ "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==",
1691
1726
  "dependencies": {
1692
1727
  "sax": ">=0.6.0",
1693
1728
  "xmlbuilder": "~11.0.0"
@@ -1706,7 +1741,7 @@
1706
1741
  },
1707
1742
  "node_modules/ytdl-core": {
1708
1743
  "version": "0.0.0-development",
1709
- "resolved": "git+ssh://git@github.com/khlevon/node-ytdl-core.git#586971bd9aeda1cbb4600851cfef82a809833ac2",
1744
+ "resolved": "git+ssh://git@github.com/khlevon/node-ytdl-core.git#87450450caabb91f81afa6e66758bf2f629664a1",
1710
1745
  "license": "MIT",
1711
1746
  "dependencies": {
1712
1747
  "m3u8stream": "^0.8.6",
@@ -1737,9 +1772,9 @@
1737
1772
  }
1738
1773
  },
1739
1774
  "@azure/core-http": {
1740
- "version": "3.0.0",
1741
- "resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-3.0.0.tgz",
1742
- "integrity": "sha512-BxI2SlGFPPz6J1XyZNIVUf0QZLBKFX+ViFjKOkzqD18J1zOINIQ8JSBKKr+i+v8+MB6LacL6Nn/sP/TE13+s2Q==",
1775
+ "version": "3.0.1",
1776
+ "resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-3.0.1.tgz",
1777
+ "integrity": "sha512-A3x+um3cAPgQe42Lu7Iv/x8/fNjhL/nIoEfqFxfn30EyxK6zC13n+OUxzZBRC0IzQqssqIbt4INf5YG7lYYFtw==",
1743
1778
  "requires": {
1744
1779
  "@azure/abort-controller": "^1.0.0",
1745
1780
  "@azure/core-auth": "^1.3.0",
@@ -1754,7 +1789,7 @@
1754
1789
  "tslib": "^2.2.0",
1755
1790
  "tunnel": "^0.0.6",
1756
1791
  "uuid": "^8.3.0",
1757
- "xml2js": "^0.4.19"
1792
+ "xml2js": "^0.5.0"
1758
1793
  },
1759
1794
  "dependencies": {
1760
1795
  "uuid": {
@@ -2049,6 +2084,16 @@
2049
2084
  "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
2050
2085
  "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
2051
2086
  },
2087
+ "axios": {
2088
+ "version": "1.3.6",
2089
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.6.tgz",
2090
+ "integrity": "sha512-PEcdkk7JcdPiMDkvM4K6ZBRYq9keuVJsToxm2zQIM70Qqo2WHTdJZMXcG9X+RmRp2VPNUQC8W1RAGbgt6b1yMg==",
2091
+ "requires": {
2092
+ "follow-redirects": "^1.15.0",
2093
+ "form-data": "^4.0.0",
2094
+ "proxy-from-env": "^1.1.0"
2095
+ }
2096
+ },
2052
2097
  "body-parser": {
2053
2098
  "version": "1.20.1",
2054
2099
  "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
@@ -2353,6 +2398,11 @@
2353
2398
  "which": "^1.1.1"
2354
2399
  }
2355
2400
  },
2401
+ "follow-redirects": {
2402
+ "version": "1.15.2",
2403
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
2404
+ "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
2405
+ },
2356
2406
  "form-data": {
2357
2407
  "version": "4.0.0",
2358
2408
  "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@@ -2657,6 +2707,11 @@
2657
2707
  "ipaddr.js": "1.9.1"
2658
2708
  }
2659
2709
  },
2710
+ "proxy-from-env": {
2711
+ "version": "1.1.0",
2712
+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
2713
+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
2714
+ },
2660
2715
  "public-ip": {
2661
2716
  "version": "6.0.1",
2662
2717
  "resolved": "https://registry.npmjs.org/public-ip/-/public-ip-6.0.1.tgz",
@@ -2893,9 +2948,9 @@
2893
2948
  }
2894
2949
  },
2895
2950
  "xml2js": {
2896
- "version": "0.4.23",
2897
- "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
2898
- "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
2951
+ "version": "0.5.0",
2952
+ "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz",
2953
+ "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==",
2899
2954
  "requires": {
2900
2955
  "sax": ">=0.6.0",
2901
2956
  "xmlbuilder": "~11.0.0"
@@ -2907,8 +2962,8 @@
2907
2962
  "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
2908
2963
  },
2909
2964
  "ytdl-core": {
2910
- "version": "git+ssh://git@github.com/khlevon/node-ytdl-core.git#586971bd9aeda1cbb4600851cfef82a809833ac2",
2911
- "from": "ytdl-core@git+ssh://git@github.com:khlevon/node-ytdl-core.git#v4.11.3-patch.1",
2965
+ "version": "git+ssh://git@github.com/khlevon/node-ytdl-core.git#87450450caabb91f81afa6e66758bf2f629664a1",
2966
+ "from": "ytdl-core@github:khlevon/node-ytdl-core#v4.11.4-patch.2",
2912
2967
  "requires": {
2913
2968
  "m3u8stream": "^0.8.6",
2914
2969
  "miniget": "^4.2.2",
@@ -11,12 +11,13 @@
11
11
  "@azure/storage-blob": "^12.13.0",
12
12
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
13
13
  "@ffprobe-installer/ffprobe": "^2.0.0",
14
+ "axios": "^1.3.6",
14
15
  "busboy": "^1.6.0",
15
16
  "express": "^4.18.2",
16
17
  "fluent-ffmpeg": "^2.1.2",
17
18
  "ioredis": "^5.3.1",
18
19
  "public-ip": "^6.0.1",
19
20
  "uuid": "^9.0.0",
20
- "ytdl-core": "git+ssh://git@github.com:khlevon/node-ytdl-core.git#v4.11.3-patch.1"
21
+ "ytdl-core": "github:khlevon/node-ytdl-core#v4.11.4-patch.2"
21
22
  }
22
23
  }
@@ -0,0 +1,37 @@
1
+ import { GoogleAuth } from 'google-auth-library';
2
+
3
+ class GcpAuthTokenHelper {
4
+ constructor(config) {
5
+ const creds = config.gcpServiceAccountKey ? JSON.parse(config.gcpServiceAccountKey) : null;
6
+ if (!creds) {
7
+ throw new Error('GCP_SERVICE_ACCOUNT_KEY is missing or undefined');
8
+ }
9
+ this.authClient = new GoogleAuth({
10
+ credentials: creds,
11
+ scopes: ['https://www.googleapis.com/auth/cloud-platform'],
12
+ });
13
+ this.token = null;
14
+ this.expiry = null;
15
+ }
16
+
17
+ async getAccessToken() {
18
+ if (!this.token || !this.isTokenValid()) {
19
+ await this.refreshToken();
20
+ }
21
+ return this.token;
22
+ }
23
+
24
+ isTokenValid() {
25
+ // Check if token is still valid with a 5-minute buffer
26
+ return this.expiry && Date.now() < this.expiry.getTime() - 5 * 60 * 1000;
27
+ }
28
+
29
+ async refreshToken() {
30
+ const authClient = await this.authClient.getClient();
31
+ const accessTokenResponse = await authClient.getAccessToken();
32
+ this.token = accessTokenResponse.token;
33
+ this.expiry = new Date(accessTokenResponse.expirationTime);
34
+ }
35
+ }
36
+
37
+ export default GcpAuthTokenHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aj-archipelago/cortex",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -43,6 +43,7 @@
43
43
  "convict": "^6.2.3",
44
44
  "express": "^4.18.2",
45
45
  "form-data": "^4.0.0",
46
+ "google-auth-library": "^8.8.0",
46
47
  "gpt-3-encoder": "^1.1.4",
47
48
  "graphql": "^16.6.0",
48
49
  "graphql-subscriptions": "^2.0.0",
@@ -51,6 +52,7 @@
51
52
  "ioredis": "^5.3.1",
52
53
  "keyv": "^4.5.2",
53
54
  "langchain": "^0.0.47",
55
+ "subsrt": "^1.1.1",
54
56
  "uuid": "^9.0.0",
55
57
  "ws": "^8.12.0"
56
58
  },
@@ -0,0 +1,17 @@
1
+ //completions.js
2
+
3
+ import { Prompt } from '../graphql/prompt.js';
4
+
5
+ export default {
6
+ prompt:
7
+ [
8
+ new Prompt({ messages: [
9
+ "{{messages}}",
10
+ ]}),
11
+ ],
12
+ inputParameters: {
13
+ messages: [],
14
+ },
15
+ model: 'palm-chat',
16
+ useInputChunking: false,
17
+ }
package/pathways/index.js CHANGED
@@ -3,10 +3,11 @@ import chat from './chat.js';
3
3
  import bias from './bias.js';
4
4
  import complete from './complete.js';
5
5
  import entities from './entities.js';
6
- import lc_test from './lc_test.mjs';
7
6
  import paraphrase from './paraphrase.js';
8
7
  import sentiment from './sentiment.js';
9
8
  import summary from './summary.js';
9
+ import test_langchain from './test_langchain.mjs';
10
+ import test_palm_chat from './test_palm_chat.js';
10
11
  import transcribe from './transcribe.js';
11
12
  import translate from './translate.js';
12
13
 
@@ -16,10 +17,11 @@ export {
16
17
  bias,
17
18
  complete,
18
19
  entities,
19
- lc_test,
20
20
  paraphrase,
21
21
  sentiment,
22
22
  summary,
23
+ test_langchain,
24
+ test_palm_chat,
23
25
  transcribe,
24
26
  translate
25
27
  };
@@ -1,4 +1,4 @@
1
- // lc_test.js
1
+ // test_langchain.mjs
2
2
  // LangChain Cortex integration test
3
3
 
4
4
  // Import required modules
@@ -0,0 +1,18 @@
1
+ //test_oai_chat.js
2
+
3
+ import { Prompt } from '../graphql/prompt.js';
4
+
5
+ // Description: Have a chat with a bot that uses context to understand the conversation
6
+ export default {
7
+ prompt:
8
+ [
9
+ new Prompt({ messages: [
10
+ "{{messages}}",
11
+ ]}),
12
+ ],
13
+ inputParameters: {
14
+ messages: [],
15
+ },
16
+ model: 'azure-td3',
17
+ useInputChunking: false,
18
+ }
@@ -0,0 +1,13 @@
1
+ //test_oai_cmpl.js
2
+
3
+ import { Prompt } from '../graphql/prompt.js';
4
+
5
+ // Description: Have a chat with a bot that uses context to understand the conversation
6
+ export default {
7
+ prompt: `{{prompt}}`,
8
+ inputParameters: {
9
+ prompt: '',
10
+ },
11
+ model: 'azure-td3',
12
+ useInputChunking: false,
13
+ }
@@ -0,0 +1,31 @@
1
+ //test_palm_chat.mjs
2
+ // Test for handling of prompts in the PaLM chat format for Cortex
3
+
4
+ import { Prompt } from '../graphql/prompt.js';
5
+
6
+ // Description: Have a chat with a bot that uses context to understand the conversation
7
+ export default {
8
+ prompt:
9
+ [
10
+ new Prompt({
11
+ context: "Instructions:\nYou an AI entity working a global media network. You are truthful, kind, and helpful. Your expertise includes journalism, journalistic ethics, researching and composing documents, and technology. You know the current date and time - it is {{now}}.",
12
+ examples: [
13
+ {
14
+ input: {"content": "What is your expertise?"},
15
+ output: {"content": "I am an expert in journalism and journalistic ethics."}
16
+ }],
17
+ messages: [
18
+ {"author": "user", "content": "Hi how are you today?"},
19
+ {"author": "assistant", "content": "I am doing well. How are you?"},
20
+ {"author": "user", "content": "I am doing well. What is your name?"},
21
+ {"author": "assistant", "content": "My name is Hula. What is your name?"},
22
+ {"author": "user", "content": "My name is Bob. What is your expertise?"},
23
+ ]}),
24
+ ],
25
+ inputParameters: {
26
+ chatHistory: [],
27
+ contextId: ``,
28
+ },
29
+ model: 'palm-chat',
30
+ useInputChunking: false,
31
+ }
@@ -4,6 +4,7 @@ export default {
4
4
  inputParameters: {
5
5
  file: ``,
6
6
  language: ``,
7
+ responseFormat: `text`,
7
8
  },
8
9
  timeout: 1800, // in seconds
9
10
  };
@@ -14,6 +14,7 @@ export default {
14
14
  },
15
15
 
16
16
  // Set the timeout for the translation process, in seconds.
17
- timeout: 300,
17
+ timeout: 400,
18
+ inputChunkSize: 500,
18
19
  };
19
20
 
@@ -13,10 +13,11 @@ test.after.always(async () => {
13
13
  });
14
14
 
15
15
  test('chunking test of translate endpoint with huge text', async t => {
16
- t.timeout(180000);
16
+ t.timeout(400000);
17
17
  const response = await testServer.executeOperation({
18
- query: 'query translate($text: String!) { translate(text: $text) { result } }',
18
+ query: 'query translate($text: String!, $to: String) { translate(text: $text, to: $to) { result } }',
19
19
  variables: {
20
+ to: 'en',
20
21
  text: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. In id erat sem. Phasellus ac dapibus purus, in fermentum nunc. Mauris quis rutrum magna. Quisque rutrum, augue vel blandit posuere, augue magna convallis turpis, nec elementum augue mauris sit amet nunc. Aenean sit amet leo est. Nunc ante ex, blandit et felis ut, iaculis lacinia est. Phasellus dictum orci id libero ullamcorper tempor.
21
22
 
22
23
  Vivamus id pharetra odio.Sed consectetur leo sed tortor dictum venenatis.Donec gravida libero non accumsan suscipit.Donec lectus turpis, ullamcorper eu pulvinar iaculis, ornare ut risus.Phasellus aliquam, turpis quis viverra condimentum, risus est pretium metus, in porta ipsum tortor vitae elit.Pellentesque id finibus erat.In suscipit, sapien non posuere dignissim, augue nisl ultrices tortor, sit amet eleifend nibh elit at risus.
@@ -63,7 +64,7 @@ Mauris diam dolor, maximus et ultrices sed, semper sed felis.Morbi ac eros tellu
63
64
  });
64
65
 
65
66
  test('chunking test of translate endpoint with single long text sentence', async t => {
66
- t.timeout(180000);
67
+ t.timeout(400000);
67
68
  const response = await testServer.executeOperation({
68
69
  query: 'query translate($text: String!) { translate(text: $text) { result } }',
69
70
  variables: {
@@ -76,7 +77,7 @@ test('chunking test of translate endpoint with single long text sentence', async
76
77
  });
77
78
 
78
79
  test('chunking test of translate endpoint with two long text sentence', async t => {
79
- t.timeout(180000);
80
+ t.timeout(400000);
80
81
  const response = await testServer.executeOperation({
81
82
  query: 'query translate($text: String!) { translate(text: $text) { result } }',
82
83
  variables: {
@@ -89,10 +90,11 @@ test('chunking test of translate endpoint with two long text sentence', async t
89
90
  });
90
91
 
91
92
  test('chunking test...', async t => {
92
- t.timeout(180000);
93
+ t.timeout(400000);
93
94
  const response = await testServer.executeOperation({
94
- query: 'query translate($text: String!) { translate(text: $text) { result } }',
95
+ query: 'query translate($text: String!, $to: String) { translate(text: $text, to: $to) { result } }',
95
96
  variables: {
97
+ to: 'en',
96
98
  text: `
97
99
  صعدت روسيا هجماتها في أنحاء أوكرانيا، بعد يوم من إعلان الغرب مدّ كييف بدبابات قتالية، واستهدفت عشرات الصواريخ والمسيّرات الروسية العاصمة الأوكرانية ومدنا في الجنوب والشرق، واعتبر الكرملين أن الدبابات لن تغيّر من طبيعة المعركة، في حين أعلنت وزارة الدفاع الأوكرانية أن هناك تحضيرات قتالية روسية انطلاقا من القرم.
98
100
 
@@ -79,19 +79,7 @@ test('requestUrl', (t) => {
79
79
  t.is(modelPlugin.requestUrl(), expectedUrl, 'requestUrl should return the correct URL');
80
80
  });
81
81
 
82
- test('parseResponse - single choice', (t) => {
83
- const { modelPlugin } = t.context;
84
- const singleChoiceResponse = {
85
- choices: [{
86
- text: '42'
87
- }]
88
- };
89
-
90
- const result = modelPlugin.parseResponse(singleChoiceResponse);
91
- t.is(result, '42', 'parseResponse should return the correct value for a single choice response');
92
- });
93
-
94
- test('parseResponse - multiple choices', (t) => {
82
+ test('default parseResponse', (t) => {
95
83
  const { modelPlugin } = t.context;
96
84
  const multipleChoicesResponse = {
97
85
  choices: [
@@ -101,7 +89,7 @@ test('parseResponse - multiple choices', (t) => {
101
89
  };
102
90
 
103
91
  const result = modelPlugin.parseResponse(multipleChoicesResponse);
104
- t.deepEqual(result, multipleChoicesResponse.choices, 'parseResponse should return the choices array for multiple choices response');
92
+ t.deepEqual(result, multipleChoicesResponse, 'default parseResponse should return the entire multiple choices response object');
105
93
  });
106
94
 
107
95
  test('truncateMessagesToTargetLength', (t) => {
@@ -0,0 +1,125 @@
1
+ import test from 'ava';
2
+ import OpenAIChatPlugin from '../graphql/plugins/openAiChatPlugin.js';
3
+ import { mockConfig, mockPathwayString, mockPathwayFunction, mockPathwayMessages } from './mocks.js';
4
+
5
+ // Test the constructor
6
+ test('constructor', (t) => {
7
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
8
+ t.is(plugin.config, mockConfig);
9
+ t.is(plugin.pathwayPrompt, mockPathwayString.prompt);
10
+ });
11
+
12
+ // Test the convertPalmToOpenAIMessages function
13
+ test('convertPalmToOpenAIMessages', (t) => {
14
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
15
+ const context = 'This is a test context.';
16
+ const examples = [
17
+ {
18
+ input: { author: 'user', content: 'Hello' },
19
+ output: { author: 'assistant', content: 'Hi there!' },
20
+ },
21
+ ];
22
+ const messages = [
23
+ { author: 'user', content: 'How are you?' },
24
+ { author: 'assistant', content: 'I am doing well, thank you!' },
25
+ ];
26
+ const result = plugin.convertPalmToOpenAIMessages(context, examples, messages);
27
+ t.deepEqual(result, [
28
+ { role: 'system', content: 'This is a test context.' },
29
+ { role: 'user', content: 'Hello' },
30
+ { role: 'assistant', content: 'Hi there!' },
31
+ { role: 'user', content: 'How are you?' },
32
+ { role: 'assistant', content: 'I am doing well, thank you!' },
33
+ ]);
34
+ });
35
+
36
+ // Test the getRequestParameters function
37
+ test('getRequestParameters', async (t) => {
38
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
39
+ const text = 'Help me';
40
+ const parameters = { name: 'John', age: 30 };
41
+ const prompt = mockPathwayString.prompt;
42
+ const result = await plugin.getRequestParameters(text, parameters, prompt);
43
+ t.deepEqual(result, {
44
+ messages: [
45
+ { role: 'user', content: 'User: Help me\nAssistant: Please help John who is 30 years old.' },
46
+ ],
47
+ temperature: 0.7,
48
+ });
49
+ });
50
+
51
+ // Test the execute function
52
+ test('execute', async (t) => {
53
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
54
+ const text = 'Help me';
55
+ const parameters = { name: 'John', age: 30 };
56
+ const prompt = mockPathwayString.prompt;
57
+
58
+ // Mock the executeRequest function
59
+ plugin.executeRequest = () => {
60
+ return {
61
+ choices: [
62
+ {
63
+ message: {
64
+ content: 'Sure, I can help John who is 30 years old.',
65
+ },
66
+ },
67
+ ],
68
+ };
69
+ };
70
+
71
+ const result = await plugin.execute(text, parameters, prompt);
72
+ t.deepEqual(result, {
73
+ choices: [
74
+ {
75
+ message: {
76
+ content: 'Sure, I can help John who is 30 years old.',
77
+ },
78
+ },
79
+ ],
80
+ });
81
+ });
82
+
83
+ // Test the parseResponse function
84
+ test('parseResponse', (t) => {
85
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
86
+ const data = {
87
+ choices: [
88
+ {
89
+ message: {
90
+ content: 'Sure, I can help John who is 30 years old.',
91
+ },
92
+ },
93
+ ],
94
+ };
95
+ const result = plugin.parseResponse(data);
96
+ t.is(result, 'Sure, I can help John who is 30 years old.');
97
+ });
98
+
99
+ // Test the logRequestData function
100
+ test('logRequestData', (t) => {
101
+ const plugin = new OpenAIChatPlugin(mockConfig, mockPathwayString);
102
+ const data = {
103
+ messages: [
104
+ { role: 'user', content: 'User: Help me\nAssistant: Please help John who is 30 years old.' },
105
+ ],
106
+ };
107
+ const responseData = {
108
+ choices: [
109
+ {
110
+ message: {
111
+ content: 'Sure, I can help John who is 30 years old.',
112
+ },
113
+ },
114
+ ],
115
+ };
116
+ const prompt = mockPathwayString.prompt;
117
+
118
+ // Mock console.log function
119
+ const originalConsoleLog = console.log;
120
+ console.log = () => {};
121
+
122
+ t.notThrows(() => plugin.logRequestData(data, responseData, prompt));
123
+
124
+ console.log = originalConsoleLog;
125
+ });