@aj-archipelago/cortex 1.1.1 → 1.1.2
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/.eslintignore +6 -0
- package/.eslintrc +3 -2
- package/lib/redisSubscription.js +2 -2
- package/package.json +1 -1
- package/pathways/sys_openai_completion.js +0 -2
- package/server/pathwayResolver.js +3 -3
- package/server/plugins/azureCognitivePlugin.js +1 -1
- package/server/plugins/azureTranslatePlugin.js +1 -0
- package/server/plugins/cohereGeneratePlugin.js +1 -1
- package/server/plugins/localModelPlugin.js +1 -0
- package/server/plugins/openAiCompletionPlugin.js +0 -1
- package/server/plugins/palmChatPlugin.js +0 -1
- package/server/plugins/palmCodeCompletionPlugin.js +0 -1
- package/server/plugins/palmCompletionPlugin.js +1 -1
- package/server/rest.js +11 -6
- package/server/subscriptions.js +0 -1
package/.eslintignore
CHANGED
package/.eslintrc
CHANGED
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"rules": {
|
|
18
18
|
"import/no-unresolved": "error",
|
|
19
|
-
"import/no-extraneous-dependencies": ["error", {"devDependencies": true
|
|
20
|
-
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
|
|
19
|
+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
20
|
+
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
21
|
+
"no-useless-escape": "off"
|
|
21
22
|
},
|
|
22
23
|
"settings": {
|
|
23
24
|
"import/resolver": {
|
package/lib/redisSubscription.js
CHANGED
|
@@ -95,8 +95,8 @@ if (connectionString) {
|
|
|
95
95
|
logger.info(`Using pubsub publish for channel ${requestProgressChannel}`);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
async function publishRequestProgress(data) {
|
|
99
|
-
if (publisherClient) {
|
|
98
|
+
async function publishRequestProgress(data, useRedis = true) {
|
|
99
|
+
if (publisherClient && useRedis) {
|
|
100
100
|
try {
|
|
101
101
|
let message = JSON.stringify(data);
|
|
102
102
|
if (redisEncryptionKey) {
|
package/package.json
CHANGED
|
@@ -70,7 +70,7 @@ class PathwayResolver {
|
|
|
70
70
|
// the graphql subscription to send progress updates to the client. Most of
|
|
71
71
|
// the time the client will be an external client, but it could also be the
|
|
72
72
|
// Cortex REST api code.
|
|
73
|
-
async asyncResolve(args) {
|
|
73
|
+
async asyncResolve(args, useRedis = true) {
|
|
74
74
|
const MAX_RETRY_COUNT = 3;
|
|
75
75
|
let attempt = 0;
|
|
76
76
|
let streamErrorOccurred = false;
|
|
@@ -88,7 +88,7 @@ class PathwayResolver {
|
|
|
88
88
|
requestId: this.requestId,
|
|
89
89
|
progress: completedCount / totalCount,
|
|
90
90
|
data: JSON.stringify(responseData),
|
|
91
|
-
});
|
|
91
|
+
}, useRedis);
|
|
92
92
|
}
|
|
93
93
|
} else {
|
|
94
94
|
try {
|
|
@@ -140,7 +140,7 @@ class PathwayResolver {
|
|
|
140
140
|
|
|
141
141
|
try {
|
|
142
142
|
//logger.info(`Publishing stream message to requestId ${this.requestId}: ${message}`);
|
|
143
|
-
publishRequestProgress(requestProgress);
|
|
143
|
+
publishRequestProgress(requestProgress, useRedis);
|
|
144
144
|
} catch (error) {
|
|
145
145
|
logger.error(`Could not publish the stream message: "${messageBuffer}", ${error}`);
|
|
146
146
|
}
|
|
@@ -30,7 +30,7 @@ class AzureCognitivePlugin extends ModelPlugin {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Set up parameters specific to the Azure Cognitive API
|
|
33
|
-
async getRequestParameters(text, parameters, prompt, mode, indexName, savedContextId, {headers, requestId, pathway,
|
|
33
|
+
async getRequestParameters(text, parameters, prompt, mode, indexName, savedContextId, {headers, requestId, pathway, _url}) {
|
|
34
34
|
const combinedParameters = { ...this.promptParameters, ...parameters };
|
|
35
35
|
const { modelPromptText } = this.getCompiledPrompt(text, combinedParameters, prompt);
|
|
36
36
|
const { inputVector, calculateInputVector, privateData, filter, docId } = combinedParameters;
|
|
@@ -8,7 +8,7 @@ class CohereGeneratePlugin extends ModelPlugin {
|
|
|
8
8
|
|
|
9
9
|
// Set up parameters specific to the Cohere API
|
|
10
10
|
getRequestParameters(text, parameters, prompt) {
|
|
11
|
-
|
|
11
|
+
let { modelPromptText, tokenLength } = this.getCompiledPrompt(text, parameters, prompt);
|
|
12
12
|
|
|
13
13
|
// Define the model's max token length
|
|
14
14
|
const modelTargetTokenLength = this.getModelMaxTokenLength() * this.getPromptTokenRatio();
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import ModelPlugin from './modelPlugin.js';
|
|
3
3
|
import { execFileSync } from 'child_process';
|
|
4
4
|
import { encode } from 'gpt-3-encoder';
|
|
5
|
+
import logger from '../../lib/logger.js';
|
|
5
6
|
|
|
6
7
|
class LocalModelPlugin extends ModelPlugin {
|
|
7
8
|
constructor(config, pathway, modelName, model) {
|
|
@@ -75,7 +75,6 @@ class PalmChatPlugin extends ModelPlugin {
|
|
|
75
75
|
// Set up parameters specific to the PaLM Chat API
|
|
76
76
|
getRequestParameters(text, parameters, prompt) {
|
|
77
77
|
const { modelPromptText, modelPromptMessages, tokenLength } = this.getCompiledPrompt(text, parameters, prompt);
|
|
78
|
-
const { stream } = parameters;
|
|
79
78
|
|
|
80
79
|
// Define the model's max token length
|
|
81
80
|
const modelTargetTokenLength = this.getModelMaxTokenLength() * this.getPromptTokenRatio();
|
|
@@ -11,7 +11,6 @@ class PalmCodeCompletionPlugin extends PalmCompletionPlugin {
|
|
|
11
11
|
// Set up parameters specific to the PaLM API Code Completion API
|
|
12
12
|
getRequestParameters(text, parameters, prompt, pathwayResolver) {
|
|
13
13
|
const { modelPromptText, tokenLength } = this.getCompiledPrompt(text, parameters, prompt);
|
|
14
|
-
const { stream } = parameters;
|
|
15
14
|
// Define the model's max token length
|
|
16
15
|
const modelTargetTokenLength = this.getModelMaxTokenLength() * this.getPromptTokenRatio();
|
|
17
16
|
|
|
@@ -22,7 +22,7 @@ class PalmCompletionPlugin extends ModelPlugin {
|
|
|
22
22
|
// Set up parameters specific to the PaLM API Text Completion API
|
|
23
23
|
getRequestParameters(text, parameters, prompt, pathwayResolver) {
|
|
24
24
|
const { modelPromptText, tokenLength } = this.getCompiledPrompt(text, parameters, prompt);
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
// Define the model's max token length
|
|
27
27
|
const modelTargetTokenLength = this.getModelMaxTokenLength() * this.getPromptTokenRatio();
|
|
28
28
|
|
package/server/rest.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// rest.js
|
|
2
2
|
// Implement the REST endpoints for the pathways
|
|
3
3
|
|
|
4
|
-
import { json } from 'express';
|
|
5
4
|
import pubsub from './pubsub.js';
|
|
6
5
|
import { requestState } from './requestState.js';
|
|
7
6
|
import { v4 as uuidv4 } from 'uuid';
|
|
@@ -168,7 +167,11 @@ const processIncomingStream = (requestId, res, jsonResponse) => {
|
|
|
168
167
|
// Fire the resolver for the async requestProgress
|
|
169
168
|
logger.info(`Rest Endpoint starting async requestProgress, requestId: ${requestId}`);
|
|
170
169
|
const { resolver, args } = requestState[requestId];
|
|
171
|
-
|
|
170
|
+
// The false here means never use a Redis subscription channel
|
|
171
|
+
// to handle these streaming messages. This is because we are
|
|
172
|
+
// guaranteed in this case that the stream is going to the same
|
|
173
|
+
// client.
|
|
174
|
+
resolver(args, false);
|
|
172
175
|
|
|
173
176
|
return subscription;
|
|
174
177
|
|
|
@@ -236,17 +239,18 @@ function buildRestEndpoints(pathways, app, server, config) {
|
|
|
236
239
|
],
|
|
237
240
|
};
|
|
238
241
|
|
|
242
|
+
// eslint-disable-next-line no-extra-boolean-cast
|
|
239
243
|
if (Boolean(req.body.stream)) {
|
|
240
244
|
jsonResponse.id = `cmpl-${resultText}`;
|
|
241
245
|
jsonResponse.choices[0].finish_reason = null;
|
|
242
246
|
//jsonResponse.object = "text_completion.chunk";
|
|
243
247
|
|
|
244
|
-
|
|
248
|
+
processIncomingStream(resultText, res, jsonResponse);
|
|
245
249
|
} else {
|
|
246
250
|
const requestId = uuidv4();
|
|
247
251
|
jsonResponse.id = `cmpl-${requestId}`;
|
|
248
252
|
res.json(jsonResponse);
|
|
249
|
-
}
|
|
253
|
+
}
|
|
250
254
|
});
|
|
251
255
|
|
|
252
256
|
app.post('/v1/chat/completions', async (req, res) => {
|
|
@@ -281,6 +285,7 @@ function buildRestEndpoints(pathways, app, server, config) {
|
|
|
281
285
|
],
|
|
282
286
|
};
|
|
283
287
|
|
|
288
|
+
// eslint-disable-next-line no-extra-boolean-cast
|
|
284
289
|
if (Boolean(req.body.stream)) {
|
|
285
290
|
jsonResponse.id = `chatcmpl-${resultText}`;
|
|
286
291
|
jsonResponse.choices[0] = {
|
|
@@ -292,7 +297,7 @@ function buildRestEndpoints(pathways, app, server, config) {
|
|
|
292
297
|
}
|
|
293
298
|
jsonResponse.object = "chat.completion.chunk";
|
|
294
299
|
|
|
295
|
-
|
|
300
|
+
processIncomingStream(resultText, res, jsonResponse);
|
|
296
301
|
} else {
|
|
297
302
|
const requestId = uuidv4();
|
|
298
303
|
jsonResponse.id = `chatcmpl-${requestId}`;
|
|
@@ -330,6 +335,6 @@ function buildRestEndpoints(pathways, app, server, config) {
|
|
|
330
335
|
});
|
|
331
336
|
|
|
332
337
|
}
|
|
333
|
-
}
|
|
338
|
+
}
|
|
334
339
|
|
|
335
340
|
export { buildRestEndpoints };
|