modelfusion 0.7.0 → 0.9.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 +14 -4
- package/composed-function/index.cjs +0 -3
- package/composed-function/index.d.ts +0 -3
- package/composed-function/index.js +0 -3
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/model-function/Model.d.ts +2 -2
- package/model-function/ModelCallEvent.d.ts +4 -6
- package/model-function/SuccessfulModelCall.cjs +6 -3
- package/model-function/SuccessfulModelCall.d.ts +3 -3
- package/model-function/SuccessfulModelCall.js +6 -3
- package/model-function/executeCall.cjs +6 -6
- package/model-function/executeCall.js +6 -6
- package/model-function/generate-json/JsonGenerationEvent.d.ts +2 -2
- package/model-function/generate-json/generateJsonOrText.cjs +4 -4
- package/model-function/generate-json/generateJsonOrText.js +4 -4
- package/model-function/generate-text/streamText.cjs +7 -7
- package/model-function/generate-text/streamText.js +7 -7
- package/model-function/index.cjs +1 -1
- package/model-function/index.d.ts +1 -1
- package/model-function/index.js +1 -1
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +1 -1
- package/package.json +1 -1
- package/run/ConsoleLogger.cjs +2 -2
- package/run/ConsoleLogger.d.ts +5 -5
- package/run/ConsoleLogger.js +2 -2
- package/run/DefaultRun.cjs +7 -7
- package/run/DefaultRun.d.ts +6 -6
- package/run/DefaultRun.js +7 -7
- package/run/Run.d.ts +2 -2
- package/run/RunFunction.d.ts +0 -4
- package/run/RunFunctionEvent.d.ts +12 -0
- package/{model-function/ModelCallEventSource.cjs → run/RunFunctionEventSource.cjs} +7 -7
- package/run/RunFunctionEventSource.d.ts +13 -0
- package/{model-function/ModelCallEventSource.js → run/RunFunctionEventSource.js} +5 -5
- package/run/RunFunctionObserver.cjs +2 -0
- package/run/RunFunctionObserver.d.ts +5 -0
- package/run/RunFunctionObserver.js +1 -0
- package/run/index.cjs +3 -0
- package/run/index.d.ts +3 -0
- package/run/index.js +3 -0
- package/tool/ExecuteToolEvent.cjs +2 -0
- package/tool/ExecuteToolEvent.d.ts +22 -0
- package/tool/ExecuteToolEvent.js +1 -0
- package/{composed-function/use-tool → tool}/Tool.cjs +31 -0
- package/tool/Tool.d.ts +42 -0
- package/tool/Tool.js +70 -0
- package/tool/ToolExecutionError.cjs +31 -0
- package/tool/ToolExecutionError.d.ts +11 -0
- package/tool/ToolExecutionError.js +27 -0
- package/tool/WebSearchTool.cjs +43 -0
- package/tool/WebSearchTool.d.ts +81 -0
- package/tool/WebSearchTool.js +39 -0
- package/tool/executeTool.cjs +79 -0
- package/tool/executeTool.d.ts +23 -0
- package/tool/executeTool.js +75 -0
- package/tool/index.cjs +23 -0
- package/tool/index.d.ts +7 -0
- package/tool/index.js +7 -0
- package/tool/useTool.cjs +33 -0
- package/tool/useTool.d.ts +15 -0
- package/tool/useTool.js +29 -0
- package/tool/useToolOrGenerateText.cjs +38 -0
- package/{composed-function/use-tool/useTool.d.ts → tool/useToolOrGenerateText.d.ts} +2 -15
- package/tool/useToolOrGenerateText.js +34 -0
- package/composed-function/use-tool/Tool.d.ts +0 -15
- package/composed-function/use-tool/Tool.js +0 -39
- package/composed-function/use-tool/useTool.cjs +0 -62
- package/composed-function/use-tool/useTool.js +0 -57
- package/model-function/ModelCallEventSource.d.ts +0 -13
- package/model-function/ModelCallObserver.d.ts +0 -5
- /package/{model-function/ModelCallObserver.cjs → run/RunFunctionEvent.cjs} +0 -0
- /package/{model-function/ModelCallObserver.js → run/RunFunctionEvent.js} +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.cjs +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.d.ts +0 -0
- /package/{composed-function/use-tool → tool}/NoSuchToolError.js +0 -0
package/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
[Introduction](#introduction) | [Quick Install](#quick-install) | [Usage](#usage-examples) | [Features](#features) | [Integrations](#integrations) | [Documentation](#documentation) | [Examples](#more-examples) | [modelfusion.dev](https://modelfusion.dev)
|
12
12
|
|
13
13
|
> [!NOTE]
|
14
|
-
> ModelFusion is in its initial development phase. Until version 1.0 there may be breaking changes, because
|
14
|
+
> ModelFusion is in its initial development phase. Until version 1.0 there may be breaking changes, because I am still exploring the API design. Feedback and suggestions are welcome.
|
15
15
|
|
16
16
|
## Introduction
|
17
17
|
|
@@ -106,13 +106,23 @@ const textStream = await streamText(
|
|
106
106
|
ModelFusion model functions return rich results that include the original response and metadata when you set the `fullResponse` option to `true`.
|
107
107
|
|
108
108
|
```ts
|
109
|
-
|
109
|
+
// access the full response and the metadata:
|
110
|
+
// the response type is specific to the model that's being used
|
111
|
+
const { response, metadata } = await generateText(
|
110
112
|
new OpenAITextGenerationModel({
|
111
113
|
model: "text-davinci-003",
|
114
|
+
maxTokens: 1000,
|
115
|
+
n: 2, // generate 2 completions
|
112
116
|
}),
|
113
117
|
"Write a short story about a robot learning to love:\n\n",
|
114
118
|
{ fullResponse: true }
|
115
119
|
);
|
120
|
+
|
121
|
+
for (const choice of response.choices) {
|
122
|
+
console.log(choice.text);
|
123
|
+
}
|
124
|
+
|
125
|
+
console.log(`Duration: ${metadata.durationInMs}ms`);
|
116
126
|
```
|
117
127
|
|
118
128
|
### [Generate JSON](https://modelfusion.dev/guide/function/generate-json)
|
@@ -437,9 +447,9 @@ Record audio with push-to-talk and transcribe it using Whisper, implemented as a
|
|
437
447
|
|
438
448
|
### [BabyAGI Agent](https://github.com/lgrammel/modelfusion/tree/main/examples/babyagi-agent)
|
439
449
|
|
440
|
-
> _terminal app_, _agent_, _BabyAGI_
|
450
|
+
> _terminal app_, _agent_, _BabyAGI_
|
441
451
|
|
442
|
-
TypeScript implementation of the
|
452
|
+
TypeScript implementation of the BabyAGI classic and BabyBeeAGI.
|
443
453
|
|
444
454
|
### [Middle school math agent](https://github.com/lgrammel/modelfusion/tree/main/examples/middle-school-math-agent)
|
445
455
|
|
@@ -14,9 +14,6 @@ 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("./use-tool/NoSuchToolError.cjs"), exports);
|
18
|
-
__exportStar(require("./use-tool/Tool.cjs"), exports);
|
19
|
-
__exportStar(require("./use-tool/useTool.cjs"), exports);
|
20
17
|
__exportStar(require("./summarize/SummarizationFunction.cjs"), exports);
|
21
18
|
__exportStar(require("./summarize/summarizeRecursively.cjs"), exports);
|
22
19
|
__exportStar(require("./summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs"), exports);
|
@@ -1,6 +1,3 @@
|
|
1
|
-
export * from "./use-tool/NoSuchToolError.js";
|
2
|
-
export * from "./use-tool/Tool.js";
|
3
|
-
export * from "./use-tool/useTool.js";
|
4
1
|
export * from "./summarize/SummarizationFunction.js";
|
5
2
|
export * from "./summarize/summarizeRecursively.js";
|
6
3
|
export * from "./summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js";
|
@@ -1,6 +1,3 @@
|
|
1
|
-
export * from "./use-tool/NoSuchToolError.js";
|
2
|
-
export * from "./use-tool/Tool.js";
|
3
|
-
export * from "./use-tool/useTool.js";
|
4
1
|
export * from "./summarize/SummarizationFunction.js";
|
5
2
|
export * from "./summarize/summarizeRecursively.js";
|
6
3
|
export * from "./summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js";
|
package/index.cjs
CHANGED
@@ -21,5 +21,6 @@ __exportStar(require("./model-provider/index.cjs"), exports);
|
|
21
21
|
__exportStar(require("./prompt/index.cjs"), exports);
|
22
22
|
__exportStar(require("./run/index.cjs"), exports);
|
23
23
|
__exportStar(require("./text-chunk/index.cjs"), exports);
|
24
|
+
__exportStar(require("./tool/index.cjs"), exports);
|
24
25
|
__exportStar(require("./util/index.cjs"), exports);
|
25
26
|
__exportStar(require("./vector-index/index.cjs"), exports);
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ModelInformation } from "./ModelInformation.js";
|
2
|
-
import {
|
2
|
+
import { RunFunctionObserver } from "../run/RunFunctionObserver.js";
|
3
3
|
export interface ModelSettings {
|
4
|
-
observers?: Array<
|
4
|
+
observers?: Array<RunFunctionObserver>;
|
5
5
|
}
|
6
6
|
export interface Model<SETTINGS> {
|
7
7
|
modelInformation: ModelInformation;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { RunFunctionFinishedEventMetadata, RunFunctionStartedEventMetadata } from "../run/RunFunctionEvent.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";
|
@@ -6,13 +6,11 @@ import { JsonGenerationFinishedEvent, JsonGenerationStartedEvent } from "./gener
|
|
6
6
|
import { TextGenerationFinishedEvent, TextGenerationStartedEvent } from "./generate-text/TextGenerationEvent.js";
|
7
7
|
import { TextStreamingFinishedEvent, TextStreamingStartedEvent } from "./generate-text/TextStreamingEvent.js";
|
8
8
|
import { TranscriptionFinishedEvent, TranscriptionStartedEvent } from "./transcribe-audio/TranscriptionEvent.js";
|
9
|
-
export type
|
10
|
-
export type ModelCallStartedEventMetadata = IdMetadata & {
|
9
|
+
export type ModelCallStartedEventMetadata = RunFunctionStartedEventMetadata & {
|
11
10
|
model: ModelInformation;
|
12
|
-
startEpochSeconds: number;
|
13
11
|
};
|
14
12
|
export type ModelCallStartedEvent = ImageGenerationStartedEvent | JsonGenerationStartedEvent | TextEmbeddingStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
|
15
|
-
export type ModelCallFinishedEventMetadata =
|
16
|
-
|
13
|
+
export type ModelCallFinishedEventMetadata = RunFunctionFinishedEventMetadata & {
|
14
|
+
model: ModelInformation;
|
17
15
|
};
|
18
16
|
export type ModelCallFinishedEvent = ImageGenerationFinishedEvent | JsonGenerationFinishedEvent | TextEmbeddingFinishedEvent | TextGenerationFinishedEvent | TextStreamingFinishedEvent | TranscriptionFinishedEvent;
|
@@ -1,9 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.extractSuccessfulModelCalls = void 0;
|
4
|
-
function extractSuccessfulModelCalls(
|
5
|
-
return
|
6
|
-
.filter((event) =>
|
4
|
+
function extractSuccessfulModelCalls(runFunctionEvents) {
|
5
|
+
return runFunctionEvents
|
6
|
+
.filter((event) => Object.keys(eventTypeToCostType).includes(event.type) &&
|
7
|
+
"status" in event &&
|
8
|
+
event.status === "success")
|
7
9
|
.map((event) => ({
|
8
10
|
model: event.metadata.model,
|
9
11
|
settings: event.settings,
|
@@ -15,6 +17,7 @@ exports.extractSuccessfulModelCalls = extractSuccessfulModelCalls;
|
|
15
17
|
const eventTypeToCostType = {
|
16
18
|
"image-generation-finished": "image-generation",
|
17
19
|
"json-generation-finished": "json-generation",
|
20
|
+
"json-or-text-generation-finished": "json-or-text-generation",
|
18
21
|
"text-embedding-finished": "text-embedding",
|
19
22
|
"text-generation-finished": "text-generation",
|
20
23
|
"text-streaming-finished": "text-streaming",
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import {
|
1
|
+
import { RunFunctionEvent } from "../run/RunFunctionEvent.js";
|
2
2
|
import { ModelInformation } from "./ModelInformation.js";
|
3
3
|
export type SuccessfulModelCall = {
|
4
|
-
type: "image-generation" | "json-generation" | "text-embedding" | "text-generation" | "text-streaming" | "transcription";
|
4
|
+
type: "image-generation" | "json-generation" | "json-or-text-generation" | "text-embedding" | "text-generation" | "text-streaming" | "transcription";
|
5
5
|
model: ModelInformation;
|
6
6
|
settings: unknown;
|
7
7
|
response: unknown;
|
8
8
|
};
|
9
|
-
export declare function extractSuccessfulModelCalls(
|
9
|
+
export declare function extractSuccessfulModelCalls(runFunctionEvents: RunFunctionEvent[]): SuccessfulModelCall[];
|
@@ -1,6 +1,8 @@
|
|
1
|
-
export function extractSuccessfulModelCalls(
|
2
|
-
return
|
3
|
-
.filter((event) =>
|
1
|
+
export function extractSuccessfulModelCalls(runFunctionEvents) {
|
2
|
+
return runFunctionEvents
|
3
|
+
.filter((event) => Object.keys(eventTypeToCostType).includes(event.type) &&
|
4
|
+
"status" in event &&
|
5
|
+
event.status === "success")
|
4
6
|
.map((event) => ({
|
5
7
|
model: event.metadata.model,
|
6
8
|
settings: event.settings,
|
@@ -11,6 +13,7 @@ export function extractSuccessfulModelCalls(modelCallEvents) {
|
|
11
13
|
const eventTypeToCostType = {
|
12
14
|
"image-generation-finished": "image-generation",
|
13
15
|
"json-generation-finished": "json-generation",
|
16
|
+
"json-or-text-generation-finished": "json-or-text-generation",
|
14
17
|
"text-embedding-finished": "text-embedding",
|
15
18
|
"text-generation-finished": "text-generation",
|
16
19
|
"text-streaming-finished": "text-streaming",
|
@@ -2,10 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.executeCall = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
|
+
const RunFunctionEventSource_js_1 = require("../run/RunFunctionEventSource.cjs");
|
5
6
|
const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
|
6
7
|
const AbortError_js_1 = require("../util/api/AbortError.cjs");
|
7
8
|
const runSafe_js_1 = require("../util/runSafe.cjs");
|
8
|
-
const ModelCallEventSource_js_1 = require("./ModelCallEventSource.cjs");
|
9
9
|
async function executeCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
|
10
10
|
if (options?.settings != null) {
|
11
11
|
model = model.withSettings(options.settings);
|
@@ -16,7 +16,7 @@ async function executeCall({ model, options, getStartEvent, getAbortEvent, getFa
|
|
16
16
|
}
|
17
17
|
const run = options?.run;
|
18
18
|
const settings = model.settings;
|
19
|
-
const eventSource = new
|
19
|
+
const eventSource = new RunFunctionEventSource_js_1.RunFunctionEventSource({
|
20
20
|
observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
|
21
21
|
errorHandler: run?.errorHandler,
|
22
22
|
});
|
@@ -30,7 +30,7 @@ async function executeCall({ model, options, getStartEvent, getAbortEvent, getFa
|
|
30
30
|
model: model.modelInformation,
|
31
31
|
startEpochSeconds: durationMeasurement.startEpochSeconds,
|
32
32
|
};
|
33
|
-
eventSource.
|
33
|
+
eventSource.notifyRunFunctionStarted(getStartEvent(startMetadata, settings));
|
34
34
|
const result = await (0, runSafe_js_1.runSafe)(() => generateResponse({
|
35
35
|
functionId: options?.functionId,
|
36
36
|
settings,
|
@@ -42,15 +42,15 @@ async function executeCall({ model, options, getStartEvent, getAbortEvent, getFa
|
|
42
42
|
};
|
43
43
|
if (!result.ok) {
|
44
44
|
if (result.isAborted) {
|
45
|
-
eventSource.
|
45
|
+
eventSource.notifyRunFunctionFinished(getAbortEvent(finishMetadata, settings));
|
46
46
|
throw new AbortError_js_1.AbortError();
|
47
47
|
}
|
48
|
-
eventSource.
|
48
|
+
eventSource.notifyRunFunctionFinished(getFailureEvent(finishMetadata, settings, result.error));
|
49
49
|
throw result.error;
|
50
50
|
}
|
51
51
|
const response = result.output;
|
52
52
|
const output = extractOutputValue(response);
|
53
|
-
eventSource.
|
53
|
+
eventSource.notifyRunFunctionFinished(getSuccessEvent(finishMetadata, settings, response, output));
|
54
54
|
return {
|
55
55
|
output,
|
56
56
|
response,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
+
import { RunFunctionEventSource } from "../run/RunFunctionEventSource.js";
|
2
3
|
import { startDurationMeasurement } from "../util/DurationMeasurement.js";
|
3
4
|
import { AbortError } from "../util/api/AbortError.js";
|
4
5
|
import { runSafe } from "../util/runSafe.js";
|
5
|
-
import { ModelCallEventSource } from "./ModelCallEventSource.js";
|
6
6
|
export async function executeCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
|
7
7
|
if (options?.settings != null) {
|
8
8
|
model = model.withSettings(options.settings);
|
@@ -13,7 +13,7 @@ export async function executeCall({ model, options, getStartEvent, getAbortEvent
|
|
13
13
|
}
|
14
14
|
const run = options?.run;
|
15
15
|
const settings = model.settings;
|
16
|
-
const eventSource = new
|
16
|
+
const eventSource = new RunFunctionEventSource({
|
17
17
|
observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
|
18
18
|
errorHandler: run?.errorHandler,
|
19
19
|
});
|
@@ -27,7 +27,7 @@ export async function executeCall({ model, options, getStartEvent, getAbortEvent
|
|
27
27
|
model: model.modelInformation,
|
28
28
|
startEpochSeconds: durationMeasurement.startEpochSeconds,
|
29
29
|
};
|
30
|
-
eventSource.
|
30
|
+
eventSource.notifyRunFunctionStarted(getStartEvent(startMetadata, settings));
|
31
31
|
const result = await runSafe(() => generateResponse({
|
32
32
|
functionId: options?.functionId,
|
33
33
|
settings,
|
@@ -39,15 +39,15 @@ export async function executeCall({ model, options, getStartEvent, getAbortEvent
|
|
39
39
|
};
|
40
40
|
if (!result.ok) {
|
41
41
|
if (result.isAborted) {
|
42
|
-
eventSource.
|
42
|
+
eventSource.notifyRunFunctionFinished(getAbortEvent(finishMetadata, settings));
|
43
43
|
throw new AbortError();
|
44
44
|
}
|
45
|
-
eventSource.
|
45
|
+
eventSource.notifyRunFunctionFinished(getFailureEvent(finishMetadata, settings, result.error));
|
46
46
|
throw result.error;
|
47
47
|
}
|
48
48
|
const response = result.output;
|
49
49
|
const output = extractOutputValue(response);
|
50
|
-
eventSource.
|
50
|
+
eventSource.notifyRunFunctionFinished(getSuccessEvent(finishMetadata, settings, response, output));
|
51
51
|
return {
|
52
52
|
output,
|
53
53
|
response,
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
|
2
2
|
export type JsonGenerationStartedEvent = {
|
3
|
-
type: "json-generation-started";
|
3
|
+
type: "json-generation-started" | "json-or-text-generation-started";
|
4
4
|
metadata: ModelCallStartedEventMetadata;
|
5
5
|
settings: unknown;
|
6
6
|
prompt: unknown;
|
7
7
|
};
|
8
8
|
export type JsonGenerationFinishedEvent = {
|
9
|
-
type: "json-generation-finished";
|
9
|
+
type: "json-generation-finished" | "json-or-text-generation-finished";
|
10
10
|
metadata: ModelCallFinishedEventMetadata;
|
11
11
|
settings: unknown;
|
12
12
|
prompt: unknown;
|
@@ -35,20 +35,20 @@ async function generateJsonOrText(model, schemaDefinitions, prompt, options) {
|
|
35
35
|
};
|
36
36
|
},
|
37
37
|
getStartEvent: (metadata, settings) => ({
|
38
|
-
type: "json-generation-started",
|
38
|
+
type: "json-or-text-generation-started",
|
39
39
|
metadata,
|
40
40
|
settings,
|
41
41
|
prompt,
|
42
42
|
}),
|
43
43
|
getAbortEvent: (metadata, settings) => ({
|
44
|
-
type: "json-generation-finished",
|
44
|
+
type: "json-or-text-generation-finished",
|
45
45
|
status: "abort",
|
46
46
|
metadata,
|
47
47
|
settings,
|
48
48
|
prompt,
|
49
49
|
}),
|
50
50
|
getFailureEvent: (metadata, settings, error) => ({
|
51
|
-
type: "json-generation-finished",
|
51
|
+
type: "json-or-text-generation-finished",
|
52
52
|
status: "failure",
|
53
53
|
metadata,
|
54
54
|
settings,
|
@@ -56,7 +56,7 @@ async function generateJsonOrText(model, schemaDefinitions, prompt, options) {
|
|
56
56
|
error,
|
57
57
|
}),
|
58
58
|
getSuccessEvent: (metadata, settings, response, output) => ({
|
59
|
-
type: "json-generation-finished",
|
59
|
+
type: "json-or-text-generation-finished",
|
60
60
|
status: "success",
|
61
61
|
metadata,
|
62
62
|
settings,
|
@@ -32,20 +32,20 @@ export async function generateJsonOrText(model, schemaDefinitions, prompt, optio
|
|
32
32
|
};
|
33
33
|
},
|
34
34
|
getStartEvent: (metadata, settings) => ({
|
35
|
-
type: "json-generation-started",
|
35
|
+
type: "json-or-text-generation-started",
|
36
36
|
metadata,
|
37
37
|
settings,
|
38
38
|
prompt,
|
39
39
|
}),
|
40
40
|
getAbortEvent: (metadata, settings) => ({
|
41
|
-
type: "json-generation-finished",
|
41
|
+
type: "json-or-text-generation-finished",
|
42
42
|
status: "abort",
|
43
43
|
metadata,
|
44
44
|
settings,
|
45
45
|
prompt,
|
46
46
|
}),
|
47
47
|
getFailureEvent: (metadata, settings, error) => ({
|
48
|
-
type: "json-generation-finished",
|
48
|
+
type: "json-or-text-generation-finished",
|
49
49
|
status: "failure",
|
50
50
|
metadata,
|
51
51
|
settings,
|
@@ -53,7 +53,7 @@ export async function generateJsonOrText(model, schemaDefinitions, prompt, optio
|
|
53
53
|
error,
|
54
54
|
}),
|
55
55
|
getSuccessEvent: (metadata, settings, response, output) => ({
|
56
|
-
type: "json-generation-finished",
|
56
|
+
type: "json-or-text-generation-finished",
|
57
57
|
status: "success",
|
58
58
|
metadata,
|
59
59
|
settings,
|
@@ -2,10 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.streamText = void 0;
|
4
4
|
const nanoid_1 = require("nanoid");
|
5
|
+
const RunFunctionEventSource_js_1 = require("../../run/RunFunctionEventSource.cjs");
|
5
6
|
const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
|
6
7
|
const AbortError_js_1 = require("../../util/api/AbortError.cjs");
|
7
8
|
const runSafe_js_1 = require("../../util/runSafe.cjs");
|
8
|
-
const ModelCallEventSource_js_1 = require("../ModelCallEventSource.cjs");
|
9
9
|
const extractTextDeltas_js_1 = require("./extractTextDeltas.cjs");
|
10
10
|
async function streamText(model, prompt, options) {
|
11
11
|
if (options?.settings != null) {
|
@@ -17,7 +17,7 @@ async function streamText(model, prompt, options) {
|
|
17
17
|
}
|
18
18
|
const run = options?.run;
|
19
19
|
const settings = model.settings;
|
20
|
-
const eventSource = new
|
20
|
+
const eventSource = new RunFunctionEventSource_js_1.RunFunctionEventSource({
|
21
21
|
observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
|
22
22
|
errorHandler: run?.errorHandler,
|
23
23
|
});
|
@@ -31,7 +31,7 @@ async function streamText(model, prompt, options) {
|
|
31
31
|
model: model.modelInformation,
|
32
32
|
startEpochSeconds: durationMeasurement.startEpochSeconds,
|
33
33
|
};
|
34
|
-
eventSource.
|
34
|
+
eventSource.notifyRunFunctionStarted({
|
35
35
|
type: "text-streaming-started",
|
36
36
|
metadata: startMetadata,
|
37
37
|
settings,
|
@@ -49,7 +49,7 @@ async function streamText(model, prompt, options) {
|
|
49
49
|
...startMetadata,
|
50
50
|
durationInMs: durationMeasurement.durationInMs,
|
51
51
|
};
|
52
|
-
eventSource.
|
52
|
+
eventSource.notifyRunFunctionFinished({
|
53
53
|
type: "text-streaming-finished",
|
54
54
|
status: "success",
|
55
55
|
metadata: finishMetadata,
|
@@ -64,7 +64,7 @@ async function streamText(model, prompt, options) {
|
|
64
64
|
...startMetadata,
|
65
65
|
durationInMs: durationMeasurement.durationInMs,
|
66
66
|
};
|
67
|
-
eventSource.
|
67
|
+
eventSource.notifyRunFunctionFinished(error instanceof AbortError_js_1.AbortError
|
68
68
|
? {
|
69
69
|
type: "text-streaming-finished",
|
70
70
|
status: "abort",
|
@@ -88,7 +88,7 @@ async function streamText(model, prompt, options) {
|
|
88
88
|
durationInMs: durationMeasurement.durationInMs,
|
89
89
|
};
|
90
90
|
if (result.isAborted) {
|
91
|
-
eventSource.
|
91
|
+
eventSource.notifyRunFunctionFinished({
|
92
92
|
type: "text-streaming-finished",
|
93
93
|
status: "abort",
|
94
94
|
metadata: finishMetadata,
|
@@ -97,7 +97,7 @@ async function streamText(model, prompt, options) {
|
|
97
97
|
});
|
98
98
|
throw new AbortError_js_1.AbortError();
|
99
99
|
}
|
100
|
-
eventSource.
|
100
|
+
eventSource.notifyRunFunctionFinished({
|
101
101
|
type: "text-streaming-finished",
|
102
102
|
status: "failure",
|
103
103
|
metadata: finishMetadata,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { nanoid as createId } from "nanoid";
|
2
|
+
import { RunFunctionEventSource } from "../../run/RunFunctionEventSource.js";
|
2
3
|
import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
|
3
4
|
import { AbortError } from "../../util/api/AbortError.js";
|
4
5
|
import { runSafe } from "../../util/runSafe.js";
|
5
|
-
import { ModelCallEventSource } from "../ModelCallEventSource.js";
|
6
6
|
import { extractTextDeltas } from "./extractTextDeltas.js";
|
7
7
|
export async function streamText(model, prompt, options) {
|
8
8
|
if (options?.settings != null) {
|
@@ -14,7 +14,7 @@ export async function streamText(model, prompt, options) {
|
|
14
14
|
}
|
15
15
|
const run = options?.run;
|
16
16
|
const settings = model.settings;
|
17
|
-
const eventSource = new
|
17
|
+
const eventSource = new RunFunctionEventSource({
|
18
18
|
observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
|
19
19
|
errorHandler: run?.errorHandler,
|
20
20
|
});
|
@@ -28,7 +28,7 @@ export async function streamText(model, prompt, options) {
|
|
28
28
|
model: model.modelInformation,
|
29
29
|
startEpochSeconds: durationMeasurement.startEpochSeconds,
|
30
30
|
};
|
31
|
-
eventSource.
|
31
|
+
eventSource.notifyRunFunctionStarted({
|
32
32
|
type: "text-streaming-started",
|
33
33
|
metadata: startMetadata,
|
34
34
|
settings,
|
@@ -46,7 +46,7 @@ export async function streamText(model, prompt, options) {
|
|
46
46
|
...startMetadata,
|
47
47
|
durationInMs: durationMeasurement.durationInMs,
|
48
48
|
};
|
49
|
-
eventSource.
|
49
|
+
eventSource.notifyRunFunctionFinished({
|
50
50
|
type: "text-streaming-finished",
|
51
51
|
status: "success",
|
52
52
|
metadata: finishMetadata,
|
@@ -61,7 +61,7 @@ export async function streamText(model, prompt, options) {
|
|
61
61
|
...startMetadata,
|
62
62
|
durationInMs: durationMeasurement.durationInMs,
|
63
63
|
};
|
64
|
-
eventSource.
|
64
|
+
eventSource.notifyRunFunctionFinished(error instanceof AbortError
|
65
65
|
? {
|
66
66
|
type: "text-streaming-finished",
|
67
67
|
status: "abort",
|
@@ -85,7 +85,7 @@ export async function streamText(model, prompt, options) {
|
|
85
85
|
durationInMs: durationMeasurement.durationInMs,
|
86
86
|
};
|
87
87
|
if (result.isAborted) {
|
88
|
-
eventSource.
|
88
|
+
eventSource.notifyRunFunctionFinished({
|
89
89
|
type: "text-streaming-finished",
|
90
90
|
status: "abort",
|
91
91
|
metadata: finishMetadata,
|
@@ -94,7 +94,7 @@ export async function streamText(model, prompt, options) {
|
|
94
94
|
});
|
95
95
|
throw new AbortError();
|
96
96
|
}
|
97
|
-
eventSource.
|
97
|
+
eventSource.notifyRunFunctionFinished({
|
98
98
|
type: "text-streaming-finished",
|
99
99
|
status: "failure",
|
100
100
|
metadata: finishMetadata,
|
package/model-function/index.cjs
CHANGED
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./FunctionOptions.cjs"), exports);
|
18
18
|
__exportStar(require("./Model.cjs"), exports);
|
19
19
|
__exportStar(require("./ModelCallEvent.cjs"), exports);
|
20
|
-
__exportStar(require("
|
20
|
+
__exportStar(require("../run/RunFunctionObserver.cjs"), exports);
|
21
21
|
__exportStar(require("./ModelInformation.cjs"), exports);
|
22
22
|
__exportStar(require("./SuccessfulModelCall.cjs"), exports);
|
23
23
|
__exportStar(require("./embed-text/TextEmbeddingEvent.cjs"), exports);
|
@@ -1,7 +1,7 @@
|
|
1
1
|
export * from "./FunctionOptions.js";
|
2
2
|
export * from "./Model.js";
|
3
3
|
export * from "./ModelCallEvent.js";
|
4
|
-
export * from "
|
4
|
+
export * from "../run/RunFunctionObserver.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./SuccessfulModelCall.js";
|
7
7
|
export * from "./embed-text/TextEmbeddingEvent.js";
|
package/model-function/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export * from "./FunctionOptions.js";
|
2
2
|
export * from "./Model.js";
|
3
3
|
export * from "./ModelCallEvent.js";
|
4
|
-
export * from "
|
4
|
+
export * from "../run/RunFunctionObserver.js";
|
5
5
|
export * from "./ModelInformation.js";
|
6
6
|
export * from "./SuccessfulModelCall.js";
|
7
7
|
export * from "./embed-text/TextEmbeddingEvent.js";
|
@@ -15,8 +15,8 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
|
|
15
15
|
get modelName(): string;
|
16
16
|
callAPI(input: A111ImageGenerationPrompt, options?: FunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<Automatic1111ImageGenerationResponse>;
|
17
17
|
generateImageResponse(prompt: A111ImageGenerationPrompt, options?: FunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<{
|
18
|
-
parameters: {};
|
19
18
|
images: string[];
|
19
|
+
parameters: {};
|
20
20
|
info: string;
|
21
21
|
}>;
|
22
22
|
extractBase64Image(response: Automatic1111ImageGenerationResponse): string;
|
@@ -37,12 +37,12 @@ declare const Automatic1111ImageGenerationResponseSchema: z.ZodObject<{
|
|
37
37
|
parameters: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
|
38
38
|
info: z.ZodString;
|
39
39
|
}, "strip", z.ZodTypeAny, {
|
40
|
-
parameters: {};
|
41
40
|
images: string[];
|
41
|
+
parameters: {};
|
42
42
|
info: string;
|
43
43
|
}, {
|
44
|
-
parameters: {};
|
45
44
|
images: string[];
|
45
|
+
parameters: {};
|
46
46
|
info: string;
|
47
47
|
}>;
|
48
48
|
export type Automatic1111ImageGenerationResponse = z.infer<typeof Automatic1111ImageGenerationResponseSchema>;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import z from "zod";
|
2
|
-
import { Tool } from "../../../composed-function/use-tool/Tool.js";
|
3
2
|
import { GenerateJsonPrompt } from "../../../model-function/generate-json/GenerateJsonModel.js";
|
4
3
|
import { GenerateJsonOrTextPrompt } from "../../../model-function/generate-json/GenerateJsonOrTextModel.js";
|
5
4
|
import { SchemaDefinition } from "../../../model-function/generate-json/SchemaDefinition.js";
|
5
|
+
import { Tool } from "../../../tool/Tool.js";
|
6
6
|
import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
|
7
7
|
import { OpenAIChatResponse } from "./OpenAIChatModel.js";
|
8
8
|
export type OpenAIFunctionDescription<T> = {
|
package/package.json
CHANGED
package/run/ConsoleLogger.cjs
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ConsoleLogger = void 0;
|
4
4
|
class ConsoleLogger {
|
5
|
-
|
5
|
+
onRunFunctionStarted(event) {
|
6
6
|
console.log(JSON.stringify(event, null, 2));
|
7
7
|
}
|
8
|
-
|
8
|
+
onRunFunctionFinished(event) {
|
9
9
|
console.log(JSON.stringify(event, null, 2));
|
10
10
|
}
|
11
11
|
}
|
package/run/ConsoleLogger.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
export declare class ConsoleLogger implements
|
4
|
-
|
5
|
-
|
1
|
+
import { RunFunctionFinishedEvent, RunFunctionStartedEvent } from "./RunFunctionEvent.js";
|
2
|
+
import { RunFunctionObserver } from "./RunFunctionObserver.js";
|
3
|
+
export declare class ConsoleLogger implements RunFunctionObserver {
|
4
|
+
onRunFunctionStarted(event: RunFunctionStartedEvent): void;
|
5
|
+
onRunFunctionFinished(event: RunFunctionFinishedEvent): void;
|
6
6
|
}
|
package/run/ConsoleLogger.js
CHANGED