modelfusion 0.53.0 → 0.53.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/core/FunctionOptions.d.ts +4 -3
- package/model-function/embed/embed.cjs +16 -0
- package/model-function/embed/embed.d.ts +16 -0
- package/model-function/embed/embed.js +16 -0
- package/model-function/executeStreamCall.cjs +72 -35
- package/model-function/executeStreamCall.js +72 -35
- package/model-function/generate-image/generateImage.cjs +12 -3
- package/model-function/generate-image/generateImage.d.ts +12 -3
- package/model-function/generate-image/generateImage.js +12 -3
- package/model-function/generate-speech/generateSpeech.cjs +16 -1
- package/model-function/generate-speech/generateSpeech.d.ts +16 -1
- package/model-function/generate-speech/generateSpeech.js +16 -1
- package/model-function/generate-speech/streamSpeech.cjs +22 -1
- package/model-function/generate-speech/streamSpeech.d.ts +22 -1
- package/model-function/generate-speech/streamSpeech.js +22 -1
- package/model-function/generate-structure/generateStructure.cjs +41 -0
- package/model-function/generate-structure/generateStructure.d.ts +41 -0
- package/model-function/generate-structure/generateStructure.js +41 -0
- package/model-function/generate-structure/generateStructureOrText.cjs +62 -0
- package/model-function/generate-structure/generateStructureOrText.d.ts +62 -0
- package/model-function/generate-structure/generateStructureOrText.js +62 -0
- package/model-function/generate-structure/streamStructure.cjs +72 -1
- package/model-function/generate-structure/streamStructure.d.ts +68 -1
- package/model-function/generate-structure/streamStructure.js +72 -1
- package/model-function/generate-text/generateText.cjs +14 -6
- package/model-function/generate-text/generateText.d.ts +14 -6
- package/model-function/generate-text/generateText.js +14 -6
- package/model-function/generate-text/streamText.cjs +25 -0
- package/model-function/generate-text/streamText.d.ts +25 -0
- package/model-function/generate-text/streamText.js +25 -0
- package/model-function/generate-transcription/generateTranscription.cjs +10 -5
- package/model-function/generate-transcription/generateTranscription.d.ts +10 -5
- package/model-function/generate-transcription/generateTranscription.js +10 -5
- package/model-function/tokenize-text/Tokenizer.d.ts +27 -3
- package/package.json +1 -1
- package/util/AsyncQueue.cjs +26 -11
- package/util/AsyncQueue.d.ts +2 -0
- package/util/AsyncQueue.js +26 -11
- package/util/AsyncQueue.test.cjs +1 -1
- package/util/AsyncQueue.test.js +1 -1
- package/util/delay.cjs +2 -2
- package/util/delay.d.ts +1 -1
- package/util/delay.js +2 -2
- package/util/index.cjs +1 -0
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
@@ -1,17 +1,25 @@
|
|
1
1
|
import { executeStandardCall } from "../executeStandardCall.js";
|
2
2
|
import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
3
3
|
/**
|
4
|
-
*
|
5
|
-
* The prompt format depends on the model.
|
6
|
-
* For example, OpenAI text models expect a string prompt, and OpenAI chat models expect an array of chat messages.
|
4
|
+
* Generate text for a prompt and return it as a string.
|
7
5
|
*
|
8
|
-
*
|
9
|
-
*
|
6
|
+
* The prompt depends on the model used.
|
7
|
+
* For instance, OpenAI completion models expect a string prompt,
|
8
|
+
* whereas OpenAI chat models expect an array of chat messages.
|
9
|
+
*
|
10
|
+
* @see https://modelfusion.dev/guide/function/generate-text
|
10
11
|
*
|
12
|
+
* @example
|
11
13
|
* const text = await generateText(
|
12
|
-
*
|
14
|
+
* new OpenAICompletionModel(...),
|
13
15
|
* "Write a short story about a robot learning to love:\n\n"
|
14
16
|
* );
|
17
|
+
*
|
18
|
+
* @param {TextGenerationModel<PROMPT, TextGenerationModelSettings>} model - The text generation model to use.
|
19
|
+
* @param {PROMPT} prompt - The prompt to use for text generation.
|
20
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
21
|
+
*
|
22
|
+
* @returns {ModelFunctionPromise<string>} - A promise that resolves to the generated text.
|
15
23
|
*/
|
16
24
|
export function generateText(model, prompt, options) {
|
17
25
|
return new ModelFunctionPromise(executeStandardCall({
|
@@ -3,6 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.streamText = void 0;
|
4
4
|
const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
|
5
5
|
const executeStreamCall_js_1 = require("../executeStreamCall.cjs");
|
6
|
+
/**
|
7
|
+
* Stream the generated text for a prompt as an async iterable.
|
8
|
+
*
|
9
|
+
* The prompt depends on the model used.
|
10
|
+
* For instance, OpenAI completion models expect a string prompt,
|
11
|
+
* whereas OpenAI chat models expect an array of chat messages.
|
12
|
+
*
|
13
|
+
* @see https://modelfusion.dev/guide/function/generate-text
|
14
|
+
*
|
15
|
+
* @example
|
16
|
+
* const textStream = await streamText(
|
17
|
+
* new OpenAICompletionModel(...),
|
18
|
+
* "Write a short story about a robot learning to love:\n\n"
|
19
|
+
* );
|
20
|
+
*
|
21
|
+
* for await (const textPart of textStream) {
|
22
|
+
* // ...
|
23
|
+
* }
|
24
|
+
*
|
25
|
+
* @param {TextStreamingModel<PROMPT>} model - The model to stream text from.
|
26
|
+
* @param {PROMPT} prompt - The prompt to use for text generation.
|
27
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
28
|
+
*
|
29
|
+
* @returns {AsyncIterableResultPromise<string>} An async iterable promise that yields the generated text.
|
30
|
+
*/
|
6
31
|
function streamText(model, prompt, options) {
|
7
32
|
let accumulatedText = "";
|
8
33
|
let lastFullDelta;
|
@@ -1,4 +1,29 @@
|
|
1
1
|
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
|
3
3
|
import { TextStreamingModel } from "./TextGenerationModel.js";
|
4
|
+
/**
|
5
|
+
* Stream the generated text for a prompt as an async iterable.
|
6
|
+
*
|
7
|
+
* The prompt depends on the model used.
|
8
|
+
* For instance, OpenAI completion models expect a string prompt,
|
9
|
+
* whereas OpenAI chat models expect an array of chat messages.
|
10
|
+
*
|
11
|
+
* @see https://modelfusion.dev/guide/function/generate-text
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* const textStream = await streamText(
|
15
|
+
* new OpenAICompletionModel(...),
|
16
|
+
* "Write a short story about a robot learning to love:\n\n"
|
17
|
+
* );
|
18
|
+
*
|
19
|
+
* for await (const textPart of textStream) {
|
20
|
+
* // ...
|
21
|
+
* }
|
22
|
+
*
|
23
|
+
* @param {TextStreamingModel<PROMPT>} model - The model to stream text from.
|
24
|
+
* @param {PROMPT} prompt - The prompt to use for text generation.
|
25
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
26
|
+
*
|
27
|
+
* @returns {AsyncIterableResultPromise<string>} An async iterable promise that yields the generated text.
|
28
|
+
*/
|
4
29
|
export declare function streamText<PROMPT>(model: TextStreamingModel<PROMPT>, prompt: PROMPT, options?: FunctionOptions): AsyncIterableResultPromise<string>;
|
@@ -1,5 +1,30 @@
|
|
1
1
|
import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
|
2
2
|
import { executeStreamCall } from "../executeStreamCall.js";
|
3
|
+
/**
|
4
|
+
* Stream the generated text for a prompt as an async iterable.
|
5
|
+
*
|
6
|
+
* The prompt depends on the model used.
|
7
|
+
* For instance, OpenAI completion models expect a string prompt,
|
8
|
+
* whereas OpenAI chat models expect an array of chat messages.
|
9
|
+
*
|
10
|
+
* @see https://modelfusion.dev/guide/function/generate-text
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* const textStream = await streamText(
|
14
|
+
* new OpenAICompletionModel(...),
|
15
|
+
* "Write a short story about a robot learning to love:\n\n"
|
16
|
+
* );
|
17
|
+
*
|
18
|
+
* for await (const textPart of textStream) {
|
19
|
+
* // ...
|
20
|
+
* }
|
21
|
+
*
|
22
|
+
* @param {TextStreamingModel<PROMPT>} model - The model to stream text from.
|
23
|
+
* @param {PROMPT} prompt - The prompt to use for text generation.
|
24
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
25
|
+
*
|
26
|
+
* @returns {AsyncIterableResultPromise<string>} An async iterable promise that yields the generated text.
|
27
|
+
*/
|
3
28
|
export function streamText(model, prompt, options) {
|
4
29
|
let accumulatedText = "";
|
5
30
|
let lastFullDelta;
|
@@ -4,18 +4,23 @@ exports.generateTranscription = void 0;
|
|
4
4
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
5
|
const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
|
6
6
|
/**
|
7
|
-
* Transcribe audio data into text.
|
7
|
+
* Transcribe audio data into text. Also called speech-to-text (STT) or automatic speech recognition (ASR).
|
8
|
+
*
|
9
|
+
* @see https://modelfusion.dev/guide/function/generate-transcription
|
8
10
|
*
|
9
11
|
* @example
|
10
12
|
* const data = await fs.promises.readFile("data/test.mp3");
|
11
13
|
*
|
12
14
|
* const transcription = await generateTranscription(
|
13
15
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
14
|
-
* {
|
15
|
-
* type: "mp3",
|
16
|
-
* data,
|
17
|
-
* }
|
16
|
+
* { type: "mp3", data }
|
18
17
|
* );
|
18
|
+
*
|
19
|
+
* @param {TranscriptionModel<DATA, TranscriptionModelSettings>} model - The model to use for transcription.
|
20
|
+
* @param {DATA} data - The data to transcribe.
|
21
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
22
|
+
*
|
23
|
+
* @returns {ModelFunctionPromise<string>} A promise that resolves to the transcribed text.
|
19
24
|
*/
|
20
25
|
function generateTranscription(model, data, options) {
|
21
26
|
return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
|
@@ -2,17 +2,22 @@ import { FunctionOptions } from "../../core/FunctionOptions.js";
|
|
2
2
|
import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
3
3
|
import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionModel.js";
|
4
4
|
/**
|
5
|
-
* Transcribe audio data into text.
|
5
|
+
* Transcribe audio data into text. Also called speech-to-text (STT) or automatic speech recognition (ASR).
|
6
|
+
*
|
7
|
+
* @see https://modelfusion.dev/guide/function/generate-transcription
|
6
8
|
*
|
7
9
|
* @example
|
8
10
|
* const data = await fs.promises.readFile("data/test.mp3");
|
9
11
|
*
|
10
12
|
* const transcription = await generateTranscription(
|
11
13
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
12
|
-
* {
|
13
|
-
* type: "mp3",
|
14
|
-
* data,
|
15
|
-
* }
|
14
|
+
* { type: "mp3", data }
|
16
15
|
* );
|
16
|
+
*
|
17
|
+
* @param {TranscriptionModel<DATA, TranscriptionModelSettings>} model - The model to use for transcription.
|
18
|
+
* @param {DATA} data - The data to transcribe.
|
19
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
20
|
+
*
|
21
|
+
* @returns {ModelFunctionPromise<string>} A promise that resolves to the transcribed text.
|
17
22
|
*/
|
18
23
|
export declare function generateTranscription<DATA>(model: TranscriptionModel<DATA, TranscriptionModelSettings>, data: DATA, options?: FunctionOptions): ModelFunctionPromise<string>;
|
@@ -1,18 +1,23 @@
|
|
1
1
|
import { executeStandardCall } from "../executeStandardCall.js";
|
2
2
|
import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
3
3
|
/**
|
4
|
-
* Transcribe audio data into text.
|
4
|
+
* Transcribe audio data into text. Also called speech-to-text (STT) or automatic speech recognition (ASR).
|
5
|
+
*
|
6
|
+
* @see https://modelfusion.dev/guide/function/generate-transcription
|
5
7
|
*
|
6
8
|
* @example
|
7
9
|
* const data = await fs.promises.readFile("data/test.mp3");
|
8
10
|
*
|
9
11
|
* const transcription = await generateTranscription(
|
10
12
|
* new OpenAITranscriptionModel({ model: "whisper-1" }),
|
11
|
-
* {
|
12
|
-
* type: "mp3",
|
13
|
-
* data,
|
14
|
-
* }
|
13
|
+
* { type: "mp3", data }
|
15
14
|
* );
|
15
|
+
*
|
16
|
+
* @param {TranscriptionModel<DATA, TranscriptionModelSettings>} model - The model to use for transcription.
|
17
|
+
* @param {DATA} data - The data to transcribe.
|
18
|
+
* @param {FunctionOptions} [options] - Optional parameters for the function.
|
19
|
+
*
|
20
|
+
* @returns {ModelFunctionPromise<string>} A promise that resolves to the transcribed text.
|
16
21
|
*/
|
17
22
|
export function generateTranscription(model, data, options) {
|
18
23
|
return new ModelFunctionPromise(executeStandardCall({
|
@@ -1,19 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* Interface for a basic tokenizer capable of converting text into tokens.
|
3
|
+
*
|
4
|
+
* This serves as the base for tokenization functionalities where the focus is on the transformation of input text into a series of numeric tokens.
|
5
|
+
*/
|
1
6
|
export interface BasicTokenizer {
|
2
7
|
/**
|
3
|
-
*
|
8
|
+
* Asynchronously tokenize the given text into a sequence of numeric tokens.
|
9
|
+
*
|
10
|
+
* @param text - Input text string that needs to be tokenized.
|
11
|
+
* @returns A promise containing an array of numbers, where each number is a token representing a part or the whole of the input text.
|
4
12
|
*/
|
5
13
|
tokenize: (text: string) => PromiseLike<Array<number>>;
|
6
14
|
}
|
15
|
+
/**
|
16
|
+
* Interface for a comprehensive tokenizer that extends the basic tokenization capabilities.
|
17
|
+
*
|
18
|
+
* In addition to basic tokenization, this interface provides methods for detokenization and
|
19
|
+
* retrieving the original text corresponding to each token, enabling a more informative and reversible transformation process.
|
20
|
+
*/
|
7
21
|
export interface FullTokenizer extends BasicTokenizer {
|
8
22
|
/**
|
9
|
-
*
|
23
|
+
* Asynchronously tokenize the given text, providing both the numeric tokens and their corresponding text.
|
24
|
+
*
|
25
|
+
* @param text - Input text string to be tokenized.
|
26
|
+
* @returns A promise containing an object with two arrays:
|
27
|
+
* 1. `tokens` - An array of numbers where each number is a token.
|
28
|
+
* 2. `tokenTexts` - An array of strings where each string represents the original text corresponding to each token.
|
10
29
|
*/
|
11
30
|
tokenizeWithTexts: (text: string) => PromiseLike<{
|
12
31
|
tokens: Array<number>;
|
13
32
|
tokenTexts: Array<string>;
|
14
33
|
}>;
|
15
34
|
/**
|
16
|
-
*
|
35
|
+
* Asynchronously revert a sequence of numeric tokens back into the original text.
|
36
|
+
* Detokenization is the process of transforming tokens back to a human-readable format, and it's essential in scenarios
|
37
|
+
* where the output needs to be interpretable or when the tokenization process has to be reversible.
|
38
|
+
*
|
39
|
+
* @param tokens - An array of numeric tokens to be converted back to text.
|
40
|
+
* @returns A promise containing a string that represents the original text corresponding to the sequence of input tokens.
|
17
41
|
*/
|
18
42
|
detokenize: (tokens: Array<number>) => PromiseLike<string>;
|
19
43
|
}
|
package/package.json
CHANGED
package/util/AsyncQueue.cjs
CHANGED
@@ -22,7 +22,7 @@ class AsyncQueue {
|
|
22
22
|
enumerable: true,
|
23
23
|
configurable: true,
|
24
24
|
writable: true,
|
25
|
-
value:
|
25
|
+
value: Array()
|
26
26
|
});
|
27
27
|
Object.defineProperty(this, "pendingResolvers", {
|
28
28
|
enumerable: true,
|
@@ -37,6 +37,11 @@ class AsyncQueue {
|
|
37
37
|
value: false
|
38
38
|
});
|
39
39
|
}
|
40
|
+
processPendingResolvers() {
|
41
|
+
while (this.pendingResolvers.length > 0) {
|
42
|
+
this.pendingResolvers.shift()?.();
|
43
|
+
}
|
44
|
+
}
|
40
45
|
/**
|
41
46
|
* Pushes an element onto the queue. If the queue is closed, an error is thrown.
|
42
47
|
*
|
@@ -47,12 +52,17 @@ class AsyncQueue {
|
|
47
52
|
*/
|
48
53
|
push(value) {
|
49
54
|
if (this.closed) {
|
50
|
-
throw new Error("Cannot push value to closed queue.
|
55
|
+
throw new Error("Cannot push value to closed queue.");
|
51
56
|
}
|
52
|
-
this.values.push(value);
|
53
|
-
|
54
|
-
|
57
|
+
this.values.push({ type: "value", value });
|
58
|
+
this.processPendingResolvers();
|
59
|
+
}
|
60
|
+
error(error) {
|
61
|
+
if (this.closed) {
|
62
|
+
throw new Error("Cannot push error to closed queue.");
|
55
63
|
}
|
64
|
+
this.values.push({ type: "error", error });
|
65
|
+
this.processPendingResolvers();
|
56
66
|
}
|
57
67
|
/**
|
58
68
|
* Closes the queue, preventing more elements from being pushed onto it.
|
@@ -62,9 +72,7 @@ class AsyncQueue {
|
|
62
72
|
*/
|
63
73
|
close() {
|
64
74
|
this.closed = true;
|
65
|
-
|
66
|
-
this.pendingResolvers.shift()?.();
|
67
|
-
}
|
75
|
+
this.processPendingResolvers();
|
68
76
|
}
|
69
77
|
/**
|
70
78
|
* Creates and returns an async iterator that allows the queue to be consumed.
|
@@ -81,11 +89,18 @@ class AsyncQueue {
|
|
81
89
|
[Symbol.asyncIterator]() {
|
82
90
|
let position = 0;
|
83
91
|
return {
|
84
|
-
next: () => new Promise((resolve) => {
|
92
|
+
next: () => new Promise((resolve, reject) => {
|
85
93
|
const attemptResolve = () => {
|
86
94
|
if (position < this.values.length) {
|
87
|
-
|
88
|
-
|
95
|
+
const entry = this.values[position++];
|
96
|
+
switch (entry.type) {
|
97
|
+
case "value":
|
98
|
+
resolve({ value: entry.value, done: false });
|
99
|
+
break;
|
100
|
+
case "error":
|
101
|
+
reject(entry.error);
|
102
|
+
break;
|
103
|
+
}
|
89
104
|
}
|
90
105
|
else if (this.closed) {
|
91
106
|
// The queue is closed, and there are no more values. Complete the iteration.
|
package/util/AsyncQueue.d.ts
CHANGED
@@ -17,6 +17,7 @@ export declare class AsyncQueue<T> implements AsyncIterable<T> {
|
|
17
17
|
private values;
|
18
18
|
private pendingResolvers;
|
19
19
|
private closed;
|
20
|
+
private processPendingResolvers;
|
20
21
|
/**
|
21
22
|
* Pushes an element onto the queue. If the queue is closed, an error is thrown.
|
22
23
|
*
|
@@ -26,6 +27,7 @@ export declare class AsyncQueue<T> implements AsyncIterable<T> {
|
|
26
27
|
* queue.push(2);
|
27
28
|
*/
|
28
29
|
push(value: T): void;
|
30
|
+
error(error: unknown): void;
|
29
31
|
/**
|
30
32
|
* Closes the queue, preventing more elements from being pushed onto it.
|
31
33
|
*
|
package/util/AsyncQueue.js
CHANGED
@@ -19,7 +19,7 @@ export class AsyncQueue {
|
|
19
19
|
enumerable: true,
|
20
20
|
configurable: true,
|
21
21
|
writable: true,
|
22
|
-
value:
|
22
|
+
value: Array()
|
23
23
|
});
|
24
24
|
Object.defineProperty(this, "pendingResolvers", {
|
25
25
|
enumerable: true,
|
@@ -34,6 +34,11 @@ export class AsyncQueue {
|
|
34
34
|
value: false
|
35
35
|
});
|
36
36
|
}
|
37
|
+
processPendingResolvers() {
|
38
|
+
while (this.pendingResolvers.length > 0) {
|
39
|
+
this.pendingResolvers.shift()?.();
|
40
|
+
}
|
41
|
+
}
|
37
42
|
/**
|
38
43
|
* Pushes an element onto the queue. If the queue is closed, an error is thrown.
|
39
44
|
*
|
@@ -44,12 +49,17 @@ export class AsyncQueue {
|
|
44
49
|
*/
|
45
50
|
push(value) {
|
46
51
|
if (this.closed) {
|
47
|
-
throw new Error("Cannot push value to closed queue.
|
52
|
+
throw new Error("Cannot push value to closed queue.");
|
48
53
|
}
|
49
|
-
this.values.push(value);
|
50
|
-
|
51
|
-
|
54
|
+
this.values.push({ type: "value", value });
|
55
|
+
this.processPendingResolvers();
|
56
|
+
}
|
57
|
+
error(error) {
|
58
|
+
if (this.closed) {
|
59
|
+
throw new Error("Cannot push error to closed queue.");
|
52
60
|
}
|
61
|
+
this.values.push({ type: "error", error });
|
62
|
+
this.processPendingResolvers();
|
53
63
|
}
|
54
64
|
/**
|
55
65
|
* Closes the queue, preventing more elements from being pushed onto it.
|
@@ -59,9 +69,7 @@ export class AsyncQueue {
|
|
59
69
|
*/
|
60
70
|
close() {
|
61
71
|
this.closed = true;
|
62
|
-
|
63
|
-
this.pendingResolvers.shift()?.();
|
64
|
-
}
|
72
|
+
this.processPendingResolvers();
|
65
73
|
}
|
66
74
|
/**
|
67
75
|
* Creates and returns an async iterator that allows the queue to be consumed.
|
@@ -78,11 +86,18 @@ export class AsyncQueue {
|
|
78
86
|
[Symbol.asyncIterator]() {
|
79
87
|
let position = 0;
|
80
88
|
return {
|
81
|
-
next: () => new Promise((resolve) => {
|
89
|
+
next: () => new Promise((resolve, reject) => {
|
82
90
|
const attemptResolve = () => {
|
83
91
|
if (position < this.values.length) {
|
84
|
-
|
85
|
-
|
92
|
+
const entry = this.values[position++];
|
93
|
+
switch (entry.type) {
|
94
|
+
case "value":
|
95
|
+
resolve({ value: entry.value, done: false });
|
96
|
+
break;
|
97
|
+
case "error":
|
98
|
+
reject(entry.error);
|
99
|
+
break;
|
100
|
+
}
|
86
101
|
}
|
87
102
|
else if (this.closed) {
|
88
103
|
// The queue is closed, and there are no more values. Complete the iteration.
|
package/util/AsyncQueue.test.cjs
CHANGED
@@ -134,5 +134,5 @@ const AsyncQueue_js_1 = require("./AsyncQueue.cjs");
|
|
134
134
|
(0, vitest_1.test)("throw error when pushing to a closed queue", async () => {
|
135
135
|
const asyncQueue = new AsyncQueue_js_1.AsyncQueue();
|
136
136
|
asyncQueue.close();
|
137
|
-
(0, vitest_1.expect)(() => asyncQueue.push(1)).toThrowError("Cannot push value to closed queue.
|
137
|
+
(0, vitest_1.expect)(() => asyncQueue.push(1)).toThrowError("Cannot push value to closed queue.");
|
138
138
|
});
|
package/util/AsyncQueue.test.js
CHANGED
@@ -132,5 +132,5 @@ test("each consumer receives all pushed values under varying conditions", async
|
|
132
132
|
test("throw error when pushing to a closed queue", async () => {
|
133
133
|
const asyncQueue = new AsyncQueue();
|
134
134
|
asyncQueue.close();
|
135
|
-
expect(() => asyncQueue.push(1)).toThrowError("Cannot push value to closed queue.
|
135
|
+
expect(() => asyncQueue.push(1)).toThrowError("Cannot push value to closed queue.");
|
136
136
|
});
|
package/util/delay.cjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.delay = void 0;
|
4
|
-
async function delay(
|
5
|
-
return new Promise((resolve) => setTimeout(resolve,
|
4
|
+
async function delay(delayInMs) {
|
5
|
+
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
6
6
|
}
|
7
7
|
exports.delay = delay;
|
package/util/delay.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare function delay(
|
1
|
+
export declare function delay(delayInMs: number): Promise<void>;
|
package/util/delay.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export async function delay(
|
2
|
-
return new Promise((resolve) => setTimeout(resolve,
|
1
|
+
export async function delay(delayInMs) {
|
2
|
+
return new Promise((resolve) => setTimeout(resolve, delayInMs));
|
3
3
|
}
|
package/util/index.cjs
CHANGED
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./AsyncQueue.cjs"), exports);
|
18
18
|
__exportStar(require("./JSONParseError.cjs"), exports);
|
19
19
|
__exportStar(require("./cosineSimilarity.cjs"), exports);
|
20
|
+
__exportStar(require("./delay.cjs"), exports);
|
20
21
|
__exportStar(require("./getAudioFileExtension.cjs"), exports);
|
21
22
|
__exportStar(require("./parseJSON.cjs"), exports);
|
package/util/index.d.ts
CHANGED