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.
Files changed (78) hide show
  1. package/README.md +14 -4
  2. package/composed-function/index.cjs +0 -3
  3. package/composed-function/index.d.ts +0 -3
  4. package/composed-function/index.js +0 -3
  5. package/index.cjs +1 -0
  6. package/index.d.ts +1 -0
  7. package/index.js +1 -0
  8. package/model-function/Model.d.ts +2 -2
  9. package/model-function/ModelCallEvent.d.ts +4 -6
  10. package/model-function/SuccessfulModelCall.cjs +6 -3
  11. package/model-function/SuccessfulModelCall.d.ts +3 -3
  12. package/model-function/SuccessfulModelCall.js +6 -3
  13. package/model-function/executeCall.cjs +6 -6
  14. package/model-function/executeCall.js +6 -6
  15. package/model-function/generate-json/JsonGenerationEvent.d.ts +2 -2
  16. package/model-function/generate-json/generateJsonOrText.cjs +4 -4
  17. package/model-function/generate-json/generateJsonOrText.js +4 -4
  18. package/model-function/generate-text/streamText.cjs +7 -7
  19. package/model-function/generate-text/streamText.js +7 -7
  20. package/model-function/index.cjs +1 -1
  21. package/model-function/index.d.ts +1 -1
  22. package/model-function/index.js +1 -1
  23. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  24. package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/run/ConsoleLogger.cjs +2 -2
  27. package/run/ConsoleLogger.d.ts +5 -5
  28. package/run/ConsoleLogger.js +2 -2
  29. package/run/DefaultRun.cjs +7 -7
  30. package/run/DefaultRun.d.ts +6 -6
  31. package/run/DefaultRun.js +7 -7
  32. package/run/Run.d.ts +2 -2
  33. package/run/RunFunction.d.ts +0 -4
  34. package/run/RunFunctionEvent.d.ts +12 -0
  35. package/{model-function/ModelCallEventSource.cjs → run/RunFunctionEventSource.cjs} +7 -7
  36. package/run/RunFunctionEventSource.d.ts +13 -0
  37. package/{model-function/ModelCallEventSource.js → run/RunFunctionEventSource.js} +5 -5
  38. package/run/RunFunctionObserver.cjs +2 -0
  39. package/run/RunFunctionObserver.d.ts +5 -0
  40. package/run/RunFunctionObserver.js +1 -0
  41. package/run/index.cjs +3 -0
  42. package/run/index.d.ts +3 -0
  43. package/run/index.js +3 -0
  44. package/tool/ExecuteToolEvent.cjs +2 -0
  45. package/tool/ExecuteToolEvent.d.ts +22 -0
  46. package/tool/ExecuteToolEvent.js +1 -0
  47. package/{composed-function/use-tool → tool}/Tool.cjs +31 -0
  48. package/tool/Tool.d.ts +42 -0
  49. package/tool/Tool.js +70 -0
  50. package/tool/ToolExecutionError.cjs +31 -0
  51. package/tool/ToolExecutionError.d.ts +11 -0
  52. package/tool/ToolExecutionError.js +27 -0
  53. package/tool/WebSearchTool.cjs +43 -0
  54. package/tool/WebSearchTool.d.ts +81 -0
  55. package/tool/WebSearchTool.js +39 -0
  56. package/tool/executeTool.cjs +79 -0
  57. package/tool/executeTool.d.ts +23 -0
  58. package/tool/executeTool.js +75 -0
  59. package/tool/index.cjs +23 -0
  60. package/tool/index.d.ts +7 -0
  61. package/tool/index.js +7 -0
  62. package/tool/useTool.cjs +33 -0
  63. package/tool/useTool.d.ts +15 -0
  64. package/tool/useTool.js +29 -0
  65. package/tool/useToolOrGenerateText.cjs +38 -0
  66. package/{composed-function/use-tool/useTool.d.ts → tool/useToolOrGenerateText.d.ts} +2 -15
  67. package/tool/useToolOrGenerateText.js +34 -0
  68. package/composed-function/use-tool/Tool.d.ts +0 -15
  69. package/composed-function/use-tool/Tool.js +0 -39
  70. package/composed-function/use-tool/useTool.cjs +0 -62
  71. package/composed-function/use-tool/useTool.js +0 -57
  72. package/model-function/ModelCallEventSource.d.ts +0 -13
  73. package/model-function/ModelCallObserver.d.ts +0 -5
  74. /package/{model-function/ModelCallObserver.cjs → run/RunFunctionEvent.cjs} +0 -0
  75. /package/{model-function/ModelCallObserver.js → run/RunFunctionEvent.js} +0 -0
  76. /package/{composed-function/use-tool → tool}/NoSuchToolError.cjs +0 -0
  77. /package/{composed-function/use-tool → tool}/NoSuchToolError.d.ts +0 -0
  78. /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 we are still exploring the API design. We welcome your feedback and suggestions.
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
- const { text, response, metadata } = await generateText(
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_, _OpenAI text-davinci-003_
450
+ > _terminal app_, _agent_, _BabyAGI_
441
451
 
442
- TypeScript implementation of the classic [BabyAGI](https://github.com/yoheinakajima/babyagi/blob/main/classic/babyagi.py) by [@yoheinakajima](https://twitter.com/yoheinakajima) without embeddings.
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
@@ -5,5 +5,6 @@ export * from "./model-provider/index.js";
5
5
  export * from "./prompt/index.js";
6
6
  export * from "./run/index.js";
7
7
  export * from "./text-chunk/index.js";
8
+ export * from "./tool/index.js";
8
9
  export * from "./util/index.js";
9
10
  export * from "./vector-index/index.js";
package/index.js CHANGED
@@ -5,5 +5,6 @@ export * from "./model-provider/index.js";
5
5
  export * from "./prompt/index.js";
6
6
  export * from "./run/index.js";
7
7
  export * from "./text-chunk/index.js";
8
+ export * from "./tool/index.js";
8
9
  export * from "./util/index.js";
9
10
  export * from "./vector-index/index.js";
@@ -1,7 +1,7 @@
1
1
  import { ModelInformation } from "./ModelInformation.js";
2
- import { ModelCallObserver } from "./ModelCallObserver.js";
2
+ import { RunFunctionObserver } from "../run/RunFunctionObserver.js";
3
3
  export interface ModelSettings {
4
- observers?: Array<ModelCallObserver>;
4
+ observers?: Array<RunFunctionObserver>;
5
5
  }
6
6
  export interface Model<SETTINGS> {
7
7
  modelInformation: ModelInformation;
@@ -1,4 +1,4 @@
1
- import { IdMetadata } from "../run/IdMetadata.js";
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 ModelCallEvent = ModelCallStartedEvent | ModelCallFinishedEvent;
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 = ModelCallStartedEventMetadata & {
16
- durationInMs: number;
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(modelCallEvents) {
5
- return modelCallEvents
6
- .filter((event) => "status" in event && event.status === "success")
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 { ModelCallFinishedEvent, ModelCallStartedEvent } from "./ModelCallEvent.js";
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(modelCallEvents: (ModelCallFinishedEvent | ModelCallStartedEvent)[]): SuccessfulModelCall[];
9
+ export declare function extractSuccessfulModelCalls(runFunctionEvents: RunFunctionEvent[]): SuccessfulModelCall[];
@@ -1,6 +1,8 @@
1
- export function extractSuccessfulModelCalls(modelCallEvents) {
2
- return modelCallEvents
3
- .filter((event) => "status" in event && event.status === "success")
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 ModelCallEventSource_js_1.ModelCallEventSource({
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.notifyModelCallStarted(getStartEvent(startMetadata, settings));
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.notifyModelCallFinished(getAbortEvent(finishMetadata, settings));
45
+ eventSource.notifyRunFunctionFinished(getAbortEvent(finishMetadata, settings));
46
46
  throw new AbortError_js_1.AbortError();
47
47
  }
48
- eventSource.notifyModelCallFinished(getFailureEvent(finishMetadata, settings, result.error));
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.notifyModelCallFinished(getSuccessEvent(finishMetadata, settings, response, output));
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 ModelCallEventSource({
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.notifyModelCallStarted(getStartEvent(startMetadata, settings));
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.notifyModelCallFinished(getAbortEvent(finishMetadata, settings));
42
+ eventSource.notifyRunFunctionFinished(getAbortEvent(finishMetadata, settings));
43
43
  throw new AbortError();
44
44
  }
45
- eventSource.notifyModelCallFinished(getFailureEvent(finishMetadata, settings, result.error));
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.notifyModelCallFinished(getSuccessEvent(finishMetadata, settings, response, output));
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 ModelCallEventSource_js_1.ModelCallEventSource({
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.notifyModelCallStarted({
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.notifyModelCallFinished({
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.notifyModelCallFinished(error instanceof AbortError_js_1.AbortError
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.notifyModelCallFinished({
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.notifyModelCallFinished({
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 ModelCallEventSource({
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.notifyModelCallStarted({
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.notifyModelCallFinished({
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.notifyModelCallFinished(error instanceof AbortError
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.notifyModelCallFinished({
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.notifyModelCallFinished({
97
+ eventSource.notifyRunFunctionFinished({
98
98
  type: "text-streaming-finished",
99
99
  status: "failure",
100
100
  metadata: finishMetadata,
@@ -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("./ModelCallObserver.cjs"), exports);
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 "./ModelCallObserver.js";
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";
@@ -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 "./ModelCallObserver.js";
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build AI applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.7.0",
4
+ "version": "0.9.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConsoleLogger = void 0;
4
4
  class ConsoleLogger {
5
- onModelCallStarted(event) {
5
+ onRunFunctionStarted(event) {
6
6
  console.log(JSON.stringify(event, null, 2));
7
7
  }
8
- onModelCallFinished(event) {
8
+ onRunFunctionFinished(event) {
9
9
  console.log(JSON.stringify(event, null, 2));
10
10
  }
11
11
  }
@@ -1,6 +1,6 @@
1
- import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
2
- import { ModelCallObserver } from "../model-function/ModelCallObserver.js";
3
- export declare class ConsoleLogger implements ModelCallObserver {
4
- onModelCallStarted(event: ModelCallStartedEvent): void;
5
- onModelCallFinished(event: ModelCallFinishedEvent): void;
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
  }
@@ -1,8 +1,8 @@
1
1
  export class ConsoleLogger {
2
- onModelCallStarted(event) {
2
+ onRunFunctionStarted(event) {
3
3
  console.log(JSON.stringify(event, null, 2));
4
4
  }
5
- onModelCallFinished(event) {
5
+ onRunFunctionFinished(event) {
6
6
  console.log(JSON.stringify(event, null, 2));
7
7
  }
8
8
  }