@aj-archipelago/cortex 1.1.24 → 1.1.25
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/lib/cortexRequest.js +15 -2
- package/lib/requestExecutor.js +3 -3
- package/package.json +1 -1
- package/server/plugins/claude3VertexPlugin.js +1 -1
- package/server/plugins/gemini15ChatPlugin.js +1 -1
- package/server/plugins/geminiChatPlugin.js +1 -1
- package/server/plugins/palmChatPlugin.js +1 -1
- package/server/plugins/palmCompletionPlugin.js +1 -1
package/lib/cortexRequest.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { selectEndpoint } from './requestExecutor.js';
|
|
2
2
|
|
|
3
3
|
class CortexRequest {
|
|
4
|
-
constructor( { url, urlSuffix, data, params, headers, cache, model, pathwayResolver, selectedEndpoint, stream } = {}) {
|
|
4
|
+
constructor( { url, urlSuffix, data, params, headers, auth, cache, model, pathwayResolver, selectedEndpoint, stream } = {}) {
|
|
5
5
|
this._url = url || '';
|
|
6
6
|
this._urlSuffix = urlSuffix || '';
|
|
7
7
|
this._data = data || {};
|
|
8
8
|
this._params = params || {};
|
|
9
9
|
this._headers = headers || {};
|
|
10
|
+
this._auth = auth || {};
|
|
10
11
|
this._cache = cache || {};
|
|
11
12
|
this._model = model || '';
|
|
12
13
|
this._pathwayResolver = pathwayResolver || {};
|
|
@@ -30,6 +31,9 @@ class CortexRequest {
|
|
|
30
31
|
this._url = sep.url;
|
|
31
32
|
this._data = { ...this._data, ...sep.params };
|
|
32
33
|
this._headers = { ...this._headers, ...sep.headers };
|
|
34
|
+
if (sep.auth) {
|
|
35
|
+
this._auth = { ...sep.auth };
|
|
36
|
+
}
|
|
33
37
|
this._params = { ...this._params, ...sep.params };
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -81,13 +85,22 @@ class CortexRequest {
|
|
|
81
85
|
|
|
82
86
|
// headers getter and setter
|
|
83
87
|
get headers() {
|
|
84
|
-
return this._headers;
|
|
88
|
+
return { ...this._headers, ...this._auth };
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
set headers(value) {
|
|
88
92
|
this._headers = value;
|
|
89
93
|
}
|
|
90
94
|
|
|
95
|
+
// auth getter and setter
|
|
96
|
+
get auth() {
|
|
97
|
+
return this._auth;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
set auth(value) {
|
|
101
|
+
this._auth = value;
|
|
102
|
+
}
|
|
103
|
+
|
|
91
104
|
// cache getter and setter
|
|
92
105
|
get cache() {
|
|
93
106
|
return this._cache;
|
package/lib/requestExecutor.js
CHANGED
|
@@ -311,9 +311,9 @@ const makeRequest = async (cortexRequest) => {
|
|
|
311
311
|
throw new Error(`Received error response: ${response.status}`);
|
|
312
312
|
}
|
|
313
313
|
} catch (error) {
|
|
314
|
-
const { response, duration } = error;
|
|
315
|
-
if (response) {
|
|
316
|
-
const status = response
|
|
314
|
+
const { response, duration, code } = error;
|
|
315
|
+
if (response || code === 'ECONNRESET') {
|
|
316
|
+
const status = response?.status || 502; // default to 502 if ECONNRESET
|
|
317
317
|
// if there is only one endpoint, only retry select error codes
|
|
318
318
|
if (cortexRequest.model.endpoints.length === 1) {
|
|
319
319
|
if (status !== 429 &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aj-archipelago/cortex",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
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
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -263,7 +263,7 @@ class Claude3VertexPlugin extends OpenAIVisionPlugin {
|
|
|
263
263
|
|
|
264
264
|
const gcpAuthTokenHelper = this.config.get("gcpAuthTokenHelper");
|
|
265
265
|
const authToken = await gcpAuthTokenHelper.getAccessToken();
|
|
266
|
-
cortexRequest.
|
|
266
|
+
cortexRequest.auth.Authorization = `Bearer ${authToken}`;
|
|
267
267
|
|
|
268
268
|
return this.executeRequest(cortexRequest);
|
|
269
269
|
}
|
|
@@ -164,7 +164,7 @@ class Gemini15ChatPlugin extends ModelPlugin {
|
|
|
164
164
|
|
|
165
165
|
const gcpAuthTokenHelper = this.config.get('gcpAuthTokenHelper');
|
|
166
166
|
const authToken = await gcpAuthTokenHelper.getAccessToken();
|
|
167
|
-
cortexRequest.
|
|
167
|
+
cortexRequest.auth.Authorization = `Bearer ${authToken}`;
|
|
168
168
|
|
|
169
169
|
return this.executeRequest(cortexRequest);
|
|
170
170
|
}
|
|
@@ -159,7 +159,7 @@ class GeminiChatPlugin extends ModelPlugin {
|
|
|
159
159
|
|
|
160
160
|
const gcpAuthTokenHelper = this.config.get('gcpAuthTokenHelper');
|
|
161
161
|
const authToken = await gcpAuthTokenHelper.getAccessToken();
|
|
162
|
-
cortexRequest.
|
|
162
|
+
cortexRequest.auth.Authorization = `Bearer ${authToken}`;
|
|
163
163
|
|
|
164
164
|
return this.executeRequest(cortexRequest);
|
|
165
165
|
}
|
|
@@ -147,7 +147,7 @@ class PalmChatPlugin extends ModelPlugin {
|
|
|
147
147
|
|
|
148
148
|
const gcpAuthTokenHelper = this.config.get('gcpAuthTokenHelper');
|
|
149
149
|
const authToken = await gcpAuthTokenHelper.getAccessToken();
|
|
150
|
-
cortexRequest.
|
|
150
|
+
cortexRequest.auth.Authorization = `Bearer ${authToken}`;
|
|
151
151
|
|
|
152
152
|
return this.executeRequest(cortexRequest);
|
|
153
153
|
}
|
|
@@ -61,7 +61,7 @@ class PalmCompletionPlugin extends ModelPlugin {
|
|
|
61
61
|
|
|
62
62
|
const gcpAuthTokenHelper = this.config.get('gcpAuthTokenHelper');
|
|
63
63
|
const authToken = await gcpAuthTokenHelper.getAccessToken();
|
|
64
|
-
cortexRequest.
|
|
64
|
+
cortexRequest.auth.Authorization = `Bearer ${authToken}`;
|
|
65
65
|
|
|
66
66
|
return this.executeRequest(cortexRequest);
|
|
67
67
|
}
|