@aj-archipelago/cortex 1.0.20 → 1.0.21
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/helper_apps/HealthCheck/.funcignore +10 -0
- package/helper_apps/HealthCheck/host.json +15 -0
- package/helper_apps/HealthCheck/package-lock.json +142 -0
- package/helper_apps/HealthCheck/package.json +14 -0
- package/helper_apps/HealthCheck/src/functions/timerTrigger.js +13 -0
- package/helper_apps/HealthCheck/src/transcribeHealthCheck.js +93 -0
- package/package.json +1 -1
- package/pathways/cognitive_insert.js +2 -0
- package/server/plugins/azureCognitivePlugin.js +21 -18
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0",
|
|
3
|
+
"logging": {
|
|
4
|
+
"applicationInsights": {
|
|
5
|
+
"samplingSettings": {
|
|
6
|
+
"isEnabled": true,
|
|
7
|
+
"excludedTypes": "Request"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"extensionBundle": {
|
|
12
|
+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
|
13
|
+
"version": "[3.*, 4.0.0)"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "healthcheck",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "healthcheck",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@azure/functions": "^4.0.0",
|
|
12
|
+
"axios": "^1.6.0"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"node_modules/@azure/functions": {
|
|
16
|
+
"version": "4.0.1",
|
|
17
|
+
"resolved": "https://registry.npmjs.org/@azure/functions/-/functions-4.0.1.tgz",
|
|
18
|
+
"integrity": "sha512-Ol38b4XOlu6IDkLnO91HaYeo2utMixG0LIA1NR9Qehu17U/cGjNx+bAcOEdNlSJWNYh5ChhzjxA/uFB5dQJtmg==",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"long": "^4.0.0",
|
|
21
|
+
"undici": "^5.13.0"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.0"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"node_modules/@fastify/busboy": {
|
|
28
|
+
"version": "2.0.0",
|
|
29
|
+
"resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.0.0.tgz",
|
|
30
|
+
"integrity": "sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ==",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=14"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"node_modules/asynckit": {
|
|
36
|
+
"version": "0.4.0",
|
|
37
|
+
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
|
38
|
+
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
|
39
|
+
},
|
|
40
|
+
"node_modules/axios": {
|
|
41
|
+
"version": "1.6.0",
|
|
42
|
+
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.0.tgz",
|
|
43
|
+
"integrity": "sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"follow-redirects": "^1.15.0",
|
|
46
|
+
"form-data": "^4.0.0",
|
|
47
|
+
"proxy-from-env": "^1.1.0"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"node_modules/combined-stream": {
|
|
51
|
+
"version": "1.0.8",
|
|
52
|
+
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
|
53
|
+
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"delayed-stream": "~1.0.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">= 0.8"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"node_modules/delayed-stream": {
|
|
62
|
+
"version": "1.0.0",
|
|
63
|
+
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
|
64
|
+
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=0.4.0"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"node_modules/follow-redirects": {
|
|
70
|
+
"version": "1.15.3",
|
|
71
|
+
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
|
|
72
|
+
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
|
|
73
|
+
"funding": [
|
|
74
|
+
{
|
|
75
|
+
"type": "individual",
|
|
76
|
+
"url": "https://github.com/sponsors/RubenVerborgh"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=4.0"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"debug": {
|
|
84
|
+
"optional": true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"node_modules/form-data": {
|
|
89
|
+
"version": "4.0.0",
|
|
90
|
+
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
|
91
|
+
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"asynckit": "^0.4.0",
|
|
94
|
+
"combined-stream": "^1.0.8",
|
|
95
|
+
"mime-types": "^2.1.12"
|
|
96
|
+
},
|
|
97
|
+
"engines": {
|
|
98
|
+
"node": ">= 6"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"node_modules/long": {
|
|
102
|
+
"version": "4.0.0",
|
|
103
|
+
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
|
|
104
|
+
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
|
|
105
|
+
},
|
|
106
|
+
"node_modules/mime-db": {
|
|
107
|
+
"version": "1.52.0",
|
|
108
|
+
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
|
109
|
+
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">= 0.6"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"node_modules/mime-types": {
|
|
115
|
+
"version": "2.1.35",
|
|
116
|
+
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
|
117
|
+
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
|
118
|
+
"dependencies": {
|
|
119
|
+
"mime-db": "1.52.0"
|
|
120
|
+
},
|
|
121
|
+
"engines": {
|
|
122
|
+
"node": ">= 0.6"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"node_modules/proxy-from-env": {
|
|
126
|
+
"version": "1.1.0",
|
|
127
|
+
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
|
128
|
+
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
|
129
|
+
},
|
|
130
|
+
"node_modules/undici": {
|
|
131
|
+
"version": "5.27.0",
|
|
132
|
+
"resolved": "https://registry.npmjs.org/undici/-/undici-5.27.0.tgz",
|
|
133
|
+
"integrity": "sha512-l3ydWhlhOJzMVOYkymLykcRRXqbUaQriERtR70B9LzNkZ4bX52Fc8wbTDneMiwo8T+AemZXvXaTx+9o5ROxrXg==",
|
|
134
|
+
"dependencies": {
|
|
135
|
+
"@fastify/busboy": "^2.0.0"
|
|
136
|
+
},
|
|
137
|
+
"engines": {
|
|
138
|
+
"node": ">=14.0"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "healthcheck",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"start": "func start",
|
|
7
|
+
"test": "echo \"No tests yet...\""
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@azure/functions": "^4.0.0",
|
|
11
|
+
"axios": "^1.6.0"
|
|
12
|
+
},
|
|
13
|
+
"main": "src/functions/*.js"
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { app } = require('@azure/functions');
|
|
2
|
+
const { transcribeHealthCheck } = require('../transcribeHealthCheck');
|
|
3
|
+
|
|
4
|
+
app.timer('timerTrigger', {
|
|
5
|
+
schedule: '0 0 * * * *',
|
|
6
|
+
// schedule: '0 * * * * *',
|
|
7
|
+
runOnStartup: true,
|
|
8
|
+
handler: async (myTimer, context) => {
|
|
9
|
+
context.log('Timer function starting request.');
|
|
10
|
+
await transcribeHealthCheck(context, 0);
|
|
11
|
+
context.log('Timer function processed request.');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
const API_URL = process.env.API_URL;
|
|
4
|
+
const API_SUBSCRIPTION_KEY = process.env.API_SUBSCRIPTION_KEY;
|
|
5
|
+
|
|
6
|
+
async function transcribeHealthCheck(context, runCount) {
|
|
7
|
+
try {
|
|
8
|
+
const query = `
|
|
9
|
+
query Transcribe($file: String!, $text: String, $wordTimestamped: Boolean, $responseFormat: String, $async: Boolean) {
|
|
10
|
+
transcribe(
|
|
11
|
+
file: $file
|
|
12
|
+
text: $text
|
|
13
|
+
wordTimestamped: $wordTimestamped
|
|
14
|
+
responseFormat: $responseFormat
|
|
15
|
+
async: $async
|
|
16
|
+
) {
|
|
17
|
+
result
|
|
18
|
+
__typename
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const variables = {
|
|
24
|
+
"file": "https://www.youtube.com/watch?v=SCvWXEFb8jE",
|
|
25
|
+
"wordTimestamped": true,
|
|
26
|
+
"responseFormat": "srt",
|
|
27
|
+
"async": false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const response = await axios({
|
|
31
|
+
url: API_URL,
|
|
32
|
+
method: 'post',
|
|
33
|
+
data: {
|
|
34
|
+
query: query,
|
|
35
|
+
variables: variables
|
|
36
|
+
},
|
|
37
|
+
headers: {
|
|
38
|
+
'Ocp-Apim-Subscription-Key': API_SUBSCRIPTION_KEY
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
context.log(response.data);
|
|
43
|
+
|
|
44
|
+
const transcribeText = response.data.data.transcribe.result;
|
|
45
|
+
|
|
46
|
+
if (!validateTranscribeText(transcribeText)) {
|
|
47
|
+
throw new Error("Invalid transcribe text");
|
|
48
|
+
} else {
|
|
49
|
+
context.log("Transcribe text is valid");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} catch (error) {
|
|
53
|
+
context.error(error);
|
|
54
|
+
if(runCount < 1){
|
|
55
|
+
transcribeHealthCheck(context, runCount + 1);
|
|
56
|
+
}else{
|
|
57
|
+
throw new Error("Error in transcribeHealthCheck");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
//validate transcribeText similar to below str:
|
|
64
|
+
/*
|
|
65
|
+
'1
|
|
66
|
+
00:00:00,140 --> 00:00:00,640
|
|
67
|
+
You
|
|
68
|
+
|
|
69
|
+
2
|
|
70
|
+
00:00:00,640 --> 00:00:00,820
|
|
71
|
+
may
|
|
72
|
+
...cor
|
|
73
|
+
*/
|
|
74
|
+
// Validate transcribeText
|
|
75
|
+
const validateTranscribeText = (text) => {
|
|
76
|
+
let numberLineRegex = /^\d+$/m;
|
|
77
|
+
let timeFormatRegex = /^\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}$/m;
|
|
78
|
+
let wordLineRegex = /^\w+$/m;
|
|
79
|
+
|
|
80
|
+
let hasNumberLine = numberLineRegex.test(text);
|
|
81
|
+
let hasTimeFormatLine = timeFormatRegex.test(text);
|
|
82
|
+
let hasWordLine = wordLineRegex.test(text);
|
|
83
|
+
|
|
84
|
+
if(hasNumberLine && hasTimeFormatLine && hasWordLine){
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
module.exports = { transcribeHealthCheck };
|
package/package.json
CHANGED
|
@@ -17,11 +17,22 @@ class AzureCognitivePlugin extends ModelPlugin {
|
|
|
17
17
|
super(config, pathway, modelName, model);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
async getInputVector (text) {
|
|
21
|
+
try{
|
|
22
|
+
if(!text || !text.trim()){
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
return JSON.parse(await callPathway(this.config, 'embeddings', { text }))[0];
|
|
26
|
+
}catch(err){
|
|
27
|
+
console.log(`Error in calculating input vector for text: ${text}, error: ${err}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
20
31
|
// Set up parameters specific to the Azure Cognitive API
|
|
21
32
|
async getRequestParameters(text, parameters, prompt, mode, indexName, savedContextId, {headers, requestId, pathway, url}) {
|
|
22
33
|
const combinedParameters = { ...this.promptParameters, ...parameters };
|
|
23
34
|
const { modelPromptText } = this.getCompiledPrompt(text, combinedParameters, prompt);
|
|
24
|
-
const { inputVector, filter, docId } = combinedParameters;
|
|
35
|
+
const { inputVector, calculateInputVector, privateData, filter, docId } = combinedParameters;
|
|
25
36
|
const data = {};
|
|
26
37
|
|
|
27
38
|
if (mode == 'delete') {
|
|
@@ -54,30 +65,22 @@ class AzureCognitivePlugin extends ModelPlugin {
|
|
|
54
65
|
|
|
55
66
|
if (mode == 'index') {
|
|
56
67
|
|
|
57
|
-
/*
|
|
58
|
-
const calculateInputVector = async () => {
|
|
59
|
-
try{
|
|
60
|
-
if(!text || !text.trim()){
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
return JSON.parse(await callPathway(this.config, 'embeddings', { text }))[0];
|
|
64
|
-
}catch(err){
|
|
65
|
-
console.log(`Error in calculating input vector for text: ${text}, error: ${err}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
68
|
const doc = {
|
|
71
69
|
id: uuidv4(),
|
|
72
70
|
content: text,
|
|
73
|
-
//contentVector: inputVector || (await calculateInputVector()),
|
|
74
71
|
owner: savedContextId,
|
|
75
72
|
docId: docId || uuidv4(),
|
|
76
73
|
createdAt: new Date().toISOString()
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
|
|
75
|
+
|
|
76
|
+
if(inputVector || calculateInputVector){ //if input vector is provided or needs to be calculated
|
|
77
|
+
doc.contentVector = inputVector ? inputVector : await this.getInputVector(text);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if(!privateData){ //if public, remove owner
|
|
81
|
+
delete doc.owner;
|
|
82
|
+
}
|
|
83
|
+
|
|
81
84
|
data.value = [doc];
|
|
82
85
|
return { data };
|
|
83
86
|
}
|