@tstdl/base 0.93.148 → 0.93.149
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/prompts/steering.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { ObjectLiteral } from '../../types/types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
output: ObjectLiteral | null;
|
|
2
|
+
export type FewShotExample<Input = ObjectLiteral, Output = ObjectLiteral> = {
|
|
3
|
+
input: Input;
|
|
4
|
+
output: Output;
|
|
6
5
|
/** Whether this is a negative example (showing what NOT to do). */
|
|
7
6
|
isNegative?: boolean;
|
|
8
7
|
/** Optional reason explaining why this example is positive or negative. */
|
|
@@ -13,7 +12,11 @@ export type FewShotExample = {
|
|
|
13
12
|
* @param examples An array of input/output pairs.
|
|
14
13
|
* @returns A formatted few-shot prompt.
|
|
15
14
|
*/
|
|
16
|
-
export declare function fewShotPrompt(examples: FewShotExample[]):
|
|
15
|
+
export declare function fewShotPrompt<Input = ObjectLiteral, Output = ObjectLiteral>(examples: FewShotExample<Input, Output>[]): {
|
|
16
|
+
Examples: string;
|
|
17
|
+
} | {
|
|
18
|
+
Examples: import("./instructions-formatter.js").InstructionsList;
|
|
19
|
+
};
|
|
17
20
|
/**
|
|
18
21
|
* Creates a prompt addition to specify the output language.
|
|
19
22
|
* @param language The desired output language (e.g., 'English', 'German', 'en', 'de').
|
package/ai/prompts/steering.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { fromEntries } from '../../utils/object/object.js';
|
|
2
2
|
import { isDefined, isString } from '../../utils/type-guards.js';
|
|
3
3
|
import { formatInstructions, orderedList, unorderedList } from './instructions-formatter.js';
|
|
4
|
-
function formatExampleValue(value) {
|
|
5
|
-
if (isString(value)) {
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
return JSON.stringify(value);
|
|
9
|
-
}
|
|
10
4
|
/**
|
|
11
5
|
* Creates a prompt addition for few-shot learning.
|
|
12
6
|
* @param examples An array of input/output pairs.
|
|
@@ -14,7 +8,7 @@ function formatExampleValue(value) {
|
|
|
14
8
|
*/
|
|
15
9
|
export function fewShotPrompt(examples) {
|
|
16
10
|
if (examples.length === 0) {
|
|
17
|
-
return {};
|
|
11
|
+
return { Examples: 'No examples provided.' };
|
|
18
12
|
}
|
|
19
13
|
// biome-ignore-start lint/style/useNamingConvention: prompt
|
|
20
14
|
const entries = examples
|
|
@@ -54,3 +48,9 @@ ${formatInstructions({
|
|
|
54
48
|
})}
|
|
55
49
|
`.trim();
|
|
56
50
|
}
|
|
51
|
+
function formatExampleValue(value) {
|
|
52
|
+
if (isString(value)) {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
return JSON.stringify(value);
|
|
56
|
+
}
|
|
@@ -411,16 +411,14 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
411
411
|
const now = this.estimatedServerTimestampSeconds();
|
|
412
412
|
const forceRefresh = this.forceRefreshRequested();
|
|
413
413
|
const refreshBufferSeconds = calculateRefreshBufferSeconds(token);
|
|
414
|
-
|
|
415
|
-
const needsRefresh = forceRefresh || (now >= Math.floor(token.exp - refreshBufferSeconds));
|
|
414
|
+
const needsRefresh = forceRefresh || (now >= (token.exp - refreshBufferSeconds));
|
|
416
415
|
if (needsRefresh) {
|
|
417
416
|
const lockResult = await this.lock.tryUse(undefined, async () => {
|
|
418
417
|
const currentToken = this.token();
|
|
419
418
|
const currentNow = this.estimatedServerTimestampSeconds();
|
|
420
419
|
const currentRefreshBufferSeconds = isDefined(currentToken) ? calculateRefreshBufferSeconds(currentToken) : 0;
|
|
421
420
|
// Passive Sync: Check if another tab refreshed the token while we were waiting for the lock (or trying to get it)
|
|
422
|
-
|
|
423
|
-
const stillNeedsRefresh = isDefined(currentToken) && (this.forceRefreshRequested() || (currentNow >= Math.floor(currentToken.exp - currentRefreshBufferSeconds)));
|
|
421
|
+
const stillNeedsRefresh = isDefined(currentToken) && (this.forceRefreshRequested() || (currentNow >= (currentToken.exp - currentRefreshBufferSeconds)));
|
|
424
422
|
if (stillNeedsRefresh) {
|
|
425
423
|
await this.refresh();
|
|
426
424
|
}
|