@tstdl/base 0.92.83 → 0.92.85
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/ai/ai.service.js +31 -13
- package/orm/decorators.js +1 -0
- package/package.json +3 -3
- package/process-shutdown.js +0 -3
package/ai/ai.service.js
CHANGED
|
@@ -9,6 +9,7 @@ import { GoogleGenerativeAI } from '@google/generative-ai';
|
|
|
9
9
|
import { NotSupportedError } from '../errors/not-supported.error.js';
|
|
10
10
|
import { Singleton } from '../injector/decorators.js';
|
|
11
11
|
import { inject, injectArgument } from '../injector/inject.js';
|
|
12
|
+
import { getShutdownSignal } from '../process-shutdown.js';
|
|
12
13
|
import { DeferredPromise } from '../promise/deferred-promise.js';
|
|
13
14
|
import { LazyPromise } from '../promise/lazy-promise.js';
|
|
14
15
|
import { convertToOpenApiSchema } from '../schema/converters/openapi-converter.js';
|
|
@@ -17,7 +18,9 @@ import { toArray } from '../utils/array/array.js';
|
|
|
17
18
|
import { mapAsync } from '../utils/async-iterable-helpers/map.js';
|
|
18
19
|
import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
|
|
19
20
|
import { hasOwnProperty, objectEntries } from '../utils/object/object.js';
|
|
20
|
-
import {
|
|
21
|
+
import { cancelableTimeout } from '../utils/timing.js';
|
|
22
|
+
import { assertDefinedPass, assertNotNullPass, isDefined, isError, isNotNull, isUndefined } from '../utils/type-guards.js';
|
|
23
|
+
import { millisecondsPerSecond } from '../utils/units.js';
|
|
21
24
|
import { resolveValueOrAsyncProvider } from '../utils/value-or-provider.js';
|
|
22
25
|
import { AiFileService } from './ai-file.service.js';
|
|
23
26
|
import { AiSession } from './ai-session.js';
|
|
@@ -211,18 +214,33 @@ Always output the content and tags in ${options?.targetLanguage ?? 'the same lan
|
|
|
211
214
|
let totalOutputTokens = 0;
|
|
212
215
|
let totalTokens = 0;
|
|
213
216
|
while (totalOutputTokens < maxTotalOutputTokens) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
217
|
+
let generation;
|
|
218
|
+
for (let i = 0;; i++) {
|
|
219
|
+
try {
|
|
220
|
+
generation = await this.getModel(model).generateContentStream({
|
|
221
|
+
generationConfig: {
|
|
222
|
+
...generationConfig,
|
|
223
|
+
maxOutputTokens: Math.min(maxModelTokens, maxTotalOutputTokens - totalOutputTokens)
|
|
224
|
+
},
|
|
225
|
+
systemInstruction: request.systemInstruction,
|
|
226
|
+
tools: (isDefined(googleFunctionDeclarations) && (googleFunctionDeclarations.length > 0)) ? [{ functionDeclarations: googleFunctionDeclarations }] : undefined,
|
|
227
|
+
toolConfig: isDefined(request.functionCallingMode)
|
|
228
|
+
? { functionCallingConfig: { mode: functionCallingModeMap[request.functionCallingMode] } }
|
|
229
|
+
: undefined,
|
|
230
|
+
contents: inputContent
|
|
231
|
+
});
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if ((i < 20) && isError(error) && (error['status'] == 429)) {
|
|
236
|
+
const canceled = await cancelableTimeout(15 * millisecondsPerSecond, getShutdownSignal());
|
|
237
|
+
if (!canceled) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
226
244
|
iterations++;
|
|
227
245
|
let lastUsageMetadata;
|
|
228
246
|
let candidate;
|
package/orm/decorators.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.92.
|
|
3
|
+
"version": "0.92.85",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"type-fest": "4.35"
|
|
137
137
|
},
|
|
138
138
|
"devDependencies": {
|
|
139
|
-
"@stylistic/eslint-plugin": "4.
|
|
139
|
+
"@stylistic/eslint-plugin": "4.1",
|
|
140
140
|
"@types/chroma-js": "2.4",
|
|
141
141
|
"@types/koa__router": "12.0",
|
|
142
142
|
"@types/luxon": "3.4",
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"@zxcvbn-ts/language-de": "^3.0",
|
|
163
163
|
"@zxcvbn-ts/language-en": "^3.0",
|
|
164
164
|
"chroma-js": "^2.6",
|
|
165
|
-
"drizzle-orm": "^0.
|
|
165
|
+
"drizzle-orm": "^0.40",
|
|
166
166
|
"handlebars": "^4.7",
|
|
167
167
|
"minio": "^8.0",
|
|
168
168
|
"mjml": "^4.15",
|
package/process-shutdown.js
CHANGED
|
@@ -14,7 +14,6 @@ export function getShutdownSignal() {
|
|
|
14
14
|
return getShutdownToken().signal;
|
|
15
15
|
}
|
|
16
16
|
let logger;
|
|
17
|
-
// eslint-disable-next-line no-shadow
|
|
18
17
|
export function setProcessShutdownLogger(shutdownLogger) {
|
|
19
18
|
logger = shutdownLogger;
|
|
20
19
|
}
|
|
@@ -49,7 +48,6 @@ export function initializeSignals() {
|
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
for (const event of quitEvents) {
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
53
51
|
process.on(event, (...args) => {
|
|
54
52
|
console.error(event, ...args);
|
|
55
53
|
quitReason = args;
|
|
@@ -57,7 +55,6 @@ export function initializeSignals() {
|
|
|
57
55
|
});
|
|
58
56
|
}
|
|
59
57
|
for (const quitSignal of quitSignals) {
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
61
58
|
process.on(quitSignal, (signal) => {
|
|
62
59
|
logger.info(`${signal} received, quitting.`);
|
|
63
60
|
requestShutdown();
|