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
package/README.md
CHANGED
@@ -372,18 +372,16 @@ const { chunks } = await retrieveTextChunks(
|
|
372
372
|
- [Transcribe Speech](https://modelfusion.dev/guide/function/transcribe-speech)
|
373
373
|
- [Synthesize Speech](https://modelfusion.dev/guide/function/synthesize-speech)
|
374
374
|
- [Generate images](https://modelfusion.dev/guide/function/generate-image)
|
375
|
-
- Summarize text
|
376
375
|
- [Tools](https://modelfusion.dev/guide/tools)
|
377
376
|
- [Text Chunks](https://modelfusion.dev/guide/text-chunk/)
|
378
377
|
- [Split Text](https://modelfusion.dev/guide/text-chunk/split)
|
379
|
-
- [
|
380
|
-
- [
|
381
|
-
- [Cost calculation](https://modelfusion.dev/guide/run/cost-calculation)
|
382
|
-
- Call recording
|
383
|
-
- Utilities
|
378
|
+
- [Utilities](https://modelfusion.dev/guide/util/)
|
379
|
+
- [Function observers](https://modelfusion.dev/guide/util/observer)
|
384
380
|
- [Retry strategies](https://modelfusion.dev/guide/util/retry)
|
385
381
|
- [Throttling strategies](https://modelfusion.dev/guide/util/throttle)
|
386
|
-
-
|
382
|
+
- [Run abstraction](https://modelfusion.dev/guide/util/run)
|
383
|
+
- [Abort signals](https://modelfusion.dev/guide/util/abort)
|
384
|
+
- [Cost calculation](https://modelfusion.dev/guide/util/cost-calculation)
|
387
385
|
|
388
386
|
## Integrations
|
389
387
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
export type SummarizationFunction =
|
1
|
+
import { FunctionOptions } from "../../core/FunctionOptions.js";
|
2
|
+
export type SummarizationFunction = (input: {
|
3
3
|
text: string;
|
4
|
-
}, string>;
|
4
|
+
}, options?: FunctionOptions) => PromiseLike<string>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Run } from "../../
|
1
|
+
import { Run } from "../../core/Run.js";
|
2
2
|
import { SplitFunction } from "../../text-chunk/split/SplitFunction.js";
|
3
3
|
import { SummarizationFunction } from "./SummarizationFunction.js";
|
4
4
|
export declare function summarizeRecursively({ summarize, split, join, text, }: {
|
package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
|
2
2
|
import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
|
3
|
-
import { Run } from "../../
|
3
|
+
import { Run } from "../../core/Run.js";
|
4
4
|
/**
|
5
5
|
* Recursively summarizes a text using a text generation model, e.g. for summarization or text extraction.
|
6
6
|
* It automatically splits the text into optimal chunks that are small enough to be processed by the model,
|
@@ -2,10 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ConsoleLogger = void 0;
|
4
4
|
class ConsoleLogger {
|
5
|
-
|
6
|
-
console.log(JSON.stringify(event, null, 2));
|
7
|
-
}
|
8
|
-
onRunFunctionFinished(event) {
|
5
|
+
onFunctionEvent(event) {
|
9
6
|
console.log(JSON.stringify(event, null, 2));
|
10
7
|
}
|
11
8
|
}
|
@@ -5,7 +5,7 @@ const nanoid_1 = require("nanoid");
|
|
5
5
|
const calculateCost_js_1 = require("../cost/calculateCost.cjs");
|
6
6
|
const SuccessfulModelCall_js_1 = require("../model-function/SuccessfulModelCall.cjs");
|
7
7
|
class DefaultRun {
|
8
|
-
constructor({ runId = (0, nanoid_1.nanoid)()
|
8
|
+
constructor({ runId = `run-${(0, nanoid_1.nanoid)()}`, sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
|
9
9
|
Object.defineProperty(this, "runId", {
|
10
10
|
enumerable: true,
|
11
11
|
configurable: true,
|
@@ -55,10 +55,7 @@ class DefaultRun {
|
|
55
55
|
this.costCalculators = costCalculators;
|
56
56
|
this.observers = [
|
57
57
|
{
|
58
|
-
|
59
|
-
this.events.push(event);
|
60
|
-
},
|
61
|
-
onRunFunctionFinished: (event) => {
|
58
|
+
onFunctionEvent: (event) => {
|
62
59
|
this.events.push(event);
|
63
60
|
},
|
64
61
|
},
|
@@ -1,22 +1,22 @@
|
|
1
1
|
import { CostCalculator } from "../cost/CostCalculator.js";
|
2
2
|
import { SuccessfulModelCall } from "../model-function/SuccessfulModelCall.js";
|
3
3
|
import { Run } from "./Run.js";
|
4
|
-
import {
|
5
|
-
import {
|
4
|
+
import { FunctionEvent } from "./FunctionEvent.js";
|
5
|
+
import { FunctionObserver } from "./FunctionObserver.js";
|
6
6
|
export declare class DefaultRun implements Run {
|
7
7
|
readonly runId: string;
|
8
8
|
readonly sessionId?: string;
|
9
9
|
readonly userId?: string;
|
10
10
|
readonly abortSignal?: AbortSignal;
|
11
11
|
readonly costCalculators: CostCalculator[];
|
12
|
-
readonly events:
|
13
|
-
readonly observers?:
|
12
|
+
readonly events: FunctionEvent[];
|
13
|
+
readonly observers?: FunctionObserver[];
|
14
14
|
constructor({ runId, sessionId, userId, abortSignal, observers, costCalculators, }?: {
|
15
15
|
runId?: string;
|
16
16
|
sessionId?: string;
|
17
17
|
userId?: string;
|
18
18
|
abortSignal?: AbortSignal;
|
19
|
-
observers?:
|
19
|
+
observers?: FunctionObserver[];
|
20
20
|
costCalculators?: CostCalculator[];
|
21
21
|
});
|
22
22
|
get successfulModelCalls(): Array<SuccessfulModelCall>;
|
@@ -2,7 +2,7 @@ import { nanoid as createId } from "nanoid";
|
|
2
2
|
import { calculateCost } from "../cost/calculateCost.js";
|
3
3
|
import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
|
4
4
|
export class DefaultRun {
|
5
|
-
constructor({ runId = createId()
|
5
|
+
constructor({ runId = `run-${createId()}`, sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
|
6
6
|
Object.defineProperty(this, "runId", {
|
7
7
|
enumerable: true,
|
8
8
|
configurable: true,
|
@@ -52,10 +52,7 @@ export class DefaultRun {
|
|
52
52
|
this.costCalculators = costCalculators;
|
53
53
|
this.observers = [
|
54
54
|
{
|
55
|
-
|
56
|
-
this.events.push(event);
|
57
|
-
},
|
58
|
-
onRunFunctionFinished: (event) => {
|
55
|
+
onFunctionEvent: (event) => {
|
59
56
|
this.events.push(event);
|
60
57
|
},
|
61
58
|
},
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/ExecuteToolEvent.js";
|
2
|
+
import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
|
3
|
+
export interface BaseFunctionEvent {
|
4
|
+
/**
|
5
|
+
* Unique identifier for the function call.
|
6
|
+
*/
|
7
|
+
callId: string | undefined;
|
8
|
+
/**
|
9
|
+
* Optional unique identifier for the function.
|
10
|
+
*/
|
11
|
+
functionId?: string | undefined;
|
12
|
+
/**
|
13
|
+
* Unique identifier for the run.
|
14
|
+
* Only available if the function is part of a run.
|
15
|
+
*/
|
16
|
+
runId?: string | undefined;
|
17
|
+
/**
|
18
|
+
* Unique identifier for the session.
|
19
|
+
* Only available if the function is part of a run with a session.
|
20
|
+
*/
|
21
|
+
sessionId?: string | undefined;
|
22
|
+
/**
|
23
|
+
* Unique identifier for the user.
|
24
|
+
* Only available if the function is part of a run with a user.
|
25
|
+
*/
|
26
|
+
userId?: string | undefined;
|
27
|
+
/**
|
28
|
+
* Timestamp of the event.
|
29
|
+
*/
|
30
|
+
timestamp: Date;
|
31
|
+
/**
|
32
|
+
* Type of the event. Defined in the subclasses.
|
33
|
+
*/
|
34
|
+
eventType: "started" | "finished";
|
35
|
+
/**
|
36
|
+
* Type of the function. Defined in the subclasses.
|
37
|
+
*/
|
38
|
+
functionType: string;
|
39
|
+
}
|
40
|
+
export interface BaseFunctionStartedEvent extends BaseFunctionEvent {
|
41
|
+
eventType: "started";
|
42
|
+
/**
|
43
|
+
* Timestamp when the function call started.
|
44
|
+
*/
|
45
|
+
startTimestamp: Date;
|
46
|
+
}
|
47
|
+
export type BaseFunctionFinishedEventResult = {
|
48
|
+
status: "success";
|
49
|
+
output: unknown;
|
50
|
+
} | {
|
51
|
+
status: "error";
|
52
|
+
error: unknown;
|
53
|
+
} | {
|
54
|
+
status: "abort";
|
55
|
+
};
|
56
|
+
export interface BaseFunctionFinishedEvent extends BaseFunctionEvent {
|
57
|
+
eventType: "finished";
|
58
|
+
/**
|
59
|
+
* Timestamp when the function call started.
|
60
|
+
*/
|
61
|
+
startTimestamp: Date;
|
62
|
+
/**
|
63
|
+
* Timestamp when the function call finished.
|
64
|
+
*/
|
65
|
+
finishTimestamp: Date;
|
66
|
+
/**
|
67
|
+
* Duration of the function call in milliseconds.
|
68
|
+
*/
|
69
|
+
durationInMs: number;
|
70
|
+
/**
|
71
|
+
* Result of the function call.
|
72
|
+
*/
|
73
|
+
result: BaseFunctionFinishedEventResult;
|
74
|
+
}
|
75
|
+
export type FunctionEvent = ModelCallStartedEvent | ExecuteToolStartedEvent | ModelCallFinishedEvent | ExecuteToolFinishedEvent;
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FunctionEventSource = void 0;
|
4
|
+
class FunctionEventSource {
|
2
5
|
constructor({ observers, errorHandler, }) {
|
3
6
|
Object.defineProperty(this, "observers", {
|
4
7
|
enumerable: true,
|
@@ -15,20 +18,10 @@ export class RunFunctionEventSource {
|
|
15
18
|
this.observers = observers;
|
16
19
|
this.errorHandler = errorHandler ?? ((error) => console.error(error));
|
17
20
|
}
|
18
|
-
|
21
|
+
notify(event) {
|
19
22
|
for (const observer of this.observers) {
|
20
23
|
try {
|
21
|
-
observer.
|
22
|
-
}
|
23
|
-
catch (error) {
|
24
|
-
this.errorHandler(error);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
}
|
28
|
-
notifyRunFunctionFinished(event) {
|
29
|
-
for (const observer of this.observers) {
|
30
|
-
try {
|
31
|
-
observer.onRunFunctionFinished?.(event);
|
24
|
+
observer.onFunctionEvent(event);
|
32
25
|
}
|
33
26
|
catch (error) {
|
34
27
|
this.errorHandler(error);
|
@@ -36,3 +29,4 @@ export class RunFunctionEventSource {
|
|
36
29
|
}
|
37
30
|
}
|
38
31
|
}
|
32
|
+
exports.FunctionEventSource = FunctionEventSource;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ErrorHandler } from "../util/ErrorHandler.js";
|
2
|
+
import { FunctionEvent } from "./FunctionEvent.js";
|
3
|
+
import { FunctionObserver } from "./FunctionObserver.js";
|
4
|
+
export declare class FunctionEventSource {
|
5
|
+
readonly observers: FunctionObserver[];
|
6
|
+
readonly errorHandler: ErrorHandler;
|
7
|
+
constructor({ observers, errorHandler, }: {
|
8
|
+
observers: FunctionObserver[];
|
9
|
+
errorHandler?: ErrorHandler;
|
10
|
+
});
|
11
|
+
notify(event: FunctionEvent): void;
|
12
|
+
}
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.RunFunctionEventSource = void 0;
|
4
|
-
class RunFunctionEventSource {
|
1
|
+
export class FunctionEventSource {
|
5
2
|
constructor({ observers, errorHandler, }) {
|
6
3
|
Object.defineProperty(this, "observers", {
|
7
4
|
enumerable: true,
|
@@ -18,20 +15,10 @@ class RunFunctionEventSource {
|
|
18
15
|
this.observers = observers;
|
19
16
|
this.errorHandler = errorHandler ?? ((error) => console.error(error));
|
20
17
|
}
|
21
|
-
|
18
|
+
notify(event) {
|
22
19
|
for (const observer of this.observers) {
|
23
20
|
try {
|
24
|
-
observer.
|
25
|
-
}
|
26
|
-
catch (error) {
|
27
|
-
this.errorHandler(error);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
notifyRunFunctionFinished(event) {
|
32
|
-
for (const observer of this.observers) {
|
33
|
-
try {
|
34
|
-
observer.onRunFunctionFinished?.(event);
|
21
|
+
observer.onFunctionEvent(event);
|
35
22
|
}
|
36
23
|
catch (error) {
|
37
24
|
this.errorHandler(error);
|
@@ -39,4 +26,3 @@ class RunFunctionEventSource {
|
|
39
26
|
}
|
40
27
|
}
|
41
28
|
}
|
42
|
-
exports.RunFunctionEventSource = RunFunctionEventSource;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Run } from "./Run.js";
|
2
|
+
import { FunctionObserver } from "./FunctionObserver.js";
|
3
|
+
/**
|
4
|
+
* Additional settings for ModelFusion functions.
|
5
|
+
*/
|
6
|
+
export type FunctionOptions = {
|
7
|
+
/**
|
8
|
+
* Optional function identifier that is used in events to identify the function.
|
9
|
+
*/
|
10
|
+
functionId?: string;
|
11
|
+
/**
|
12
|
+
* Optional observers that are called when the function is invoked.
|
13
|
+
*/
|
14
|
+
observers?: Array<FunctionObserver>;
|
15
|
+
/**
|
16
|
+
* Optional run as part of which this function is called.
|
17
|
+
*/
|
18
|
+
run?: Run;
|
19
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getGlobalFunctionObservers = exports.setGlobalFunctionObservers = void 0;
|
4
|
+
let globalFunctionObservers = [];
|
5
|
+
function setGlobalFunctionObservers(functionObservers) {
|
6
|
+
globalFunctionObservers = functionObservers;
|
7
|
+
}
|
8
|
+
exports.setGlobalFunctionObservers = setGlobalFunctionObservers;
|
9
|
+
function getGlobalFunctionObservers() {
|
10
|
+
return globalFunctionObservers;
|
11
|
+
}
|
12
|
+
exports.getGlobalFunctionObservers = getGlobalFunctionObservers;
|
package/{run → core}/Run.d.ts
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorHandler } from "../util/ErrorHandler.js";
|
2
|
-
import {
|
2
|
+
import { FunctionObserver } from "./FunctionObserver.js";
|
3
3
|
export interface Run {
|
4
4
|
/**
|
5
5
|
* Unique identifier for a specific run. Primarily utilized for efficient referencing
|
@@ -22,6 +22,6 @@ export interface Run {
|
|
22
22
|
* to the run.
|
23
23
|
*/
|
24
24
|
abortSignal?: AbortSignal;
|
25
|
-
observers?:
|
25
|
+
observers?: FunctionObserver[];
|
26
26
|
errorHandler?: ErrorHandler;
|
27
27
|
}
|
package/{run → core}/index.cjs
RENAMED
@@ -16,10 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./ConsoleLogger.cjs"), exports);
|
18
18
|
__exportStar(require("./DefaultRun.cjs"), exports);
|
19
|
-
__exportStar(require("./
|
19
|
+
__exportStar(require("./FunctionEvent.cjs"), exports);
|
20
|
+
__exportStar(require("./FunctionEventSource.cjs"), exports);
|
21
|
+
__exportStar(require("./FunctionObserver.cjs"), exports);
|
22
|
+
__exportStar(require("./FunctionOptions.cjs"), exports);
|
23
|
+
__exportStar(require("./GlobalFunctionObservers.cjs"), exports);
|
20
24
|
__exportStar(require("./Run.cjs"), exports);
|
21
|
-
__exportStar(require("./RunFunction.cjs"), exports);
|
22
|
-
__exportStar(require("./RunFunctionEvent.cjs"), exports);
|
23
|
-
__exportStar(require("./RunFunctionObserver.cjs"), exports);
|
24
|
-
__exportStar(require("./RunFunctionEventSource.cjs"), exports);
|
25
25
|
__exportStar(require("./Vector.cjs"), exports);
|
package/core/index.d.ts
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
export * from "./ConsoleLogger.js";
|
2
|
+
export * from "./DefaultRun.js";
|
3
|
+
export * from "./FunctionEvent.js";
|
4
|
+
export * from "./FunctionEventSource.js";
|
5
|
+
export * from "./FunctionObserver.js";
|
6
|
+
export * from "./FunctionOptions.js";
|
7
|
+
export * from "./GlobalFunctionObservers.js";
|
8
|
+
export * from "./Run.js";
|
9
|
+
export * from "./Vector.js";
|
package/core/index.js
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
export * from "./ConsoleLogger.js";
|
2
|
+
export * from "./DefaultRun.js";
|
3
|
+
export * from "./FunctionEvent.js";
|
4
|
+
export * from "./FunctionEventSource.js";
|
5
|
+
export * from "./FunctionObserver.js";
|
6
|
+
export * from "./FunctionOptions.js";
|
7
|
+
export * from "./GlobalFunctionObservers.js";
|
8
|
+
export * from "./Run.js";
|
9
|
+
export * from "./Vector.js";
|
package/index.cjs
CHANGED
@@ -15,11 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./composed-function/index.cjs"), exports);
|
18
|
+
__exportStar(require("./core/index.cjs"), exports);
|
18
19
|
__exportStar(require("./cost/index.cjs"), exports);
|
19
20
|
__exportStar(require("./model-function/index.cjs"), exports);
|
20
21
|
__exportStar(require("./model-provider/index.cjs"), exports);
|
21
22
|
__exportStar(require("./prompt/index.cjs"), exports);
|
22
|
-
__exportStar(require("./run/index.cjs"), exports);
|
23
23
|
__exportStar(require("./text-chunk/index.cjs"), exports);
|
24
24
|
__exportStar(require("./tool/index.cjs"), exports);
|
25
25
|
__exportStar(require("./util/index.cjs"), exports);
|
package/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
export * from "./composed-function/index.js";
|
2
|
+
export * from "./core/index.js";
|
2
3
|
export * from "./cost/index.js";
|
3
4
|
export * from "./model-function/index.js";
|
4
5
|
export * from "./model-provider/index.js";
|
5
6
|
export * from "./prompt/index.js";
|
6
|
-
export * from "./run/index.js";
|
7
7
|
export * from "./text-chunk/index.js";
|
8
8
|
export * from "./tool/index.js";
|
9
9
|
export * from "./util/index.js";
|
package/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
export * from "./composed-function/index.js";
|
2
|
+
export * from "./core/index.js";
|
2
3
|
export * from "./cost/index.js";
|
3
4
|
export * from "./model-function/index.js";
|
4
5
|
export * from "./model-provider/index.js";
|
5
6
|
export * from "./prompt/index.js";
|
6
|
-
export * from "./run/index.js";
|
7
7
|
export * from "./text-chunk/index.js";
|
8
8
|
export * from "./tool/index.js";
|
9
9
|
export * from "./util/index.js";
|
@@ -1,7 +1,10 @@
|
|
1
1
|
import { ModelInformation } from "./ModelInformation.js";
|
2
|
-
import {
|
2
|
+
import { FunctionObserver } from "../core/FunctionObserver.js";
|
3
3
|
export interface ModelSettings {
|
4
|
-
|
4
|
+
/**
|
5
|
+
* Observers that are called when the model is used in run functions.
|
6
|
+
*/
|
7
|
+
observers?: Array<FunctionObserver>;
|
5
8
|
}
|
6
9
|
export interface Model<SETTINGS> {
|
7
10
|
modelInformation: ModelInformation;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
|
2
2
|
import { ModelInformation } from "./ModelInformation.js";
|
3
3
|
import { TextEmbeddingFinishedEvent, TextEmbeddingStartedEvent } from "./embed-text/TextEmbeddingEvent.js";
|
4
4
|
import { ImageGenerationFinishedEvent, ImageGenerationStartedEvent } from "./generate-image/ImageGenerationEvent.js";
|
@@ -7,11 +7,26 @@ import { TextGenerationFinishedEvent, TextGenerationStartedEvent } from "./gener
|
|
7
7
|
import { TextStreamingFinishedEvent, TextStreamingStartedEvent } from "./generate-text/TextStreamingEvent.js";
|
8
8
|
import { SpeechSynthesisFinishedEvent, SpeechSynthesisStartedEvent } from "./synthesize-speech/SpeechSynthesisEvent.js";
|
9
9
|
import { TranscriptionFinishedEvent, TranscriptionStartedEvent } from "./transcribe-speech/TranscriptionEvent.js";
|
10
|
-
export
|
10
|
+
export interface BaseModelCallStartedEvent extends BaseFunctionStartedEvent {
|
11
11
|
model: ModelInformation;
|
12
|
+
settings: unknown;
|
13
|
+
input: unknown;
|
14
|
+
}
|
15
|
+
export type BaseModelCallFinishedEventResult = {
|
16
|
+
status: "success";
|
17
|
+
response: unknown;
|
18
|
+
output: unknown;
|
19
|
+
} | {
|
20
|
+
status: "error";
|
21
|
+
error: unknown;
|
22
|
+
} | {
|
23
|
+
status: "abort";
|
12
24
|
};
|
13
|
-
export
|
14
|
-
export type ModelCallFinishedEventMetadata = RunFunctionFinishedEventMetadata & {
|
25
|
+
export interface BaseModelCallFinishedEvent extends BaseFunctionFinishedEvent {
|
15
26
|
model: ModelInformation;
|
16
|
-
|
27
|
+
settings: unknown;
|
28
|
+
input: unknown;
|
29
|
+
result: BaseModelCallFinishedEventResult;
|
30
|
+
}
|
31
|
+
export type ModelCallStartedEvent = ImageGenerationStartedEvent | JsonGenerationStartedEvent | SpeechSynthesisStartedEvent | TextEmbeddingStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
|
17
32
|
export type ModelCallFinishedEvent = ImageGenerationFinishedEvent | JsonGenerationFinishedEvent | SpeechSynthesisFinishedEvent | TextEmbeddingFinishedEvent | TextGenerationFinishedEvent | TextStreamingFinishedEvent | TranscriptionFinishedEvent;
|
@@ -3,24 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractSuccessfulModelCalls = void 0;
|
4
4
|
function extractSuccessfulModelCalls(runFunctionEvents) {
|
5
5
|
return runFunctionEvents
|
6
|
-
.filter((event) =>
|
7
|
-
"status" in event &&
|
8
|
-
event.status === "success")
|
6
|
+
.filter((event) => "result" in event &&
|
7
|
+
"status" in event.result &&
|
8
|
+
event.result.status === "success")
|
9
9
|
.map((event) => ({
|
10
|
-
model: event.
|
10
|
+
model: event.model,
|
11
11
|
settings: event.settings,
|
12
|
-
response: event.response,
|
13
|
-
type:
|
12
|
+
response: event.result.response,
|
13
|
+
type: event.functionType,
|
14
14
|
}));
|
15
15
|
}
|
16
16
|
exports.extractSuccessfulModelCalls = extractSuccessfulModelCalls;
|
17
|
-
const eventTypeToCostType = {
|
18
|
-
"image-generation-finished": "image-generation",
|
19
|
-
"json-generation-finished": "json-generation",
|
20
|
-
"json-or-text-generation-finished": "json-or-text-generation",
|
21
|
-
"speech-synthesis-finished": "speech-synthesis",
|
22
|
-
"text-embedding-finished": "text-embedding",
|
23
|
-
"text-generation-finished": "text-generation",
|
24
|
-
"text-streaming-finished": "text-streaming",
|
25
|
-
"transcription-finished": "transcription",
|
26
|
-
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { FunctionEvent } from "../core/FunctionEvent.js";
|
2
2
|
import { ModelInformation } from "./ModelInformation.js";
|
3
3
|
export type SuccessfulModelCall = {
|
4
4
|
type: "image-generation" | "json-generation" | "json-or-text-generation" | "speech-synthesis" | "text-embedding" | "text-generation" | "text-streaming" | "transcription";
|
@@ -6,4 +6,4 @@ export type SuccessfulModelCall = {
|
|
6
6
|
settings: unknown;
|
7
7
|
response: unknown;
|
8
8
|
};
|
9
|
-
export declare function extractSuccessfulModelCalls(runFunctionEvents:
|
9
|
+
export declare function extractSuccessfulModelCalls(runFunctionEvents: FunctionEvent[]): SuccessfulModelCall[];
|
@@ -1,22 +1,12 @@
|
|
1
1
|
export function extractSuccessfulModelCalls(runFunctionEvents) {
|
2
2
|
return runFunctionEvents
|
3
|
-
.filter((event) =>
|
4
|
-
"status" in event &&
|
5
|
-
event.status === "success")
|
3
|
+
.filter((event) => "result" in event &&
|
4
|
+
"status" in event.result &&
|
5
|
+
event.result.status === "success")
|
6
6
|
.map((event) => ({
|
7
|
-
model: event.
|
7
|
+
model: event.model,
|
8
8
|
settings: event.settings,
|
9
|
-
response: event.response,
|
10
|
-
type:
|
9
|
+
response: event.result.response,
|
10
|
+
type: event.functionType,
|
11
11
|
}));
|
12
12
|
}
|
13
|
-
const eventTypeToCostType = {
|
14
|
-
"image-generation-finished": "image-generation",
|
15
|
-
"json-generation-finished": "json-generation",
|
16
|
-
"json-or-text-generation-finished": "json-or-text-generation",
|
17
|
-
"speech-synthesis-finished": "speech-synthesis",
|
18
|
-
"text-embedding-finished": "text-embedding",
|
19
|
-
"text-generation-finished": "text-generation",
|
20
|
-
"text-streaming-finished": "text-streaming",
|
21
|
-
"transcription-finished": "transcription",
|
22
|
-
};
|
@@ -1,23 +1,21 @@
|
|
1
|
-
import { Vector } from "../../
|
2
|
-
import {
|
3
|
-
export
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
9
|
-
export type TextEmbeddingFinishedEvent = {
|
10
|
-
type: "text-embedding-finished";
|
11
|
-
metadata: ModelCallFinishedEventMetadata;
|
12
|
-
settings: unknown;
|
13
|
-
texts: Array<string>;
|
14
|
-
} & ({
|
1
|
+
import { Vector } from "../../core/Vector.js";
|
2
|
+
import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
|
3
|
+
export interface TextEmbeddingStartedEvent extends BaseModelCallStartedEvent {
|
4
|
+
functionType: "text-embedding";
|
5
|
+
input: string | Array<string>;
|
6
|
+
}
|
7
|
+
export type TextEmbeddingFinishedEventResult = {
|
15
8
|
status: "success";
|
16
9
|
response: unknown;
|
17
|
-
|
10
|
+
output: Vector | Array<Vector>;
|
18
11
|
} | {
|
19
|
-
status: "
|
12
|
+
status: "error";
|
20
13
|
error: unknown;
|
21
14
|
} | {
|
22
15
|
status: "abort";
|
23
|
-
}
|
16
|
+
};
|
17
|
+
export interface TextEmbeddingFinishedEvent extends BaseModelCallFinishedEvent {
|
18
|
+
functionType: "text-embedding";
|
19
|
+
input: string | Array<string>;
|
20
|
+
result: TextEmbeddingFinishedEventResult;
|
21
|
+
}
|