modelfusion 0.40.1 → 0.41.1
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 +14 -7
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +3 -3
- package/core/FunctionEvent.d.ts +1 -1
- package/model-function/AsyncIterableResultPromise.d.ts +1 -1
- package/model-function/Delta.d.ts +8 -0
- package/model-function/ModelCallEvent.d.ts +1 -1
- package/model-function/ModelCallMetadata.d.ts +13 -0
- package/model-function/describe-image/ImageDescriptionEvent.d.ts +1 -1
- package/model-function/describe-image/ImageDescriptionModel.d.ts +6 -4
- package/model-function/describe-image/describeImage.cjs +7 -2
- package/model-function/describe-image/describeImage.d.ts +2 -2
- package/model-function/describe-image/describeImage.js +7 -2
- package/model-function/embed/EmbeddingEvent.d.ts +1 -1
- package/model-function/embed/EmbeddingModel.d.ts +6 -4
- package/model-function/embed/embed.cjs +16 -11
- package/model-function/embed/embed.d.ts +3 -3
- package/model-function/embed/embed.js +16 -11
- package/model-function/executeCall.cjs +26 -30
- package/model-function/executeCall.d.ts +19 -28
- package/model-function/executeCall.js +26 -30
- package/model-function/generate-image/ImageGenerationEvent.d.ts +1 -1
- package/model-function/generate-image/ImageGenerationModel.d.ts +6 -4
- package/model-function/generate-image/generateImage.cjs +7 -2
- package/model-function/generate-image/generateImage.d.ts +2 -2
- package/model-function/generate-image/generateImage.js +7 -2
- package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +6 -5
- package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +7 -5
- package/model-function/generate-structure/StructureFromTextGenerationModel.js +6 -5
- package/model-function/generate-structure/StructureGenerationEvent.d.ts +1 -1
- package/model-function/generate-structure/StructureGenerationModel.d.ts +15 -18
- package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +19 -17
- package/model-function/generate-structure/generateStructure.cjs +10 -8
- package/model-function/generate-structure/generateStructure.d.ts +2 -2
- package/model-function/generate-structure/generateStructure.js +10 -8
- package/model-function/generate-structure/generateStructureOrText.cjs +15 -8
- package/model-function/generate-structure/generateStructureOrText.d.ts +4 -4
- package/model-function/generate-structure/generateStructureOrText.js +15 -8
- package/model-function/generate-structure/streamStructure.cjs +4 -16
- package/model-function/generate-structure/streamStructure.d.ts +3 -7
- package/model-function/generate-structure/streamStructure.js +4 -16
- package/model-function/generate-text/TextGenerationEvent.d.ts +1 -1
- package/model-function/generate-text/TextGenerationModel.d.ts +18 -19
- package/model-function/generate-text/generateText.cjs +8 -9
- package/model-function/generate-text/generateText.d.ts +2 -2
- package/model-function/generate-text/generateText.js +8 -9
- package/model-function/generate-text/streamText.cjs +8 -21
- package/model-function/generate-text/streamText.d.ts +3 -7
- package/model-function/generate-text/streamText.js +8 -21
- package/model-function/index.cjs +2 -2
- package/model-function/index.d.ts +2 -2
- package/model-function/index.js +2 -2
- package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +1 -1
- package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +3 -3
- package/model-function/synthesize-speech/synthesizeSpeech.cjs +7 -2
- package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
- package/model-function/synthesize-speech/synthesizeSpeech.js +7 -2
- package/model-function/transcribe-speech/TranscriptionEvent.d.ts +1 -1
- package/model-function/transcribe-speech/TranscriptionModel.d.ts +6 -4
- package/model-function/transcribe-speech/transcribe.cjs +7 -2
- package/model-function/transcribe-speech/transcribe.d.ts +2 -2
- package/model-function/transcribe-speech/transcribe.js +7 -2
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +14 -18
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +11 -9
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +14 -18
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +13 -16
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +12 -10
- package/model-provider/cohere/CohereTextEmbeddingModel.js +13 -16
- package/model-provider/cohere/CohereTextGenerationModel.cjs +25 -28
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +24 -22
- package/model-provider/cohere/CohereTextGenerationModel.js +25 -28
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.cjs +10 -17
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
- package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.js +10 -17
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.cjs +13 -16
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.d.ts +9 -7
- package/model-provider/huggingface/HuggingFaceImageDescriptionModel.js +13 -16
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +19 -25
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +8 -6
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +19 -25
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +18 -24
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +10 -8
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +18 -24
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +13 -16
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +8 -6
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +13 -16
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +27 -33
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +62 -60
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +27 -33
- package/model-provider/lmnt/LmntSpeechSynthesisModel.cjs +7 -12
- package/model-provider/lmnt/LmntSpeechSynthesisModel.d.ts +2 -2
- package/model-provider/lmnt/LmntSpeechSynthesisModel.js +7 -12
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +8 -16
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +11 -11
- package/model-provider/openai/OpenAIImageGenerationModel.js +8 -16
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +18 -24
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +18 -16
- package/model-provider/openai/OpenAITextEmbeddingModel.js +18 -24
- package/model-provider/openai/OpenAITextGenerationModel.cjs +19 -26
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +31 -33
- package/model-provider/openai/OpenAITextGenerationModel.js +19 -26
- package/model-provider/openai/OpenAITranscriptionModel.cjs +19 -28
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +27 -7
- package/model-provider/openai/OpenAITranscriptionModel.js +19 -28
- package/model-provider/openai/chat/OpenAIChatModel.cjs +76 -85
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +127 -50
- package/model-provider/openai/chat/OpenAIChatModel.js +77 -86
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +4 -3
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +2 -2
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +2 -1
- package/model-provider/stability/StabilityImageGenerationModel.cjs +16 -21
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +13 -11
- package/model-provider/stability/StabilityImageGenerationModel.js +16 -21
- package/package.json +1 -1
- package/prompt/PromptFormatTextGenerationModel.cjs +2 -18
- package/prompt/PromptFormatTextGenerationModel.d.ts +14 -10
- package/prompt/PromptFormatTextGenerationModel.js +2 -18
- package/prompt/PromptFormatTextStreamingModel.cjs +31 -0
- package/prompt/PromptFormatTextStreamingModel.d.ts +13 -0
- package/prompt/PromptFormatTextStreamingModel.js +27 -0
- package/prompt/chat/trimChatPrompt.d.ts +2 -2
- package/prompt/index.cjs +1 -0
- package/prompt/index.d.ts +1 -0
- package/prompt/index.js +1 -0
- package/retriever/Retriever.d.ts +3 -6
- package/retriever/retrieve.cjs +2 -2
- package/retriever/retrieve.d.ts +3 -3
- package/retriever/retrieve.js +2 -2
- package/tool/executeTool.cjs +2 -2
- package/tool/executeTool.js +2 -2
- package/tool/useTool.cjs +2 -4
- package/tool/useTool.d.ts +2 -2
- package/tool/useTool.js +2 -4
- package/tool/useToolOrGenerateText.d.ts +2 -2
- package/util/SafeResult.d.ts +1 -1
- package/util/runSafe.cjs +1 -1
- package/util/runSafe.js +1 -1
- package/vector-index/VectorIndexRetriever.cjs +0 -7
- package/vector-index/VectorIndexRetriever.d.ts +5 -5
- package/vector-index/VectorIndexRetriever.js +0 -7
- package/vector-index/upsertIntoVectorIndex.d.ts +4 -4
- package/model-function/DeltaEvent.d.ts +0 -7
- package/model-function/ModelFunctionOptions.d.ts +0 -4
- /package/model-function/{DeltaEvent.cjs → Delta.cjs} +0 -0
- /package/model-function/{DeltaEvent.js → Delta.js} +0 -0
- /package/model-function/{ModelFunctionOptions.cjs → ModelCallMetadata.cjs} +0 -0
- /package/model-function/{ModelFunctionOptions.js → ModelCallMetadata.js} +0 -0
@@ -14,22 +14,21 @@ const executeCall_js_1 = require("../executeCall.cjs");
|
|
14
14
|
* "Write a short story about a robot learning to love:\n\n"
|
15
15
|
* );
|
16
16
|
*/
|
17
|
-
function generateText(
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
19
|
-
model, prompt, options) {
|
17
|
+
function generateText(model, prompt, options) {
|
20
18
|
return (0, executeCall_js_1.executeCall)({
|
21
19
|
functionType: "text-generation",
|
22
20
|
input: prompt,
|
23
21
|
model,
|
24
22
|
options,
|
25
|
-
generateResponse: (options) =>
|
26
|
-
|
23
|
+
generateResponse: async (options) => {
|
24
|
+
const result = await model.doGenerateText(prompt, options);
|
27
25
|
const shouldTrimWhitespace = model.settings.trimWhitespace ?? true;
|
28
|
-
return
|
29
|
-
|
30
|
-
:
|
26
|
+
return {
|
27
|
+
response: result.response,
|
28
|
+
extractedValue: shouldTrimWhitespace ? result.text.trim() : result.text,
|
29
|
+
usage: result.usage,
|
30
|
+
};
|
31
31
|
},
|
32
|
-
extractUsage: (result) => model.extractUsage?.(result),
|
33
32
|
});
|
34
33
|
}
|
35
34
|
exports.generateText = generateText;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { ModelFunctionPromise } from "../executeCall.js";
|
3
3
|
import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
|
4
4
|
/**
|
@@ -13,4 +13,4 @@ import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerati
|
|
13
13
|
* "Write a short story about a robot learning to love:\n\n"
|
14
14
|
* );
|
15
15
|
*/
|
16
|
-
export declare function generateText<PROMPT
|
16
|
+
export declare function generateText<PROMPT>(model: TextGenerationModel<PROMPT, TextGenerationModelSettings>, prompt: PROMPT, options?: FunctionOptions): ModelFunctionPromise<string>;
|
@@ -11,21 +11,20 @@ import { executeCall } from "../executeCall.js";
|
|
11
11
|
* "Write a short story about a robot learning to love:\n\n"
|
12
12
|
* );
|
13
13
|
*/
|
14
|
-
export function generateText(
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16
|
-
model, prompt, options) {
|
14
|
+
export function generateText(model, prompt, options) {
|
17
15
|
return executeCall({
|
18
16
|
functionType: "text-generation",
|
19
17
|
input: prompt,
|
20
18
|
model,
|
21
19
|
options,
|
22
|
-
generateResponse: (options) =>
|
23
|
-
|
20
|
+
generateResponse: async (options) => {
|
21
|
+
const result = await model.doGenerateText(prompt, options);
|
24
22
|
const shouldTrimWhitespace = model.settings.trimWhitespace ?? true;
|
25
|
-
return
|
26
|
-
|
27
|
-
:
|
23
|
+
return {
|
24
|
+
response: result.response,
|
25
|
+
extractedValue: shouldTrimWhitespace ? result.text.trim() : result.text,
|
26
|
+
usage: result.usage,
|
27
|
+
};
|
28
28
|
},
|
29
|
-
extractUsage: (result) => model.extractUsage?.(result),
|
30
29
|
});
|
31
30
|
}
|
@@ -15,21 +15,12 @@ function streamText(model, prompt, options) {
|
|
15
15
|
}
|
16
16
|
exports.streamText = streamText;
|
17
17
|
async function doStreamText(model, prompt, options) {
|
18
|
-
if (options?.settings != null) {
|
19
|
-
model = model.withSettings(options.settings);
|
20
|
-
options = {
|
21
|
-
functionId: options.functionId,
|
22
|
-
observers: options.observers,
|
23
|
-
run: options.run,
|
24
|
-
};
|
25
|
-
}
|
26
18
|
const run = options?.run;
|
27
|
-
const settings = model.settings;
|
28
19
|
const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
|
29
20
|
observers: [
|
30
21
|
...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
|
31
22
|
...(0, GlobalFunctionObservers_js_1.getGlobalFunctionObservers)(),
|
32
|
-
...(settings.observers ?? []),
|
23
|
+
...(model.settings.observers ?? []),
|
33
24
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
34
25
|
...(options?.observers ?? []),
|
35
26
|
],
|
@@ -54,11 +45,7 @@ async function doStreamText(model, prompt, options) {
|
|
54
45
|
...startMetadata,
|
55
46
|
});
|
56
47
|
const result = await (0, runSafe_js_1.runSafe)(async () => {
|
57
|
-
const deltaIterable = await model.
|
58
|
-
functionId: options?.functionId,
|
59
|
-
settings,
|
60
|
-
run,
|
61
|
-
});
|
48
|
+
const deltaIterable = await model.doStreamText(prompt, options);
|
62
49
|
return (async function* () {
|
63
50
|
let accumulatedText = "";
|
64
51
|
let lastFullDelta;
|
@@ -89,10 +76,10 @@ async function doStreamText(model, prompt, options) {
|
|
89
76
|
}
|
90
77
|
if (event?.type === "delta") {
|
91
78
|
lastFullDelta = event.fullDelta;
|
92
|
-
const
|
93
|
-
if (
|
94
|
-
accumulatedText +=
|
95
|
-
yield
|
79
|
+
const textDelta = event.valueDelta;
|
80
|
+
if (textDelta != null && textDelta.length > 0) {
|
81
|
+
accumulatedText += textDelta;
|
82
|
+
yield textDelta;
|
96
83
|
}
|
97
84
|
}
|
98
85
|
}
|
@@ -107,7 +94,7 @@ async function doStreamText(model, prompt, options) {
|
|
107
94
|
result: {
|
108
95
|
status: "success",
|
109
96
|
response: lastFullDelta,
|
110
|
-
|
97
|
+
value: accumulatedText,
|
111
98
|
},
|
112
99
|
});
|
113
100
|
})();
|
@@ -138,7 +125,7 @@ async function doStreamText(model, prompt, options) {
|
|
138
125
|
throw result.error;
|
139
126
|
}
|
140
127
|
return {
|
141
|
-
output: result.
|
128
|
+
output: result.value,
|
142
129
|
metadata: startMetadata,
|
143
130
|
};
|
144
131
|
}
|
@@ -1,8 +1,4 @@
|
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
1
2
|
import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
|
2
|
-
import {
|
3
|
-
|
4
|
-
import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
|
5
|
-
export declare function streamText<PROMPT, FULL_DELTA, SETTINGS extends TextGenerationModelSettings>(model: TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS> & {
|
6
|
-
generateDeltaStreamResponse: (prompt: PROMPT, options: ModelFunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
|
7
|
-
extractTextDelta: (fullDelta: FULL_DELTA) => string | undefined;
|
8
|
-
}, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): AsyncIterableResultPromise<string>;
|
3
|
+
import { TextStreamingModel } from "./TextGenerationModel.js";
|
4
|
+
export declare function streamText<PROMPT>(model: TextStreamingModel<PROMPT>, prompt: PROMPT, options?: FunctionOptions): AsyncIterableResultPromise<string>;
|
@@ -11,21 +11,12 @@ export function streamText(model, prompt, options) {
|
|
11
11
|
return new AsyncIterableResultPromise(doStreamText(model, prompt, options));
|
12
12
|
}
|
13
13
|
async function doStreamText(model, prompt, options) {
|
14
|
-
if (options?.settings != null) {
|
15
|
-
model = model.withSettings(options.settings);
|
16
|
-
options = {
|
17
|
-
functionId: options.functionId,
|
18
|
-
observers: options.observers,
|
19
|
-
run: options.run,
|
20
|
-
};
|
21
|
-
}
|
22
14
|
const run = options?.run;
|
23
|
-
const settings = model.settings;
|
24
15
|
const eventSource = new FunctionEventSource({
|
25
16
|
observers: [
|
26
17
|
...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
|
27
18
|
...getGlobalFunctionObservers(),
|
28
|
-
...(settings.observers ?? []),
|
19
|
+
...(model.settings.observers ?? []),
|
29
20
|
...(run?.functionObserver != null ? [run.functionObserver] : []),
|
30
21
|
...(options?.observers ?? []),
|
31
22
|
],
|
@@ -50,11 +41,7 @@ async function doStreamText(model, prompt, options) {
|
|
50
41
|
...startMetadata,
|
51
42
|
});
|
52
43
|
const result = await runSafe(async () => {
|
53
|
-
const deltaIterable = await model.
|
54
|
-
functionId: options?.functionId,
|
55
|
-
settings,
|
56
|
-
run,
|
57
|
-
});
|
44
|
+
const deltaIterable = await model.doStreamText(prompt, options);
|
58
45
|
return (async function* () {
|
59
46
|
let accumulatedText = "";
|
60
47
|
let lastFullDelta;
|
@@ -85,10 +72,10 @@ async function doStreamText(model, prompt, options) {
|
|
85
72
|
}
|
86
73
|
if (event?.type === "delta") {
|
87
74
|
lastFullDelta = event.fullDelta;
|
88
|
-
const
|
89
|
-
if (
|
90
|
-
accumulatedText +=
|
91
|
-
yield
|
75
|
+
const textDelta = event.valueDelta;
|
76
|
+
if (textDelta != null && textDelta.length > 0) {
|
77
|
+
accumulatedText += textDelta;
|
78
|
+
yield textDelta;
|
92
79
|
}
|
93
80
|
}
|
94
81
|
}
|
@@ -103,7 +90,7 @@ async function doStreamText(model, prompt, options) {
|
|
103
90
|
result: {
|
104
91
|
status: "success",
|
105
92
|
response: lastFullDelta,
|
106
|
-
|
93
|
+
value: accumulatedText,
|
107
94
|
},
|
108
95
|
});
|
109
96
|
})();
|
@@ -134,7 +121,7 @@ async function doStreamText(model, prompt, options) {
|
|
134
121
|
throw result.error;
|
135
122
|
}
|
136
123
|
return {
|
137
|
-
output: result.
|
124
|
+
output: result.value,
|
138
125
|
metadata: startMetadata,
|
139
126
|
};
|
140
127
|
}
|
package/model-function/index.cjs
CHANGED
@@ -14,10 +14,10 @@ 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("./
|
17
|
+
__exportStar(require("./Delta.cjs"), exports);
|
18
18
|
__exportStar(require("./Model.cjs"), exports);
|
19
19
|
__exportStar(require("./ModelCallEvent.cjs"), exports);
|
20
|
-
__exportStar(require("./
|
20
|
+
__exportStar(require("./ModelCallMetadata.cjs"), exports);
|
21
21
|
__exportStar(require("./ModelInformation.cjs"), exports);
|
22
22
|
__exportStar(require("./SuccessfulModelCall.cjs"), exports);
|
23
23
|
__exportStar(require("./describe-image/ImageDescriptionEvent.cjs"), exports);
|
@@ -1,7 +1,7 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./Delta.js";
|
2
2
|
export * from "./Model.js";
|
3
3
|
export * from "./ModelCallEvent.js";
|
4
|
-
export * from "./
|
4
|
+
export * from "./ModelCallMetadata.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./SuccessfulModelCall.js";
|
7
7
|
export * from "./describe-image/ImageDescriptionEvent.js";
|
package/model-function/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
export * from "./
|
1
|
+
export * from "./Delta.js";
|
2
2
|
export * from "./Model.js";
|
3
3
|
export * from "./ModelCallEvent.js";
|
4
|
-
export * from "./
|
4
|
+
export * from "./ModelCallMetadata.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./SuccessfulModelCall.js";
|
7
7
|
export * from "./describe-image/ImageDescriptionEvent.js";
|
@@ -1,11 +1,11 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import {
|
2
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
3
3
|
import { Model, ModelSettings } from "../Model.js";
|
4
4
|
export interface SpeechSynthesisModelSettings extends ModelSettings {
|
5
5
|
}
|
6
|
-
export interface SpeechSynthesisModel<SETTINGS extends SpeechSynthesisModelSettings> extends Model<SETTINGS> {
|
6
|
+
export interface SpeechSynthesisModel<SETTINGS extends SpeechSynthesisModelSettings = SpeechSynthesisModelSettings> 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?: FunctionOptions) => PromiseLike<Buffer>;
|
11
11
|
}
|
@@ -11,8 +11,13 @@ function synthesizeSpeech(model, text, options) {
|
|
11
11
|
input: text,
|
12
12
|
model,
|
13
13
|
options,
|
14
|
-
generateResponse: (options) =>
|
15
|
-
|
14
|
+
generateResponse: async (options) => {
|
15
|
+
const response = await model.generateSpeechResponse(text, options);
|
16
|
+
return {
|
17
|
+
response,
|
18
|
+
extractedValue: response,
|
19
|
+
};
|
20
|
+
},
|
16
21
|
});
|
17
22
|
}
|
18
23
|
exports.synthesizeSpeech = synthesizeSpeech;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import {
|
2
|
+
import { FunctionOptions } from "../../core/FunctionOptions.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
|
8
|
+
export declare function synthesizeSpeech(model: SpeechSynthesisModel<SpeechSynthesisModelSettings>, text: string, options?: FunctionOptions): ModelFunctionPromise<Buffer>;
|
@@ -8,7 +8,12 @@ export function synthesizeSpeech(model, text, options) {
|
|
8
8
|
input: text,
|
9
9
|
model,
|
10
10
|
options,
|
11
|
-
generateResponse: (options) =>
|
12
|
-
|
11
|
+
generateResponse: async (options) => {
|
12
|
+
const response = await model.generateSpeechResponse(text, options);
|
13
|
+
return {
|
14
|
+
response,
|
15
|
+
extractedValue: response,
|
16
|
+
};
|
17
|
+
},
|
13
18
|
});
|
14
19
|
}
|
@@ -1,8 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
2
|
import { Model, ModelSettings } from "../Model.js";
|
3
3
|
export interface TranscriptionModelSettings extends ModelSettings {
|
4
4
|
}
|
5
|
-
export interface TranscriptionModel<DATA,
|
6
|
-
|
7
|
-
|
5
|
+
export interface TranscriptionModel<DATA, SETTINGS extends TranscriptionModelSettings = TranscriptionModelSettings> extends Model<SETTINGS> {
|
6
|
+
doTranscribe: (data: DATA, options?: FunctionOptions) => PromiseLike<{
|
7
|
+
response: unknown;
|
8
|
+
transcription: string;
|
9
|
+
}>;
|
8
10
|
}
|
@@ -22,8 +22,13 @@ function transcribe(model, data, options) {
|
|
22
22
|
input: data,
|
23
23
|
model,
|
24
24
|
options,
|
25
|
-
generateResponse: (options) =>
|
26
|
-
|
25
|
+
generateResponse: async (options) => {
|
26
|
+
const result = await model.doTranscribe(data, options);
|
27
|
+
return {
|
28
|
+
response: result.response,
|
29
|
+
extractedValue: result.transcription,
|
30
|
+
};
|
31
|
+
},
|
27
32
|
});
|
28
33
|
}
|
29
34
|
exports.transcribe = transcribe;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.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
|
18
|
+
export declare function transcribe<DATA>(model: TranscriptionModel<DATA, TranscriptionModelSettings>, data: DATA, options?: FunctionOptions): ModelFunctionPromise<string>;
|
@@ -19,7 +19,12 @@ export function transcribe(model, data, options) {
|
|
19
19
|
input: data,
|
20
20
|
model,
|
21
21
|
options,
|
22
|
-
generateResponse: (options) =>
|
23
|
-
|
22
|
+
generateResponse: async (options) => {
|
23
|
+
const result = await model.doTranscribe(data, options);
|
24
|
+
return {
|
25
|
+
response: result.response,
|
26
|
+
extractedValue: result.transcription,
|
27
|
+
};
|
28
|
+
},
|
24
29
|
});
|
25
30
|
}
|
@@ -2,9 +2,9 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.Automatic1111ImageGenerationModel = void 0;
|
4
4
|
const zod_1 = require("zod");
|
5
|
-
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
6
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
7
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
7
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
8
8
|
const Automatic1111ApiConfiguration_js_1 = require("./Automatic1111ApiConfiguration.cjs");
|
9
9
|
const Automatic1111Error_js_1 = require("./Automatic1111Error.cjs");
|
10
10
|
/**
|
@@ -26,19 +26,14 @@ class Automatic1111ImageGenerationModel extends AbstractModel_js_1.AbstractModel
|
|
26
26
|
return this.settings.model;
|
27
27
|
}
|
28
28
|
async callAPI(input, options) {
|
29
|
-
const run = options?.run;
|
30
|
-
const settings = options?.settings;
|
31
|
-
const callSettings = {
|
32
|
-
...this.settings,
|
33
|
-
...settings,
|
34
|
-
abortSignal: run?.abortSignal,
|
35
|
-
engineId: this.settings.model,
|
36
|
-
prompt: input.prompt,
|
37
|
-
};
|
38
29
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
39
|
-
retry:
|
40
|
-
throttle:
|
41
|
-
call: async () => callAutomatic1111ImageGenerationAPI(
|
30
|
+
retry: this.settings.api?.retry,
|
31
|
+
throttle: this.settings.api?.throttle,
|
32
|
+
call: async () => callAutomatic1111ImageGenerationAPI({
|
33
|
+
...this.settings,
|
34
|
+
abortSignal: options?.run?.abortSignal,
|
35
|
+
prompt: input.prompt,
|
36
|
+
}),
|
42
37
|
});
|
43
38
|
}
|
44
39
|
get settingsForEvent() {
|
@@ -49,11 +44,12 @@ class Automatic1111ImageGenerationModel extends AbstractModel_js_1.AbstractModel
|
|
49
44
|
steps: this.settings.steps,
|
50
45
|
};
|
51
46
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
async doGenerateImage(prompt, options) {
|
48
|
+
const response = await this.callAPI(prompt, options);
|
49
|
+
return {
|
50
|
+
response,
|
51
|
+
base64Image: response.images[0],
|
52
|
+
};
|
57
53
|
}
|
58
54
|
withSettings(additionalSettings) {
|
59
55
|
return new Automatic1111ImageGenerationModel(Object.assign({}, this.settings, additionalSettings));
|
@@ -1,25 +1,27 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
-
import {
|
2
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
3
3
|
import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
|
4
|
-
import {
|
4
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
5
|
import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js";
|
6
6
|
/**
|
7
7
|
* Create an image generation model that calls the AUTOMATIC1111 Stable Diffusion Web UI API.
|
8
8
|
*
|
9
9
|
* @see https://github.com/AUTOMATIC1111/stable-diffusion-webui
|
10
10
|
*/
|
11
|
-
export declare class Automatic1111ImageGenerationModel extends AbstractModel<Automatic1111ImageGenerationModelSettings> implements ImageGenerationModel<A111ImageGenerationPrompt,
|
11
|
+
export declare class Automatic1111ImageGenerationModel extends AbstractModel<Automatic1111ImageGenerationModelSettings> implements ImageGenerationModel<A111ImageGenerationPrompt, Automatic1111ImageGenerationModelSettings> {
|
12
12
|
constructor(settings: Automatic1111ImageGenerationModelSettings);
|
13
13
|
readonly provider: "Automatic1111";
|
14
14
|
get modelName(): string;
|
15
|
-
callAPI(input: A111ImageGenerationPrompt, options?:
|
15
|
+
callAPI(input: A111ImageGenerationPrompt, options?: FunctionOptions): Promise<Automatic1111ImageGenerationResponse>;
|
16
16
|
get settingsForEvent(): Partial<Automatic1111ImageGenerationModelSettings>;
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
doGenerateImage(prompt: A111ImageGenerationPrompt, options?: FunctionOptions): Promise<{
|
18
|
+
response: {
|
19
|
+
images: string[];
|
20
|
+
parameters: {};
|
21
|
+
info: string;
|
22
|
+
};
|
23
|
+
base64Image: string;
|
21
24
|
}>;
|
22
|
-
extractBase64Image(response: Automatic1111ImageGenerationResponse): string;
|
23
25
|
withSettings(additionalSettings: Automatic1111ImageGenerationModelSettings): this;
|
24
26
|
}
|
25
27
|
export interface Automatic1111ImageGenerationModelSettings extends ImageGenerationModelSettings {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { z } from "zod";
|
2
|
-
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
3
2
|
import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
|
4
3
|
import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
|
4
|
+
import { AbstractModel } from "../../model-function/AbstractModel.js";
|
5
5
|
import { Automatic1111ApiConfiguration } from "./Automatic1111ApiConfiguration.js";
|
6
6
|
import { failedAutomatic1111CallResponseHandler } from "./Automatic1111Error.js";
|
7
7
|
/**
|
@@ -23,19 +23,14 @@ export class Automatic1111ImageGenerationModel extends AbstractModel {
|
|
23
23
|
return this.settings.model;
|
24
24
|
}
|
25
25
|
async callAPI(input, options) {
|
26
|
-
const run = options?.run;
|
27
|
-
const settings = options?.settings;
|
28
|
-
const callSettings = {
|
29
|
-
...this.settings,
|
30
|
-
...settings,
|
31
|
-
abortSignal: run?.abortSignal,
|
32
|
-
engineId: this.settings.model,
|
33
|
-
prompt: input.prompt,
|
34
|
-
};
|
35
26
|
return callWithRetryAndThrottle({
|
36
|
-
retry:
|
37
|
-
throttle:
|
38
|
-
call: async () => callAutomatic1111ImageGenerationAPI(
|
27
|
+
retry: this.settings.api?.retry,
|
28
|
+
throttle: this.settings.api?.throttle,
|
29
|
+
call: async () => callAutomatic1111ImageGenerationAPI({
|
30
|
+
...this.settings,
|
31
|
+
abortSignal: options?.run?.abortSignal,
|
32
|
+
prompt: input.prompt,
|
33
|
+
}),
|
39
34
|
});
|
40
35
|
}
|
41
36
|
get settingsForEvent() {
|
@@ -46,11 +41,12 @@ export class Automatic1111ImageGenerationModel extends AbstractModel {
|
|
46
41
|
steps: this.settings.steps,
|
47
42
|
};
|
48
43
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
async doGenerateImage(prompt, options) {
|
45
|
+
const response = await this.callAPI(prompt, options);
|
46
|
+
return {
|
47
|
+
response,
|
48
|
+
base64Image: response.images[0],
|
49
|
+
};
|
54
50
|
}
|
55
51
|
withSettings(additionalSettings) {
|
56
52
|
return new Automatic1111ImageGenerationModel(Object.assign({}, this.settings, additionalSettings));
|
@@ -97,18 +97,14 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
97
97
|
if (texts.length > this.maxValuesPerCall) {
|
98
98
|
throw new Error(`The Cohere embedding API only supports ${this.maxValuesPerCall} texts per API call.`);
|
99
99
|
}
|
100
|
-
const run = options?.run;
|
101
|
-
const settings = options?.settings;
|
102
|
-
const callSettings = {
|
103
|
-
...this.settings,
|
104
|
-
...settings,
|
105
|
-
abortSignal: run?.abortSignal,
|
106
|
-
texts,
|
107
|
-
};
|
108
100
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
109
|
-
retry:
|
110
|
-
throttle:
|
111
|
-
call: async () => callCohereEmbeddingAPI(
|
101
|
+
retry: this.settings.api?.retry,
|
102
|
+
throttle: this.settings.api?.throttle,
|
103
|
+
call: async () => callCohereEmbeddingAPI({
|
104
|
+
...this.settings,
|
105
|
+
abortSignal: options?.run?.abortSignal,
|
106
|
+
texts,
|
107
|
+
}),
|
112
108
|
});
|
113
109
|
}
|
114
110
|
get settingsForEvent() {
|
@@ -116,11 +112,12 @@ class CohereTextEmbeddingModel extends AbstractModel_js_1.AbstractModel {
|
|
116
112
|
truncate: this.settings.truncate,
|
117
113
|
};
|
118
114
|
}
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
async doEmbedValues(texts, options) {
|
116
|
+
const response = await this.callAPI(texts, options);
|
117
|
+
return {
|
118
|
+
response,
|
119
|
+
embeddings: response.embeddings,
|
120
|
+
};
|
124
121
|
}
|
125
122
|
withSettings(additionalSettings) {
|
126
123
|
return new CohereTextEmbeddingModel(Object.assign({}, this.settings, additionalSettings));
|