modelfusion 0.20.1 → 0.22.0
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/README.md +5 -7
- package/composed-function/summarize/SummarizationFunction.d.ts +3 -3
- package/composed-function/summarize/summarizeRecursively.d.ts +1 -1
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +1 -1
- package/{run → core}/ConsoleLogger.cjs +1 -4
- package/core/ConsoleLogger.d.ts +5 -0
- package/core/ConsoleLogger.js +5 -0
- package/{run → core}/DefaultRun.cjs +2 -5
- package/{run → core}/DefaultRun.d.ts +5 -5
- package/{run → core}/DefaultRun.js +2 -5
- package/core/FunctionEvent.d.ts +75 -0
- package/{run/RunFunctionEventSource.js → core/FunctionEventSource.cjs} +7 -13
- package/core/FunctionEventSource.d.ts +12 -0
- package/{run/RunFunctionEventSource.cjs → core/FunctionEventSource.js} +3 -17
- package/core/FunctionObserver.d.ts +7 -0
- package/core/FunctionOptions.d.ts +19 -0
- package/core/GlobalFunctionObservers.cjs +12 -0
- package/core/GlobalFunctionObservers.d.ts +3 -0
- package/core/GlobalFunctionObservers.js +7 -0
- package/{run → core}/Run.d.ts +2 -2
- package/{run → core}/index.cjs +5 -5
- package/core/index.d.ts +9 -0
- package/core/index.js +9 -0
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/model-function/Model.d.ts +5 -2
- package/model-function/ModelCallEvent.d.ts +20 -5
- package/model-function/ModelFunctionOptions.d.ts +4 -0
- package/model-function/SuccessfulModelCall.cjs +6 -16
- package/model-function/SuccessfulModelCall.d.ts +2 -2
- package/model-function/SuccessfulModelCall.js +6 -16
- package/model-function/embed-text/TextEmbeddingEvent.d.ts +15 -17
- package/model-function/embed-text/TextEmbeddingModel.d.ts +3 -3
- package/model-function/embed-text/embedText.cjs +6 -67
- package/model-function/embed-text/embedText.d.ts +4 -4
- package/model-function/embed-text/embedText.js +6 -67
- package/model-function/executeCall.cjs +49 -14
- package/model-function/executeCall.d.ts +9 -10
- package/model-function/executeCall.js +49 -14
- package/model-function/generate-image/ImageGenerationEvent.d.ts +12 -16
- package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
- package/model-function/generate-image/generateImage.cjs +2 -30
- package/model-function/generate-image/generateImage.d.ts +2 -2
- package/model-function/generate-image/generateImage.js +2 -30
- package/model-function/generate-json/GenerateJsonModel.d.ts +2 -2
- package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +2 -2
- package/model-function/generate-json/JsonGenerationEvent.d.ts +6 -21
- package/model-function/generate-json/JsonTextGenerationModel.d.ts +2 -2
- package/model-function/generate-json/generateJson.cjs +2 -30
- package/model-function/generate-json/generateJson.d.ts +2 -2
- package/model-function/generate-json/generateJson.js +2 -30
- package/model-function/generate-json/generateJsonOrText.cjs +2 -30
- package/model-function/generate-json/generateJsonOrText.d.ts +2 -2
- package/model-function/generate-json/generateJsonOrText.js +2 -30
- package/model-function/generate-text/TextGenerationEvent.d.ts +13 -15
- package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
- package/model-function/generate-text/TextStreamingEvent.d.ts +7 -22
- package/model-function/generate-text/generateText.cjs +2 -30
- package/model-function/generate-text/generateText.d.ts +2 -2
- package/model-function/generate-text/generateText.js +2 -30
- package/model-function/generate-text/streamText.cjs +52 -42
- package/model-function/generate-text/streamText.d.ts +5 -5
- package/model-function/generate-text/streamText.js +52 -42
- package/model-function/index.cjs +1 -1
- package/model-function/index.d.ts +1 -1
- package/model-function/index.js +1 -1
- package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +14 -15
- package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +2 -2
- package/model-function/synthesize-speech/synthesizeSpeech.cjs +2 -30
- package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
- package/model-function/synthesize-speech/synthesizeSpeech.js +2 -30
- package/model-function/transcribe-speech/TranscriptionEvent.d.ts +12 -16
- package/model-function/transcribe-speech/TranscriptionModel.d.ts +2 -2
- package/model-function/transcribe-speech/transcribe.cjs +2 -30
- package/model-function/transcribe-speech/transcribe.d.ts +2 -2
- package/model-function/transcribe-speech/transcribe.js +2 -30
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +6 -6
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +4 -4
- package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -3
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +3 -3
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +4 -4
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +3 -3
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -4
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +5 -5
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +3 -3
- package/package.json +1 -1
- package/prompt/PromptFormatTextGenerationModel.d.ts +3 -3
- package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -0
- package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.d.ts +2 -2
- package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +2 -2
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +2 -2
- package/text-chunk/split/SplitFunction.d.ts +3 -3
- package/text-chunk/upsertTextChunks.d.ts +2 -2
- package/tool/ExecuteToolEvent.d.ts +9 -20
- package/tool/Tool.d.ts +3 -3
- package/tool/WebSearchTool.cjs +25 -0
- package/tool/WebSearchTool.d.ts +57 -1
- package/tool/WebSearchTool.js +25 -0
- package/tool/executeTool.cjs +39 -31
- package/tool/executeTool.d.ts +5 -4
- package/tool/executeTool.js +39 -31
- package/tool/useTool.cjs +2 -6
- package/tool/useTool.d.ts +2 -2
- package/tool/useTool.js +2 -6
- package/tool/useToolOrGenerateText.cjs +1 -3
- package/tool/useToolOrGenerateText.d.ts +2 -2
- package/tool/useToolOrGenerateText.js +1 -3
- package/util/DurationMeasurement.cjs +6 -0
- package/util/DurationMeasurement.d.ts +1 -0
- package/util/DurationMeasurement.js +6 -0
- package/util/api/postToApi.cjs +8 -0
- package/util/api/postToApi.js +8 -0
- package/vector-index/VectorIndex.d.ts +1 -1
- package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
- package/vector-index/pinecone/PineconeVectorIndex.d.ts +1 -1
- package/model-function/FunctionOptions.d.ts +0 -6
- package/run/ConsoleLogger.d.ts +0 -6
- package/run/ConsoleLogger.js +0 -8
- package/run/IdMetadata.d.ts +0 -7
- package/run/RunFunction.d.ts +0 -9
- package/run/RunFunctionEvent.d.ts +0 -12
- package/run/RunFunctionEventSource.d.ts +0 -13
- package/run/RunFunctionObserver.cjs +0 -2
- package/run/RunFunctionObserver.d.ts +0 -5
- package/run/RunFunctionObserver.js +0 -1
- package/run/index.d.ts +0 -9
- package/run/index.js +0 -9
- /package/{model-function/FunctionOptions.cjs → core/FunctionEvent.cjs} +0 -0
- /package/{model-function/FunctionOptions.js → core/FunctionEvent.js} +0 -0
- /package/{run/IdMetadata.cjs → core/FunctionObserver.cjs} +0 -0
- /package/{run/IdMetadata.js → core/FunctionObserver.js} +0 -0
- /package/{run/Run.cjs → core/FunctionOptions.cjs} +0 -0
- /package/{run/Run.js → core/FunctionOptions.js} +0 -0
- /package/{run/RunFunction.cjs → core/Run.cjs} +0 -0
- /package/{run/RunFunction.js → core/Run.js} +0 -0
- /package/{run → core}/Vector.cjs +0 -0
- /package/{run → core}/Vector.d.ts +0 -0
- /package/{run → core}/Vector.js +0 -0
- /package/{run/RunFunctionEvent.cjs → model-function/ModelFunctionOptions.cjs} +0 -0
- /package/{run/RunFunctionEvent.js → model-function/ModelFunctionOptions.js} +0 -0
@@ -1,5 +1,6 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
-
import {
|
2
|
+
import { FunctionEventSource } from "../../core/FunctionEventSource.js";
|
3
|
+
import { getGlobalFunctionObservers } from "../../core/GlobalFunctionObservers.js";
|
3
4
|
import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
|
4
5
|
import { AbortError } from "../../util/api/AbortError.js";
|
5
6
|
import { runSafe } from "../../util/runSafe.js";
|
@@ -45,13 +46,19 @@ async function doStreamText(model, prompt, options) {
|
|
45
46
|
model = model.withSettings(options.settings);
|
46
47
|
options = {
|
47
48
|
functionId: options.functionId,
|
49
|
+
observers: options.observers,
|
48
50
|
run: options.run,
|
49
51
|
};
|
50
52
|
}
|
51
53
|
const run = options?.run;
|
52
54
|
const settings = model.settings;
|
53
|
-
const eventSource = new
|
54
|
-
observers: [
|
55
|
+
const eventSource = new FunctionEventSource({
|
56
|
+
observers: [
|
57
|
+
...getGlobalFunctionObservers(),
|
58
|
+
...(settings.observers ?? []),
|
59
|
+
...(run?.observers ?? []),
|
60
|
+
...(options?.observers ?? []),
|
61
|
+
],
|
55
62
|
errorHandler: run?.errorHandler,
|
56
63
|
});
|
57
64
|
const durationMeasurement = startDurationMeasurement();
|
@@ -62,13 +69,15 @@ async function doStreamText(model, prompt, options) {
|
|
62
69
|
userId: run?.userId,
|
63
70
|
functionId: options?.functionId,
|
64
71
|
model: model.modelInformation,
|
65
|
-
|
66
|
-
|
67
|
-
eventSource.notifyRunFunctionStarted({
|
68
|
-
type: "text-streaming-started",
|
69
|
-
metadata: startMetadata,
|
72
|
+
functionType: "text-streaming",
|
73
|
+
input: prompt,
|
70
74
|
settings,
|
71
|
-
|
75
|
+
timestamp: durationMeasurement.startDate,
|
76
|
+
startTimestamp: durationMeasurement.startDate,
|
77
|
+
};
|
78
|
+
eventSource.notify({
|
79
|
+
...startMetadata,
|
80
|
+
eventType: "started",
|
72
81
|
});
|
73
82
|
const result = await runSafe(async () => extractTextDeltas({
|
74
83
|
deltaIterable: await model.generateDeltaStreamResponse(prompt, {
|
@@ -80,63 +89,64 @@ async function doStreamText(model, prompt, options) {
|
|
80
89
|
onDone: (fullText, lastFullDelta) => {
|
81
90
|
const finishMetadata = {
|
82
91
|
...startMetadata,
|
92
|
+
eventType: "finished",
|
93
|
+
finishTimestamp: new Date(),
|
83
94
|
durationInMs: durationMeasurement.durationInMs,
|
84
95
|
};
|
85
|
-
eventSource.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
generatedText: fullText,
|
96
|
+
eventSource.notify({
|
97
|
+
...finishMetadata,
|
98
|
+
result: {
|
99
|
+
status: "success",
|
100
|
+
response: lastFullDelta,
|
101
|
+
output: fullText,
|
102
|
+
},
|
93
103
|
});
|
94
104
|
},
|
95
105
|
onError: (error) => {
|
96
106
|
const finishMetadata = {
|
97
107
|
...startMetadata,
|
108
|
+
eventType: "finished",
|
109
|
+
finishTimestamp: new Date(),
|
98
110
|
durationInMs: durationMeasurement.durationInMs,
|
99
111
|
};
|
100
|
-
eventSource.
|
112
|
+
eventSource.notify(error instanceof AbortError
|
101
113
|
? {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
prompt,
|
114
|
+
...finishMetadata,
|
115
|
+
result: {
|
116
|
+
status: "abort",
|
117
|
+
},
|
107
118
|
}
|
108
119
|
: {
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
error,
|
120
|
+
...finishMetadata,
|
121
|
+
result: {
|
122
|
+
status: "error",
|
123
|
+
error,
|
124
|
+
},
|
115
125
|
});
|
116
126
|
},
|
117
127
|
}));
|
118
128
|
if (!result.ok) {
|
119
129
|
const finishMetadata = {
|
120
130
|
...startMetadata,
|
131
|
+
eventType: "finished",
|
132
|
+
finishTimestamp: new Date(),
|
121
133
|
durationInMs: durationMeasurement.durationInMs,
|
122
134
|
};
|
123
135
|
if (result.isAborted) {
|
124
|
-
eventSource.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
prompt,
|
136
|
+
eventSource.notify({
|
137
|
+
...finishMetadata,
|
138
|
+
result: {
|
139
|
+
status: "abort",
|
140
|
+
},
|
130
141
|
});
|
131
142
|
throw new AbortError();
|
132
143
|
}
|
133
|
-
eventSource.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
error: result.error,
|
144
|
+
eventSource.notify({
|
145
|
+
...finishMetadata,
|
146
|
+
result: {
|
147
|
+
status: "error",
|
148
|
+
error: result.error,
|
149
|
+
},
|
140
150
|
});
|
141
151
|
throw result.error;
|
142
152
|
}
|
package/model-function/index.cjs
CHANGED
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./FunctionOptions.cjs"), exports);
|
18
17
|
__exportStar(require("./Model.cjs"), exports);
|
19
18
|
__exportStar(require("./ModelCallEvent.cjs"), exports);
|
19
|
+
__exportStar(require("./ModelFunctionOptions.cjs"), exports);
|
20
20
|
__exportStar(require("./ModelInformation.cjs"), exports);
|
21
21
|
__exportStar(require("./SuccessfulModelCall.cjs"), exports);
|
22
22
|
__exportStar(require("./embed-text/TextEmbeddingEvent.cjs"), exports);
|
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from "./FunctionOptions.js";
|
2
1
|
export * from "./Model.js";
|
3
2
|
export * from "./ModelCallEvent.js";
|
3
|
+
export * from "./ModelFunctionOptions.js";
|
4
4
|
export * from "./ModelInformation.js";
|
5
5
|
export * from "./SuccessfulModelCall.js";
|
6
6
|
export * from "./embed-text/TextEmbeddingEvent.js";
|
package/model-function/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from "./FunctionOptions.js";
|
2
1
|
export * from "./Model.js";
|
3
2
|
export * from "./ModelCallEvent.js";
|
3
|
+
export * from "./ModelFunctionOptions.js";
|
4
4
|
export * from "./ModelInformation.js";
|
5
5
|
export * from "./SuccessfulModelCall.js";
|
6
6
|
export * from "./embed-text/TextEmbeddingEvent.js";
|
@@ -1,22 +1,21 @@
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
2
|
-
import {
|
3
|
-
export
|
4
|
-
|
5
|
-
metadata: ModelCallStartedEventMetadata;
|
6
|
-
settings: unknown;
|
2
|
+
import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
|
3
|
+
export interface SpeechSynthesisStartedEvent extends BaseModelCallStartedEvent {
|
4
|
+
functionType: "speech-synthesis";
|
7
5
|
text: string;
|
8
|
-
}
|
9
|
-
export type
|
10
|
-
type: "speech-synthesis-finished";
|
11
|
-
metadata: ModelCallFinishedEventMetadata;
|
12
|
-
settings: unknown;
|
13
|
-
text: string;
|
14
|
-
} & ({
|
6
|
+
}
|
7
|
+
export type SpeechSynthesisFinishedEventResult = {
|
15
8
|
status: "success";
|
16
|
-
response:
|
9
|
+
response: unknown;
|
10
|
+
output: Buffer;
|
17
11
|
} | {
|
18
|
-
status: "
|
12
|
+
status: "error";
|
19
13
|
error: unknown;
|
20
14
|
} | {
|
21
15
|
status: "abort";
|
22
|
-
}
|
16
|
+
};
|
17
|
+
export interface SpeechSynthesisFinishedEvent extends BaseModelCallFinishedEvent {
|
18
|
+
functionType: "speech-synthesis";
|
19
|
+
text: string;
|
20
|
+
result: SpeechSynthesisFinishedEventResult;
|
21
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
2
|
-
import {
|
2
|
+
import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
|
3
3
|
import { Model, ModelSettings } from "../Model.js";
|
4
4
|
export interface SpeechSynthesisModelSettings extends ModelSettings {
|
5
5
|
}
|
@@ -7,5 +7,5 @@ export interface SpeechSynthesisModel<SETTINGS> extends Model<SETTINGS> {
|
|
7
7
|
/**
|
8
8
|
* Generates an mp3 audio buffer that contains the speech for the given text.
|
9
9
|
*/
|
10
|
-
generateSpeechResponse: (text: string, options?:
|
10
|
+
generateSpeechResponse: (text: string, options?: ModelFunctionOptions<SETTINGS>) => PromiseLike<Buffer>;
|
11
11
|
}
|
@@ -7,40 +7,12 @@ const executeCall_js_1 = require("../executeCall.cjs");
|
|
7
7
|
*/
|
8
8
|
function synthesizeSpeech(model, text, options) {
|
9
9
|
return (0, executeCall_js_1.executeCall)({
|
10
|
+
functionType: "speech-synthesis",
|
11
|
+
input: text,
|
10
12
|
model,
|
11
13
|
options,
|
12
14
|
generateResponse: (options) => model.generateSpeechResponse(text, options),
|
13
15
|
extractOutputValue: (buffer) => buffer,
|
14
|
-
getStartEvent: (metadata, settings) => ({
|
15
|
-
type: "speech-synthesis-started",
|
16
|
-
metadata,
|
17
|
-
settings,
|
18
|
-
text,
|
19
|
-
}),
|
20
|
-
getAbortEvent: (metadata, settings) => ({
|
21
|
-
type: "speech-synthesis-finished",
|
22
|
-
status: "abort",
|
23
|
-
settings,
|
24
|
-
metadata,
|
25
|
-
text,
|
26
|
-
}),
|
27
|
-
getFailureEvent: (metadata, settings, error) => ({
|
28
|
-
type: "speech-synthesis-finished",
|
29
|
-
status: "failure",
|
30
|
-
metadata,
|
31
|
-
settings,
|
32
|
-
text,
|
33
|
-
error,
|
34
|
-
}),
|
35
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
36
|
-
type: "speech-synthesis-finished",
|
37
|
-
status: "success",
|
38
|
-
metadata,
|
39
|
-
settings,
|
40
|
-
text,
|
41
|
-
response,
|
42
|
-
speech: output,
|
43
|
-
}),
|
44
16
|
});
|
45
17
|
}
|
46
18
|
exports.synthesizeSpeech = synthesizeSpeech;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
2
|
-
import {
|
2
|
+
import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
|
3
3
|
import { ModelFunctionPromise } from "../executeCall.js";
|
4
4
|
import { SpeechSynthesisModel, SpeechSynthesisModelSettings } from "./SpeechSynthesisModel.js";
|
5
5
|
/**
|
6
6
|
* Synthesizes speech from text.
|
7
7
|
*/
|
8
|
-
export declare function synthesizeSpeech<SETTINGS extends SpeechSynthesisModelSettings>(model: SpeechSynthesisModel<SETTINGS>, text: string, options?:
|
8
|
+
export declare function synthesizeSpeech<SETTINGS extends SpeechSynthesisModelSettings>(model: SpeechSynthesisModel<SETTINGS>, text: string, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<SpeechSynthesisModel<SETTINGS>, Buffer, Buffer>;
|
@@ -4,39 +4,11 @@ import { executeCall } from "../executeCall.js";
|
|
4
4
|
*/
|
5
5
|
export function synthesizeSpeech(model, text, options) {
|
6
6
|
return executeCall({
|
7
|
+
functionType: "speech-synthesis",
|
8
|
+
input: text,
|
7
9
|
model,
|
8
10
|
options,
|
9
11
|
generateResponse: (options) => model.generateSpeechResponse(text, options),
|
10
12
|
extractOutputValue: (buffer) => buffer,
|
11
|
-
getStartEvent: (metadata, settings) => ({
|
12
|
-
type: "speech-synthesis-started",
|
13
|
-
metadata,
|
14
|
-
settings,
|
15
|
-
text,
|
16
|
-
}),
|
17
|
-
getAbortEvent: (metadata, settings) => ({
|
18
|
-
type: "speech-synthesis-finished",
|
19
|
-
status: "abort",
|
20
|
-
settings,
|
21
|
-
metadata,
|
22
|
-
text,
|
23
|
-
}),
|
24
|
-
getFailureEvent: (metadata, settings, error) => ({
|
25
|
-
type: "speech-synthesis-finished",
|
26
|
-
status: "failure",
|
27
|
-
metadata,
|
28
|
-
settings,
|
29
|
-
text,
|
30
|
-
error,
|
31
|
-
}),
|
32
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
33
|
-
type: "speech-synthesis-finished",
|
34
|
-
status: "success",
|
35
|
-
metadata,
|
36
|
-
settings,
|
37
|
-
text,
|
38
|
-
response,
|
39
|
-
speech: output,
|
40
|
-
}),
|
41
13
|
});
|
42
14
|
}
|
@@ -1,22 +1,18 @@
|
|
1
|
-
import {
|
2
|
-
export
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
data: unknown;
|
7
|
-
};
|
8
|
-
export type TranscriptionFinishedEvent = {
|
9
|
-
type: "transcription-finished";
|
10
|
-
metadata: ModelCallFinishedEventMetadata;
|
11
|
-
settings: unknown;
|
12
|
-
data: unknown;
|
13
|
-
} & ({
|
1
|
+
import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
|
2
|
+
export interface TranscriptionStartedEvent extends BaseModelCallStartedEvent {
|
3
|
+
functionType: "transcription";
|
4
|
+
}
|
5
|
+
export type TranscriptionFinishedEventResult = {
|
14
6
|
status: "success";
|
15
7
|
response: unknown;
|
16
|
-
|
8
|
+
output: string;
|
17
9
|
} | {
|
18
|
-
status: "
|
10
|
+
status: "error";
|
19
11
|
error: unknown;
|
20
12
|
} | {
|
21
13
|
status: "abort";
|
22
|
-
}
|
14
|
+
};
|
15
|
+
export interface TranscriptionFinishedEvent extends BaseModelCallFinishedEvent {
|
16
|
+
functionType: "transcription";
|
17
|
+
result: TranscriptionFinishedEventResult;
|
18
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
|
2
2
|
import { Model, ModelSettings } from "../Model.js";
|
3
3
|
export interface TranscriptionModelSettings extends ModelSettings {
|
4
4
|
}
|
5
5
|
export interface TranscriptionModel<DATA, RESPONSE, SETTINGS> extends Model<SETTINGS> {
|
6
|
-
generateTranscriptionResponse: (data: DATA, options?:
|
6
|
+
generateTranscriptionResponse: (data: DATA, options?: ModelFunctionOptions<SETTINGS>) => PromiseLike<RESPONSE>;
|
7
7
|
extractTranscriptionText: (response: RESPONSE) => string;
|
8
8
|
}
|
@@ -18,40 +18,12 @@ const executeCall_js_1 = require("../executeCall.cjs");
|
|
18
18
|
*/
|
19
19
|
function transcribe(model, data, options) {
|
20
20
|
return (0, executeCall_js_1.executeCall)({
|
21
|
+
functionType: "transcription",
|
22
|
+
input: data,
|
21
23
|
model,
|
22
24
|
options,
|
23
25
|
generateResponse: (options) => model.generateTranscriptionResponse(data, options),
|
24
26
|
extractOutputValue: model.extractTranscriptionText,
|
25
|
-
getStartEvent: (metadata, settings) => ({
|
26
|
-
type: "transcription-started",
|
27
|
-
metadata,
|
28
|
-
settings,
|
29
|
-
data,
|
30
|
-
}),
|
31
|
-
getAbortEvent: (metadata, settings) => ({
|
32
|
-
type: "transcription-finished",
|
33
|
-
status: "abort",
|
34
|
-
settings,
|
35
|
-
metadata,
|
36
|
-
data,
|
37
|
-
}),
|
38
|
-
getFailureEvent: (metadata, settings, error) => ({
|
39
|
-
type: "transcription-finished",
|
40
|
-
status: "failure",
|
41
|
-
metadata,
|
42
|
-
settings,
|
43
|
-
data,
|
44
|
-
error,
|
45
|
-
}),
|
46
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
47
|
-
type: "transcription-finished",
|
48
|
-
status: "success",
|
49
|
-
metadata,
|
50
|
-
settings,
|
51
|
-
data,
|
52
|
-
response,
|
53
|
-
transcription: output,
|
54
|
-
}),
|
55
27
|
});
|
56
28
|
}
|
57
29
|
exports.transcribe = transcribe;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
|
2
2
|
import { ModelFunctionPromise } from "../executeCall.js";
|
3
3
|
import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionModel.js";
|
4
4
|
/**
|
@@ -15,4 +15,4 @@ import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionM
|
|
15
15
|
* }
|
16
16
|
* );
|
17
17
|
*/
|
18
|
-
export declare function transcribe<DATA, RESPONSE, SETTINGS extends TranscriptionModelSettings>(model: TranscriptionModel<DATA, RESPONSE, SETTINGS>, data: DATA, options?:
|
18
|
+
export declare function transcribe<DATA, RESPONSE, SETTINGS extends TranscriptionModelSettings>(model: TranscriptionModel<DATA, RESPONSE, SETTINGS>, data: DATA, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<TranscriptionModel<DATA, RESPONSE, SETTINGS>, string, RESPONSE>;
|
@@ -15,39 +15,11 @@ import { executeCall } from "../executeCall.js";
|
|
15
15
|
*/
|
16
16
|
export function transcribe(model, data, options) {
|
17
17
|
return executeCall({
|
18
|
+
functionType: "transcription",
|
19
|
+
input: data,
|
18
20
|
model,
|
19
21
|
options,
|
20
22
|
generateResponse: (options) => model.generateTranscriptionResponse(data, options),
|
21
23
|
extractOutputValue: model.extractTranscriptionText,
|
22
|
-
getStartEvent: (metadata, settings) => ({
|
23
|
-
type: "transcription-started",
|
24
|
-
metadata,
|
25
|
-
settings,
|
26
|
-
data,
|
27
|
-
}),
|
28
|
-
getAbortEvent: (metadata, settings) => ({
|
29
|
-
type: "transcription-finished",
|
30
|
-
status: "abort",
|
31
|
-
settings,
|
32
|
-
metadata,
|
33
|
-
data,
|
34
|
-
}),
|
35
|
-
getFailureEvent: (metadata, settings, error) => ({
|
36
|
-
type: "transcription-finished",
|
37
|
-
status: "failure",
|
38
|
-
metadata,
|
39
|
-
settings,
|
40
|
-
data,
|
41
|
-
error,
|
42
|
-
}),
|
43
|
-
getSuccessEvent: (metadata, settings, response, output) => ({
|
44
|
-
type: "transcription-finished",
|
45
|
-
status: "success",
|
46
|
-
metadata,
|
47
|
-
settings,
|
48
|
-
data,
|
49
|
-
response,
|
50
|
-
transcription: output,
|
51
|
-
}),
|
52
24
|
});
|
53
25
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js";
|
5
5
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
6
6
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
@@ -13,8 +13,8 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
|
|
13
13
|
constructor(settings: Automatic1111ImageGenerationModelSettings);
|
14
14
|
readonly provider: "Automatic1111";
|
15
15
|
get modelName(): string;
|
16
|
-
callAPI(input: A111ImageGenerationPrompt, options?:
|
17
|
-
generateImageResponse(prompt: A111ImageGenerationPrompt, options?:
|
16
|
+
callAPI(input: A111ImageGenerationPrompt, options?: ModelFunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<Automatic1111ImageGenerationResponse>;
|
17
|
+
generateImageResponse(prompt: A111ImageGenerationPrompt, options?: ModelFunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<{
|
18
18
|
images: string[];
|
19
19
|
parameters: {};
|
20
20
|
info: string;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../../model-function/embed-text/TextEmbeddingModel.js";
|
5
5
|
import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
6
6
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
@@ -61,15 +61,15 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
|
|
61
61
|
}>;
|
62
62
|
detokenize(tokens: number[]): Promise<string>;
|
63
63
|
private get apiKey();
|
64
|
-
callAPI(texts: Array<string>, options?:
|
65
|
-
generateEmbeddingResponse(texts: string[], options?:
|
66
|
-
texts: string[];
|
64
|
+
callAPI(texts: Array<string>, options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>;
|
65
|
+
generateEmbeddingResponse(texts: string[], options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{
|
67
66
|
id: string;
|
68
67
|
meta: {
|
69
68
|
api_version: {
|
70
69
|
version: string;
|
71
70
|
};
|
72
71
|
};
|
72
|
+
texts: string[];
|
73
73
|
embeddings: number[][];
|
74
74
|
}>;
|
75
75
|
extractEmbeddings(response: CohereTextEmbeddingResponse): number[][];
|
@@ -97,22 +97,22 @@ declare const cohereTextEmbeddingResponseSchema: z.ZodObject<{
|
|
97
97
|
};
|
98
98
|
}>;
|
99
99
|
}, "strip", z.ZodTypeAny, {
|
100
|
-
texts: string[];
|
101
100
|
id: string;
|
102
101
|
meta: {
|
103
102
|
api_version: {
|
104
103
|
version: string;
|
105
104
|
};
|
106
105
|
};
|
106
|
+
texts: string[];
|
107
107
|
embeddings: number[][];
|
108
108
|
}, {
|
109
|
-
texts: string[];
|
110
109
|
id: string;
|
111
110
|
meta: {
|
112
111
|
api_version: {
|
113
112
|
version: string;
|
114
113
|
};
|
115
114
|
};
|
115
|
+
texts: string[];
|
116
116
|
embeddings: number[][];
|
117
117
|
}>;
|
118
118
|
export type CohereTextEmbeddingResponse = z.infer<typeof cohereTextEmbeddingResponseSchema>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { DeltaEvent } from "../../model-function/generate-text/DeltaEvent.js";
|
5
5
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
6
6
|
import { PromptFormat } from "../../prompt/PromptFormat.js";
|
@@ -72,8 +72,8 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
72
72
|
countPromptTokens(input: string): Promise<number>;
|
73
73
|
callAPI<RESPONSE>(prompt: string, options: {
|
74
74
|
responseFormat: CohereTextGenerationResponseFormatType<RESPONSE>;
|
75
|
-
} &
|
76
|
-
generateTextResponse(prompt: string, options?:
|
75
|
+
} & ModelFunctionOptions<CohereTextGenerationModelSettings>): Promise<RESPONSE>;
|
76
|
+
generateTextResponse(prompt: string, options?: ModelFunctionOptions<CohereTextGenerationModelSettings>): Promise<{
|
77
77
|
prompt: string;
|
78
78
|
id: string;
|
79
79
|
generations: {
|
@@ -88,7 +88,7 @@ export declare class CohereTextGenerationModel extends AbstractModel<CohereTextG
|
|
88
88
|
} | undefined;
|
89
89
|
}>;
|
90
90
|
extractText(response: CohereTextGenerationResponse): string;
|
91
|
-
generateDeltaStreamResponse(prompt: string, options?:
|
91
|
+
generateDeltaStreamResponse(prompt: string, options?: ModelFunctionOptions<CohereTextGenerationModelSettings>): Promise<AsyncIterable<DeltaEvent<CohereTextGenerationDelta>>>;
|
92
92
|
extractTextDelta(fullDelta: CohereTextGenerationDelta): string | undefined;
|
93
93
|
withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, string>): PromptFormatTextGenerationModel<INPUT_PROMPT, string, CohereTextGenerationResponse, CohereTextGenerationDelta, CohereTextGenerationModelSettings, this>;
|
94
94
|
withSettings(additionalSettings: Partial<CohereTextGenerationModelSettings>): this;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
3
|
-
import { Run } from "../../
|
3
|
+
import { Run } from "../../core/Run.js";
|
4
4
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
5
5
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
6
6
|
import { CohereTextGenerationModelType } from "./CohereTextGenerationModel.js";
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { SpeechSynthesisModel, SpeechSynthesisModelSettings } from "../../model-function/synthesize-speech/SpeechSynthesisModel.js";
|
5
5
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
6
6
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
@@ -24,6 +24,6 @@ export declare class ElevenLabsSpeechSynthesisModel extends AbstractModel<Eleven
|
|
24
24
|
readonly modelName: null;
|
25
25
|
private get apiKey();
|
26
26
|
private callAPI;
|
27
|
-
generateSpeechResponse(text: string, options?:
|
27
|
+
generateSpeechResponse(text: string, options?: ModelFunctionOptions<ElevenLabsSpeechSynthesisModelSettings> | undefined): Promise<Buffer>;
|
28
28
|
withSettings(additionalSettings: Partial<ElevenLabsSpeechSynthesisModelSettings>): this;
|
29
29
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../../model-function/embed-text/TextEmbeddingModel.js";
|
5
5
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
6
6
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
@@ -46,9 +46,9 @@ export declare class HuggingFaceTextEmbeddingModel extends AbstractModel<Hugging
|
|
46
46
|
readonly embeddingDimensions: number | undefined;
|
47
47
|
readonly tokenizer: undefined;
|
48
48
|
private get apiKey();
|
49
|
-
callAPI(texts: Array<string>, options?:
|
49
|
+
callAPI(texts: Array<string>, options?: ModelFunctionOptions<HuggingFaceTextEmbeddingModelSettings>): Promise<HuggingFaceTextEmbeddingResponse>;
|
50
50
|
readonly countPromptTokens: undefined;
|
51
|
-
generateEmbeddingResponse(texts: string[], options?:
|
51
|
+
generateEmbeddingResponse(texts: string[], options?: ModelFunctionOptions<HuggingFaceTextEmbeddingModelSettings>): Promise<number[][]>;
|
52
52
|
extractEmbeddings(response: HuggingFaceTextEmbeddingResponse): number[][];
|
53
53
|
withSettings(additionalSettings: Partial<HuggingFaceTextEmbeddingModelSettings>): this;
|
54
54
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import z from "zod";
|
2
2
|
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
|
-
import {
|
3
|
+
import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
|
4
4
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
5
5
|
import { RetryFunction } from "../../util/api/RetryFunction.js";
|
6
6
|
import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
|
@@ -49,9 +49,9 @@ export declare class HuggingFaceTextGenerationModel extends AbstractModel<Huggin
|
|
49
49
|
readonly contextWindowSize: undefined;
|
50
50
|
readonly tokenizer: undefined;
|
51
51
|
private get apiKey();
|
52
|
-
callAPI(prompt: string, options?:
|
52
|
+
callAPI(prompt: string, options?: ModelFunctionOptions<HuggingFaceTextGenerationModelSettings>): Promise<HuggingFaceTextGenerationResponse>;
|
53
53
|
readonly countPromptTokens: undefined;
|
54
|
-
generateTextResponse(prompt: string, options?:
|
54
|
+
generateTextResponse(prompt: string, options?: ModelFunctionOptions<HuggingFaceTextGenerationModelSettings>): Promise<{
|
55
55
|
generated_text: string;
|
56
56
|
}[]>;
|
57
57
|
extractText(response: HuggingFaceTextGenerationResponse): string;
|