modelfusion 0.53.1 → 0.54.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 +2 -2
- package/browser/convertAudioChunksToBase64.cjs +8 -0
- package/browser/convertAudioChunksToBase64.d.ts +4 -0
- package/browser/convertAudioChunksToBase64.js +4 -0
- package/browser/convertBlobToBase64.cjs +23 -0
- package/browser/convertBlobToBase64.d.ts +1 -0
- package/browser/convertBlobToBase64.js +19 -0
- package/{ui → browser}/index.cjs +5 -0
- package/browser/index.d.ts +6 -0
- package/browser/index.js +6 -0
- package/browser/invokeFlow.cjs +23 -0
- package/browser/invokeFlow.d.ts +8 -0
- package/browser/invokeFlow.js +19 -0
- package/{event-source → browser}/readEventSource.cjs +8 -3
- package/{event-source → browser}/readEventSource.d.ts +3 -1
- package/{event-source → browser}/readEventSource.js +8 -3
- package/{event-source → browser}/readEventSourceStream.cjs +1 -1
- package/{event-source → browser}/readEventSourceStream.js +1 -1
- package/core/FunctionOptions.d.ts +4 -3
- package/event-source/createEventSourceStream.cjs +7 -3
- package/event-source/createEventSourceStream.js +7 -3
- package/event-source/index.cjs +0 -2
- package/event-source/index.d.ts +0 -2
- package/event-source/index.js +0 -2
- package/index.cjs +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- 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/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 +13 -4
- package/server/fastify/AssetStorage.cjs +2 -0
- package/server/fastify/AssetStorage.d.ts +17 -0
- package/server/fastify/AssetStorage.js +1 -0
- package/server/fastify/DefaultFlow.cjs +22 -0
- package/server/fastify/DefaultFlow.d.ts +16 -0
- package/server/fastify/DefaultFlow.js +18 -0
- package/server/fastify/FileSystemAssetStorage.cjs +60 -0
- package/server/fastify/FileSystemAssetStorage.d.ts +19 -0
- package/server/fastify/FileSystemAssetStorage.js +56 -0
- package/server/fastify/FileSystemLogger.cjs +48 -0
- package/server/fastify/FileSystemLogger.d.ts +18 -0
- package/server/fastify/FileSystemLogger.js +44 -0
- package/server/fastify/Flow.cjs +2 -0
- package/server/fastify/Flow.d.ts +9 -0
- package/server/fastify/Flow.js +1 -0
- package/server/fastify/FlowRun.cjs +71 -0
- package/server/fastify/FlowRun.d.ts +28 -0
- package/server/fastify/FlowRun.js +67 -0
- package/server/fastify/FlowSchema.cjs +2 -0
- package/server/fastify/FlowSchema.d.ts +5 -0
- package/server/fastify/FlowSchema.js +1 -0
- package/server/fastify/Logger.cjs +2 -0
- package/server/fastify/Logger.d.ts +13 -0
- package/server/fastify/Logger.js +1 -0
- package/server/fastify/PathProvider.cjs +34 -0
- package/server/fastify/PathProvider.d.ts +12 -0
- package/server/fastify/PathProvider.js +30 -0
- package/server/fastify/index.cjs +24 -0
- package/server/fastify/index.d.ts +8 -0
- package/server/fastify/index.js +8 -0
- package/server/fastify/modelFusionFlowPlugin.cjs +102 -0
- package/server/fastify/modelFusionFlowPlugin.d.ts +12 -0
- package/server/fastify/modelFusionFlowPlugin.js +98 -0
- package/ui/index.d.ts +0 -1
- package/ui/index.js +0 -1
- /package/{ui → browser}/MediaSourceAppender.cjs +0 -0
- /package/{ui → browser}/MediaSourceAppender.d.ts +0 -0
- /package/{ui → browser}/MediaSourceAppender.js +0 -0
- /package/{event-source → browser}/readEventSourceStream.d.ts +0 -0
package/README.md
CHANGED
@@ -623,9 +623,9 @@ Create an 19th century painting image for your input.
|
|
623
623
|
|
624
624
|
Record audio with push-to-talk and transcribe it using Whisper, implemented as a Next.js app. The app shows a list of the transcriptions.
|
625
625
|
|
626
|
-
### [Speech Streaming (Vite
|
626
|
+
### [Duplex Speech Streaming (using Vite/React & ModelFusion Server/Fastify)](https://github.com/lgrammel/modelfusion/tree/main/examples/speech-streaming-vite-react-fastify)
|
627
627
|
|
628
|
-
> _Speech Streaming_, _OpenAI_, _Elevenlabs_ _streaming_, _Vite_, _Fastify_
|
628
|
+
> _Speech Streaming_, _OpenAI_, _Elevenlabs_ _streaming_, _Vite_, _Fastify_, _ModelFusion Server_
|
629
629
|
|
630
630
|
Given a prompt, the server returns both a text and a speech stream response.
|
631
631
|
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.convertAudioChunksToBase64 = void 0;
|
4
|
+
const convertBlobToBase64_js_1 = require("./convertBlobToBase64.cjs");
|
5
|
+
function convertAudioChunksToBase64({ audioChunks, mimeType, }) {
|
6
|
+
return (0, convertBlobToBase64_js_1.convertBlobToBase64)(new Blob(audioChunks, { type: mimeType }));
|
7
|
+
}
|
8
|
+
exports.convertAudioChunksToBase64 = convertAudioChunksToBase64;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.convertBlobToBase64 = void 0;
|
4
|
+
async function convertBlobToBase64(blob) {
|
5
|
+
return new Promise((resolve, reject) => {
|
6
|
+
const reader = new FileReader();
|
7
|
+
reader.onloadend = () => {
|
8
|
+
if (reader.result) {
|
9
|
+
const base64String = btoa(new Uint8Array(reader.result).reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
10
|
+
resolve(base64String);
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
reject(new Error("Failed to read blob."));
|
14
|
+
}
|
15
|
+
};
|
16
|
+
reader.onerror = () => {
|
17
|
+
reader.abort();
|
18
|
+
reject(new DOMException("Problem parsing input blob."));
|
19
|
+
};
|
20
|
+
reader.readAsArrayBuffer(blob);
|
21
|
+
});
|
22
|
+
}
|
23
|
+
exports.convertBlobToBase64 = convertBlobToBase64;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function convertBlobToBase64(blob: Blob): Promise<string>;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
export async function convertBlobToBase64(blob) {
|
2
|
+
return new Promise((resolve, reject) => {
|
3
|
+
const reader = new FileReader();
|
4
|
+
reader.onloadend = () => {
|
5
|
+
if (reader.result) {
|
6
|
+
const base64String = btoa(new Uint8Array(reader.result).reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
7
|
+
resolve(base64String);
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
reject(new Error("Failed to read blob."));
|
11
|
+
}
|
12
|
+
};
|
13
|
+
reader.onerror = () => {
|
14
|
+
reader.abort();
|
15
|
+
reject(new DOMException("Problem parsing input blob."));
|
16
|
+
};
|
17
|
+
reader.readAsArrayBuffer(blob);
|
18
|
+
});
|
19
|
+
}
|
package/{ui → browser}/index.cjs
RENAMED
@@ -15,3 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./MediaSourceAppender.cjs"), exports);
|
18
|
+
__exportStar(require("./convertAudioChunksToBase64.cjs"), exports);
|
19
|
+
__exportStar(require("./convertBlobToBase64.cjs"), exports);
|
20
|
+
__exportStar(require("./invokeFlow.cjs"), exports);
|
21
|
+
__exportStar(require("./readEventSource.cjs"), exports);
|
22
|
+
__exportStar(require("./readEventSourceStream.cjs"), exports);
|
package/browser/index.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.invokeFlow = void 0;
|
4
|
+
const ZodSchema_1 = require("../core/structure/ZodSchema");
|
5
|
+
const readEventSource_1 = require("./readEventSource");
|
6
|
+
async function invokeFlow({ url, input, schema, onEvent, onStop, }) {
|
7
|
+
const response = await fetch(url, {
|
8
|
+
method: "POST",
|
9
|
+
headers: { "Content-Type": "application/json" },
|
10
|
+
body: JSON.stringify(input),
|
11
|
+
});
|
12
|
+
const eventSourceUrl = (await response.json()).url;
|
13
|
+
(0, readEventSource_1.readEventSource)({
|
14
|
+
url: eventSourceUrl,
|
15
|
+
schema: new ZodSchema_1.ZodSchema(schema.events),
|
16
|
+
isStopEvent(event) {
|
17
|
+
return event.data === "[DONE]";
|
18
|
+
},
|
19
|
+
onEvent,
|
20
|
+
onStop,
|
21
|
+
});
|
22
|
+
}
|
23
|
+
exports.invokeFlow = invokeFlow;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { FlowSchema } from "../server/fastify/FlowSchema";
|
2
|
+
export declare function invokeFlow<INPUT, EVENT>({ url, input, schema, onEvent, onStop, }: {
|
3
|
+
url: string;
|
4
|
+
input: INPUT;
|
5
|
+
schema: FlowSchema<INPUT, EVENT>;
|
6
|
+
onEvent: (event: EVENT, eventSource: EventSource) => void;
|
7
|
+
onStop?: (eventSource: EventSource) => void;
|
8
|
+
}): Promise<void>;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { ZodSchema } from "../core/structure/ZodSchema";
|
2
|
+
import { readEventSource } from "./readEventSource";
|
3
|
+
export async function invokeFlow({ url, input, schema, onEvent, onStop, }) {
|
4
|
+
const response = await fetch(url, {
|
5
|
+
method: "POST",
|
6
|
+
headers: { "Content-Type": "application/json" },
|
7
|
+
body: JSON.stringify(input),
|
8
|
+
});
|
9
|
+
const eventSourceUrl = (await response.json()).url;
|
10
|
+
readEventSource({
|
11
|
+
url: eventSourceUrl,
|
12
|
+
schema: new ZodSchema(schema.events),
|
13
|
+
isStopEvent(event) {
|
14
|
+
return event.data === "[DONE]";
|
15
|
+
},
|
16
|
+
onEvent,
|
17
|
+
onStop,
|
18
|
+
});
|
19
|
+
}
|
@@ -2,11 +2,16 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.readEventSource = void 0;
|
4
4
|
const parseJSON_js_1 = require("../util/parseJSON.cjs");
|
5
|
-
function readEventSource({ url, schema, onEvent, onError = console.error, }) {
|
5
|
+
function readEventSource({ url, schema, onEvent, onError = console.error, onStop, isStopEvent, }) {
|
6
6
|
const eventSource = new EventSource(url);
|
7
|
-
eventSource.onmessage = (
|
7
|
+
eventSource.onmessage = (event) => {
|
8
8
|
try {
|
9
|
-
|
9
|
+
if (isStopEvent?.(event)) {
|
10
|
+
eventSource.close();
|
11
|
+
onStop?.(eventSource);
|
12
|
+
return;
|
13
|
+
}
|
14
|
+
const parseResult = (0, parseJSON_js_1.safeParseJsonWithSchema)(event.data, schema);
|
10
15
|
if (!parseResult.success) {
|
11
16
|
onError(parseResult.error, eventSource);
|
12
17
|
return;
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { Schema } from "../core/structure/Schema.js";
|
2
|
-
export declare function readEventSource<T>({ url, schema, onEvent, onError, }: {
|
2
|
+
export declare function readEventSource<T>({ url, schema, onEvent, onError, onStop, isStopEvent, }: {
|
3
3
|
url: string;
|
4
4
|
schema: Schema<T>;
|
5
5
|
onEvent: (event: T, eventSource: EventSource) => void;
|
6
6
|
onError?: (error: unknown, eventSource: EventSource) => void;
|
7
|
+
onStop?: (eventSource: EventSource) => void;
|
8
|
+
isStopEvent?: (event: MessageEvent<unknown>) => boolean;
|
7
9
|
}): void;
|
@@ -1,9 +1,14 @@
|
|
1
1
|
import { safeParseJsonWithSchema } from "../util/parseJSON.js";
|
2
|
-
export function readEventSource({ url, schema, onEvent, onError = console.error, }) {
|
2
|
+
export function readEventSource({ url, schema, onEvent, onError = console.error, onStop, isStopEvent, }) {
|
3
3
|
const eventSource = new EventSource(url);
|
4
|
-
eventSource.onmessage = (
|
4
|
+
eventSource.onmessage = (event) => {
|
5
5
|
try {
|
6
|
-
|
6
|
+
if (isStopEvent?.(event)) {
|
7
|
+
eventSource.close();
|
8
|
+
onStop?.(eventSource);
|
9
|
+
return;
|
10
|
+
}
|
11
|
+
const parseResult = safeParseJsonWithSchema(event.data, schema);
|
7
12
|
if (!parseResult.success) {
|
8
13
|
onError(parseResult.error, eventSource);
|
9
14
|
return;
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readEventSourceStream = void 0;
|
4
4
|
const parseJSON_js_1 = require("../util/parseJSON.cjs");
|
5
5
|
const AsyncQueue_js_1 = require("../util/AsyncQueue.cjs");
|
6
|
-
const parseEventSourceStream_js_1 = require("
|
6
|
+
const parseEventSourceStream_js_1 = require("../event-source/parseEventSourceStream.cjs");
|
7
7
|
function readEventSourceStream({ stream, schema, errorHandler, }) {
|
8
8
|
const queue = new AsyncQueue_js_1.AsyncQueue();
|
9
9
|
// run async (no await on purpose):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { safeParseJsonWithSchema } from "../util/parseJSON.js";
|
2
2
|
import { AsyncQueue } from "../util/AsyncQueue.js";
|
3
|
-
import { parseEventSourceStream } from "
|
3
|
+
import { parseEventSourceStream } from "../event-source/parseEventSourceStream.js";
|
4
4
|
export function readEventSourceStream({ stream, schema, errorHandler, }) {
|
5
5
|
const queue = new AsyncQueue();
|
6
6
|
// run async (no await on purpose):
|
@@ -5,7 +5,7 @@ import { FunctionObserver } from "./FunctionObserver.js";
|
|
5
5
|
*/
|
6
6
|
export type FunctionOptions = {
|
7
7
|
/**
|
8
|
-
* Optional function identifier
|
8
|
+
* Optional function identifier. Used in events and logging.
|
9
9
|
*/
|
10
10
|
functionId?: string;
|
11
11
|
/**
|
@@ -18,11 +18,12 @@ export type FunctionOptions = {
|
|
18
18
|
*/
|
19
19
|
observers?: Array<FunctionObserver>;
|
20
20
|
/**
|
21
|
-
* Optional run as part of which this function is called.
|
21
|
+
* Optional run as part of which this function is called. Used in events and logging.
|
22
|
+
* Run callbacks are invoked when it is provided.
|
22
23
|
*/
|
23
24
|
run?: Run;
|
24
25
|
/**
|
25
|
-
* Unique identifier of the call id of the parent function.
|
26
|
+
* Unique identifier of the call id of the parent function. Used in events and logging.
|
26
27
|
*/
|
27
28
|
parentCallId?: string | undefined;
|
28
29
|
};
|
@@ -5,10 +5,14 @@ const textEncoder = new TextEncoder();
|
|
5
5
|
function createEventSourceStream(events) {
|
6
6
|
return new ReadableStream({
|
7
7
|
async start(controller) {
|
8
|
-
|
9
|
-
|
8
|
+
try {
|
9
|
+
for await (const event of events) {
|
10
|
+
controller.enqueue(textEncoder.encode(`data: ${JSON.stringify(event)}\n\n`));
|
11
|
+
}
|
12
|
+
}
|
13
|
+
finally {
|
14
|
+
controller.close();
|
10
15
|
}
|
11
|
-
controller.close();
|
12
16
|
},
|
13
17
|
});
|
14
18
|
}
|
@@ -2,10 +2,14 @@ const textEncoder = new TextEncoder();
|
|
2
2
|
export function createEventSourceStream(events) {
|
3
3
|
return new ReadableStream({
|
4
4
|
async start(controller) {
|
5
|
-
|
6
|
-
|
5
|
+
try {
|
6
|
+
for await (const event of events) {
|
7
|
+
controller.enqueue(textEncoder.encode(`data: ${JSON.stringify(event)}\n\n`));
|
8
|
+
}
|
9
|
+
}
|
10
|
+
finally {
|
11
|
+
controller.close();
|
7
12
|
}
|
8
|
-
controller.close();
|
9
13
|
},
|
10
14
|
});
|
11
15
|
}
|
package/event-source/index.cjs
CHANGED
@@ -15,5 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./createEventSourceStream.cjs"), exports);
|
18
|
-
__exportStar(require("./readEventSource.cjs"), exports);
|
19
|
-
__exportStar(require("./readEventSourceStream.cjs"), exports);
|
package/event-source/index.d.ts
CHANGED
package/event-source/index.js
CHANGED
package/index.cjs
CHANGED
@@ -25,6 +25,5 @@ __exportStar(require("./observability/index.cjs"), exports);
|
|
25
25
|
__exportStar(require("./retriever/index.cjs"), exports);
|
26
26
|
__exportStar(require("./text-chunk/index.cjs"), exports);
|
27
27
|
__exportStar(require("./tool/index.cjs"), exports);
|
28
|
-
__exportStar(require("./ui/index.cjs"), exports);
|
29
28
|
__exportStar(require("./util/index.cjs"), exports);
|
30
29
|
__exportStar(require("./vector-index/index.cjs"), exports);
|
package/index.d.ts
CHANGED
@@ -9,6 +9,5 @@ export * from "./observability/index.js";
|
|
9
9
|
export * from "./retriever/index.js";
|
10
10
|
export * from "./text-chunk/index.js";
|
11
11
|
export * from "./tool/index.js";
|
12
|
-
export * from "./ui/index.js";
|
13
12
|
export * from "./util/index.js";
|
14
13
|
export * from "./vector-index/index.js";
|
package/index.js
CHANGED
@@ -9,6 +9,5 @@ export * from "./observability/index.js";
|
|
9
9
|
export * from "./retriever/index.js";
|
10
10
|
export * from "./text-chunk/index.js";
|
11
11
|
export * from "./tool/index.js";
|
12
|
-
export * from "./ui/index.js";
|
13
12
|
export * from "./util/index.js";
|
14
13
|
export * from "./vector-index/index.js";
|
@@ -6,6 +6,8 @@ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
|
|
6
6
|
/**
|
7
7
|
* Generate embeddings for multiple values.
|
8
8
|
*
|
9
|
+
* @see https://modelfusion.dev/guide/function/embed
|
10
|
+
*
|
9
11
|
* @example
|
10
12
|
* const embeddings = await embedMany(
|
11
13
|
* new OpenAITextEmbeddingModel(...),
|
@@ -14,6 +16,12 @@ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
|
|
14
16
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
15
17
|
* ]
|
16
18
|
* );
|
19
|
+
*
|
20
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating embeddings.
|
21
|
+
* @param {VALUE[]} values - The values to generate embeddings for.
|
22
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
23
|
+
*
|
24
|
+
* @returns {ModelFunctionPromise<Vector[]>} - A promise that resolves to an array of vectors representing the embeddings.
|
17
25
|
*/
|
18
26
|
function embedMany(model, values, options) {
|
19
27
|
return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
|
@@ -50,11 +58,19 @@ exports.embedMany = embedMany;
|
|
50
58
|
/**
|
51
59
|
* Generate an embedding for a single value.
|
52
60
|
*
|
61
|
+
* @see https://modelfusion.dev/guide/function/embed
|
62
|
+
*
|
53
63
|
* @example
|
54
64
|
* const embedding = await embed(
|
55
65
|
* new OpenAITextEmbeddingModel(...),
|
56
66
|
* "At first, Nox didn't know what to do with the pup."
|
57
67
|
* );
|
68
|
+
*
|
69
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating the embedding.
|
70
|
+
* @param {VALUE} value - The value to generate an embedding for.
|
71
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
72
|
+
*
|
73
|
+
* @returns {ModelFunctionPromise<Vector>} - A promise that resolves to a vector representing the embedding.
|
58
74
|
*/
|
59
75
|
function embed(model, value, options) {
|
60
76
|
return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
|
@@ -5,6 +5,8 @@ import { EmbeddingModel, EmbeddingModelSettings } from "./EmbeddingModel.js";
|
|
5
5
|
/**
|
6
6
|
* Generate embeddings for multiple values.
|
7
7
|
*
|
8
|
+
* @see https://modelfusion.dev/guide/function/embed
|
9
|
+
*
|
8
10
|
* @example
|
9
11
|
* const embeddings = await embedMany(
|
10
12
|
* new OpenAITextEmbeddingModel(...),
|
@@ -13,15 +15,29 @@ import { EmbeddingModel, EmbeddingModelSettings } from "./EmbeddingModel.js";
|
|
13
15
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
14
16
|
* ]
|
15
17
|
* );
|
18
|
+
*
|
19
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating embeddings.
|
20
|
+
* @param {VALUE[]} values - The values to generate embeddings for.
|
21
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
22
|
+
*
|
23
|
+
* @returns {ModelFunctionPromise<Vector[]>} - A promise that resolves to an array of vectors representing the embeddings.
|
16
24
|
*/
|
17
25
|
export declare function embedMany<VALUE>(model: EmbeddingModel<VALUE, EmbeddingModelSettings>, values: VALUE[], options?: FunctionOptions): ModelFunctionPromise<Vector[]>;
|
18
26
|
/**
|
19
27
|
* Generate an embedding for a single value.
|
20
28
|
*
|
29
|
+
* @see https://modelfusion.dev/guide/function/embed
|
30
|
+
*
|
21
31
|
* @example
|
22
32
|
* const embedding = await embed(
|
23
33
|
* new OpenAITextEmbeddingModel(...),
|
24
34
|
* "At first, Nox didn't know what to do with the pup."
|
25
35
|
* );
|
36
|
+
*
|
37
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating the embedding.
|
38
|
+
* @param {VALUE} value - The value to generate an embedding for.
|
39
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
40
|
+
*
|
41
|
+
* @returns {ModelFunctionPromise<Vector>} - A promise that resolves to a vector representing the embedding.
|
26
42
|
*/
|
27
43
|
export declare function embed<VALUE>(model: EmbeddingModel<VALUE, EmbeddingModelSettings>, value: VALUE, options?: FunctionOptions): ModelFunctionPromise<Vector>;
|
@@ -3,6 +3,8 @@ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
|
3
3
|
/**
|
4
4
|
* Generate embeddings for multiple values.
|
5
5
|
*
|
6
|
+
* @see https://modelfusion.dev/guide/function/embed
|
7
|
+
*
|
6
8
|
* @example
|
7
9
|
* const embeddings = await embedMany(
|
8
10
|
* new OpenAITextEmbeddingModel(...),
|
@@ -11,6 +13,12 @@ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
|
11
13
|
* "He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
|
12
14
|
* ]
|
13
15
|
* );
|
16
|
+
*
|
17
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating embeddings.
|
18
|
+
* @param {VALUE[]} values - The values to generate embeddings for.
|
19
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
20
|
+
*
|
21
|
+
* @returns {ModelFunctionPromise<Vector[]>} - A promise that resolves to an array of vectors representing the embeddings.
|
14
22
|
*/
|
15
23
|
export function embedMany(model, values, options) {
|
16
24
|
return new ModelFunctionPromise(executeStandardCall({
|
@@ -46,11 +54,19 @@ export function embedMany(model, values, options) {
|
|
46
54
|
/**
|
47
55
|
* Generate an embedding for a single value.
|
48
56
|
*
|
57
|
+
* @see https://modelfusion.dev/guide/function/embed
|
58
|
+
*
|
49
59
|
* @example
|
50
60
|
* const embedding = await embed(
|
51
61
|
* new OpenAITextEmbeddingModel(...),
|
52
62
|
* "At first, Nox didn't know what to do with the pup."
|
53
63
|
* );
|
64
|
+
*
|
65
|
+
* @param {EmbeddingModel<VALUE, EmbeddingModelSettings>} model - The model to use for generating the embedding.
|
66
|
+
* @param {VALUE} value - The value to generate an embedding for.
|
67
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
68
|
+
*
|
69
|
+
* @returns {ModelFunctionPromise<Vector>} - A promise that resolves to a vector representing the embedding.
|
54
70
|
*/
|
55
71
|
export function embed(model, value, options) {
|
56
72
|
return new ModelFunctionPromise(executeStandardCall({
|
@@ -4,11 +4,13 @@ exports.generateImage = void 0;
|
|
4
4
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
5
5
|
const ImageGenerationPromise_js_1 = require("./ImageGenerationPromise.cjs");
|
6
6
|
/**
|
7
|
-
* Generates
|
8
|
-
*
|
9
|
-
* For example, OpenAI image models expect a string prompt,
|
7
|
+
* Generates an image using a prompt.
|
8
|
+
*
|
9
|
+
* The prompt depends on the model. For example, OpenAI image models expect a string prompt,
|
10
10
|
* and Stability AI models expect an array of text prompts with optional weights.
|
11
11
|
*
|
12
|
+
* @see https://modelfusion.dev/guide/function/generate-image
|
13
|
+
*
|
12
14
|
* @example
|
13
15
|
* const image = await generateImage(
|
14
16
|
* new StabilityImageGenerationModel(...),
|
@@ -17,6 +19,13 @@ const ImageGenerationPromise_js_1 = require("./ImageGenerationPromise.cjs");
|
|
17
19
|
* { text: "style of early 19th century painting", weight: 0.5 },
|
18
20
|
* ]
|
19
21
|
* );
|
22
|
+
*
|
23
|
+
* @param {ImageGenerationModel<PROMPT, ImageGenerationModelSettings>} model - The image generation model to be used.
|
24
|
+
* @param {PROMPT} prompt - The prompt to be used for image generation.
|
25
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
26
|
+
*
|
27
|
+
* @returns {ImageGenerationPromise} - Returns a promise that resolves to the generated image.
|
28
|
+
* The image is a Buffer containing the image data in PNG format.
|
20
29
|
*/
|
21
30
|
function generateImage(model, prompt, options) {
|
22
31
|
return new ImageGenerationPromise_js_1.ImageGenerationPromise((0, executeStandardCall_js_1.executeStandardCall)({
|
@@ -2,11 +2,13 @@ import { FunctionOptions } from "../../core/FunctionOptions.js";
|
|
2
2
|
import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGenerationModel.js";
|
3
3
|
import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
|
4
4
|
/**
|
5
|
-
* Generates
|
6
|
-
*
|
7
|
-
* For example, OpenAI image models expect a string prompt,
|
5
|
+
* Generates an image using a prompt.
|
6
|
+
*
|
7
|
+
* The prompt depends on the model. For example, OpenAI image models expect a string prompt,
|
8
8
|
* and Stability AI models expect an array of text prompts with optional weights.
|
9
9
|
*
|
10
|
+
* @see https://modelfusion.dev/guide/function/generate-image
|
11
|
+
*
|
10
12
|
* @example
|
11
13
|
* const image = await generateImage(
|
12
14
|
* new StabilityImageGenerationModel(...),
|
@@ -15,5 +17,12 @@ import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
|
|
15
17
|
* { text: "style of early 19th century painting", weight: 0.5 },
|
16
18
|
* ]
|
17
19
|
* );
|
20
|
+
*
|
21
|
+
* @param {ImageGenerationModel<PROMPT, ImageGenerationModelSettings>} model - The image generation model to be used.
|
22
|
+
* @param {PROMPT} prompt - The prompt to be used for image generation.
|
23
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
24
|
+
*
|
25
|
+
* @returns {ImageGenerationPromise} - Returns a promise that resolves to the generated image.
|
26
|
+
* The image is a Buffer containing the image data in PNG format.
|
18
27
|
*/
|
19
28
|
export declare function generateImage<PROMPT>(model: ImageGenerationModel<PROMPT, ImageGenerationModelSettings>, prompt: PROMPT, options?: FunctionOptions): ImageGenerationPromise;
|
@@ -1,11 +1,13 @@
|
|
1
1
|
import { executeStandardCall } from "../executeStandardCall.js";
|
2
2
|
import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
|
3
3
|
/**
|
4
|
-
* Generates
|
5
|
-
*
|
6
|
-
* For example, OpenAI image models expect a string prompt,
|
4
|
+
* Generates an image using a prompt.
|
5
|
+
*
|
6
|
+
* The prompt depends on the model. For example, OpenAI image models expect a string prompt,
|
7
7
|
* and Stability AI models expect an array of text prompts with optional weights.
|
8
8
|
*
|
9
|
+
* @see https://modelfusion.dev/guide/function/generate-image
|
10
|
+
*
|
9
11
|
* @example
|
10
12
|
* const image = await generateImage(
|
11
13
|
* new StabilityImageGenerationModel(...),
|
@@ -14,6 +16,13 @@ import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
|
|
14
16
|
* { text: "style of early 19th century painting", weight: 0.5 },
|
15
17
|
* ]
|
16
18
|
* );
|
19
|
+
*
|
20
|
+
* @param {ImageGenerationModel<PROMPT, ImageGenerationModelSettings>} model - The image generation model to be used.
|
21
|
+
* @param {PROMPT} prompt - The prompt to be used for image generation.
|
22
|
+
* @param {FunctionOptions} [options] - Optional settings for the function.
|
23
|
+
*
|
24
|
+
* @returns {ImageGenerationPromise} - Returns a promise that resolves to the generated image.
|
25
|
+
* The image is a Buffer containing the image data in PNG format.
|
17
26
|
*/
|
18
27
|
export function generateImage(model, prompt, options) {
|
19
28
|
return new ImageGenerationPromise(executeStandardCall({
|
@@ -4,7 +4,22 @@ exports.generateSpeech = void 0;
|
|
4
4
|
const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
|
5
5
|
const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
|
6
6
|
/**
|
7
|
-
* Synthesizes speech from text.
|
7
|
+
* Synthesizes speech from text. Also called text-to-speech (TTS).
|
8
|
+
*
|
9
|
+
* @see https://modelfusion.dev/guide/function/generate-speech
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
* const speech = await generateSpeech(
|
13
|
+
* new LmntSpeechModel(...),
|
14
|
+
* "Good evening, ladies and gentlemen! Exciting news on the airwaves tonight " +
|
15
|
+
* "as The Rolling Stones unveil 'Hackney Diamonds.'
|
16
|
+
* );
|
17
|
+
*
|
18
|
+
* @param {SpeechGenerationModel<SpeechGenerationModelSettings>} model - The speech generation model.
|
19
|
+
* @param {string} text - The text to be converted to speech.
|
20
|
+
* @param {FunctionOptions} [options] - Optional function options.
|
21
|
+
*
|
22
|
+
* @returns {ModelFunctionPromise<Buffer>} - A promise that resolves to a buffer containing the synthesized speech.
|
8
23
|
*/
|
9
24
|
function generateSpeech(model, text, options) {
|
10
25
|
return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
|
@@ -3,6 +3,21 @@ import { FunctionOptions } from "../../core/FunctionOptions.js";
|
|
3
3
|
import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
4
4
|
import { SpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGenerationModel.js";
|
5
5
|
/**
|
6
|
-
* Synthesizes speech from text.
|
6
|
+
* Synthesizes speech from text. Also called text-to-speech (TTS).
|
7
|
+
*
|
8
|
+
* @see https://modelfusion.dev/guide/function/generate-speech
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* const speech = await generateSpeech(
|
12
|
+
* new LmntSpeechModel(...),
|
13
|
+
* "Good evening, ladies and gentlemen! Exciting news on the airwaves tonight " +
|
14
|
+
* "as The Rolling Stones unveil 'Hackney Diamonds.'
|
15
|
+
* );
|
16
|
+
*
|
17
|
+
* @param {SpeechGenerationModel<SpeechGenerationModelSettings>} model - The speech generation model.
|
18
|
+
* @param {string} text - The text to be converted to speech.
|
19
|
+
* @param {FunctionOptions} [options] - Optional function options.
|
20
|
+
*
|
21
|
+
* @returns {ModelFunctionPromise<Buffer>} - A promise that resolves to a buffer containing the synthesized speech.
|
7
22
|
*/
|
8
23
|
export declare function generateSpeech(model: SpeechGenerationModel<SpeechGenerationModelSettings>, text: string, options?: FunctionOptions): ModelFunctionPromise<Buffer>;
|
@@ -1,7 +1,22 @@
|
|
1
1
|
import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
|
2
2
|
import { executeStandardCall } from "../executeStandardCall.js";
|
3
3
|
/**
|
4
|
-
* Synthesizes speech from text.
|
4
|
+
* Synthesizes speech from text. Also called text-to-speech (TTS).
|
5
|
+
*
|
6
|
+
* @see https://modelfusion.dev/guide/function/generate-speech
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* const speech = await generateSpeech(
|
10
|
+
* new LmntSpeechModel(...),
|
11
|
+
* "Good evening, ladies and gentlemen! Exciting news on the airwaves tonight " +
|
12
|
+
* "as The Rolling Stones unveil 'Hackney Diamonds.'
|
13
|
+
* );
|
14
|
+
*
|
15
|
+
* @param {SpeechGenerationModel<SpeechGenerationModelSettings>} model - The speech generation model.
|
16
|
+
* @param {string} text - The text to be converted to speech.
|
17
|
+
* @param {FunctionOptions} [options] - Optional function options.
|
18
|
+
*
|
19
|
+
* @returns {ModelFunctionPromise<Buffer>} - A promise that resolves to a buffer containing the synthesized speech.
|
5
20
|
*/
|
6
21
|
export function generateSpeech(model, text, options) {
|
7
22
|
return new ModelFunctionPromise(executeStandardCall({
|