modelfusion 0.20.1 → 0.21.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 (128) hide show
  1. package/README.md +5 -7
  2. package/composed-function/summarize/SummarizationFunction.d.ts +3 -3
  3. package/model-function/Model.d.ts +5 -2
  4. package/model-function/ModelCallEvent.d.ts +3 -3
  5. package/model-function/ModelFunctionOptions.d.ts +4 -0
  6. package/model-function/SuccessfulModelCall.cjs +3 -15
  7. package/model-function/SuccessfulModelCall.d.ts +2 -2
  8. package/model-function/SuccessfulModelCall.js +3 -15
  9. package/model-function/embed-text/TextEmbeddingEvent.d.ts +6 -8
  10. package/model-function/embed-text/TextEmbeddingModel.d.ts +2 -2
  11. package/model-function/embed-text/embedText.cjs +16 -22
  12. package/model-function/embed-text/embedText.d.ts +3 -3
  13. package/model-function/embed-text/embedText.js +16 -22
  14. package/model-function/executeCall.cjs +30 -8
  15. package/model-function/executeCall.d.ts +16 -9
  16. package/model-function/executeCall.js +30 -8
  17. package/model-function/generate-image/ImageGenerationEvent.d.ts +6 -8
  18. package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
  19. package/model-function/generate-image/generateImage.cjs +8 -11
  20. package/model-function/generate-image/generateImage.d.ts +2 -2
  21. package/model-function/generate-image/generateImage.js +8 -11
  22. package/model-function/generate-json/GenerateJsonModel.d.ts +2 -2
  23. package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +2 -2
  24. package/model-function/generate-json/JsonGenerationEvent.d.ts +6 -8
  25. package/model-function/generate-json/JsonTextGenerationModel.d.ts +2 -2
  26. package/model-function/generate-json/generateJson.cjs +8 -11
  27. package/model-function/generate-json/generateJson.d.ts +2 -2
  28. package/model-function/generate-json/generateJson.js +8 -11
  29. package/model-function/generate-json/generateJsonOrText.cjs +8 -11
  30. package/model-function/generate-json/generateJsonOrText.d.ts +2 -2
  31. package/model-function/generate-json/generateJsonOrText.js +8 -11
  32. package/model-function/generate-text/TextGenerationEvent.d.ts +6 -8
  33. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  34. package/model-function/generate-text/TextStreamingEvent.d.ts +6 -8
  35. package/model-function/generate-text/generateText.cjs +8 -11
  36. package/model-function/generate-text/generateText.d.ts +2 -2
  37. package/model-function/generate-text/generateText.js +8 -11
  38. package/model-function/generate-text/streamText.cjs +38 -23
  39. package/model-function/generate-text/streamText.d.ts +5 -5
  40. package/model-function/generate-text/streamText.js +38 -23
  41. package/model-function/index.cjs +1 -1
  42. package/model-function/index.d.ts +1 -1
  43. package/model-function/index.js +1 -1
  44. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +6 -8
  45. package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +2 -2
  46. package/model-function/synthesize-speech/synthesizeSpeech.cjs +8 -10
  47. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
  48. package/model-function/synthesize-speech/synthesizeSpeech.js +8 -10
  49. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +6 -8
  50. package/model-function/transcribe-speech/TranscriptionModel.d.ts +2 -2
  51. package/model-function/transcribe-speech/transcribe.cjs +8 -11
  52. package/model-function/transcribe-speech/transcribe.d.ts +2 -2
  53. package/model-function/transcribe-speech/transcribe.js +8 -11
  54. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  55. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
  56. package/model-provider/cohere/CohereTextGenerationModel.d.ts +4 -4
  57. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
  58. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -3
  59. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
  60. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +3 -3
  61. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +4 -4
  62. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +3 -3
  63. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
  64. package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -4
  65. package/model-provider/openai/OpenAITranscriptionModel.d.ts +3 -3
  66. package/model-provider/openai/chat/OpenAIChatModel.d.ts +5 -5
  67. package/model-provider/stability/StabilityImageGenerationModel.d.ts +3 -3
  68. package/package.json +1 -1
  69. package/prompt/PromptFormatTextGenerationModel.d.ts +3 -3
  70. package/run/ConsoleLogger.cjs +1 -4
  71. package/run/ConsoleLogger.d.ts +4 -5
  72. package/run/ConsoleLogger.js +1 -4
  73. package/run/DefaultRun.cjs +1 -4
  74. package/run/DefaultRun.d.ts +5 -5
  75. package/run/DefaultRun.js +1 -4
  76. package/run/FunctionEvent.d.ts +51 -0
  77. package/run/{RunFunctionEventSource.js → FunctionEventSource.cjs} +7 -13
  78. package/run/FunctionEventSource.d.ts +12 -0
  79. package/run/{RunFunctionEventSource.cjs → FunctionEventSource.js} +3 -17
  80. package/run/FunctionObserver.d.ts +7 -0
  81. package/run/FunctionOptions.d.ts +19 -0
  82. package/run/GlobalFunctionObservers.cjs +12 -0
  83. package/run/GlobalFunctionObservers.d.ts +3 -0
  84. package/run/GlobalFunctionObservers.js +7 -0
  85. package/run/Run.d.ts +2 -2
  86. package/run/index.cjs +5 -5
  87. package/run/index.d.ts +5 -5
  88. package/run/index.js +5 -5
  89. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -0
  90. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.d.ts +2 -2
  91. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -0
  92. package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +2 -2
  93. package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +2 -2
  94. package/text-chunk/split/SplitFunction.d.ts +3 -3
  95. package/text-chunk/upsertTextChunks.d.ts +2 -2
  96. package/tool/ExecuteToolEvent.d.ts +6 -8
  97. package/tool/Tool.d.ts +3 -3
  98. package/tool/WebSearchTool.d.ts +2 -1
  99. package/tool/executeTool.cjs +28 -26
  100. package/tool/executeTool.d.ts +5 -4
  101. package/tool/executeTool.js +28 -26
  102. package/tool/useTool.cjs +2 -6
  103. package/tool/useTool.d.ts +2 -2
  104. package/tool/useTool.js +2 -6
  105. package/tool/useToolOrGenerateText.cjs +1 -3
  106. package/tool/useToolOrGenerateText.d.ts +2 -2
  107. package/tool/useToolOrGenerateText.js +1 -3
  108. package/util/DurationMeasurement.cjs +6 -0
  109. package/util/DurationMeasurement.d.ts +1 -0
  110. package/util/DurationMeasurement.js +6 -0
  111. package/util/api/postToApi.cjs +8 -0
  112. package/util/api/postToApi.js +8 -0
  113. package/model-function/FunctionOptions.d.ts +0 -6
  114. package/run/IdMetadata.d.ts +0 -7
  115. package/run/RunFunction.d.ts +0 -9
  116. package/run/RunFunctionEvent.d.ts +0 -12
  117. package/run/RunFunctionEventSource.d.ts +0 -13
  118. package/run/RunFunctionObserver.cjs +0 -2
  119. package/run/RunFunctionObserver.d.ts +0 -5
  120. package/run/RunFunctionObserver.js +0 -1
  121. /package/model-function/{FunctionOptions.cjs → ModelFunctionOptions.cjs} +0 -0
  122. /package/model-function/{FunctionOptions.js → ModelFunctionOptions.js} +0 -0
  123. /package/run/{IdMetadata.cjs → FunctionEvent.cjs} +0 -0
  124. /package/run/{IdMetadata.js → FunctionEvent.js} +0 -0
  125. /package/run/{RunFunction.cjs → FunctionObserver.cjs} +0 -0
  126. /package/run/{RunFunction.js → FunctionObserver.js} +0 -0
  127. /package/run/{RunFunctionEvent.cjs → FunctionOptions.cjs} +0 -0
  128. /package/run/{RunFunctionEvent.js → FunctionOptions.js} +0 -0
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.streamText = exports.StreamTextPromise = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
- const RunFunctionEventSource_js_1 = require("../../run/RunFunctionEventSource.cjs");
5
+ const FunctionEventSource_js_1 = require("../../run/FunctionEventSource.cjs");
6
+ const GlobalFunctionObservers_js_1 = require("../../run/GlobalFunctionObservers.cjs");
6
7
  const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
7
8
  const AbortError_js_1 = require("../../util/api/AbortError.cjs");
8
9
  const runSafe_js_1 = require("../../util/runSafe.cjs");
@@ -50,13 +51,19 @@ async function doStreamText(model, prompt, options) {
50
51
  model = model.withSettings(options.settings);
51
52
  options = {
52
53
  functionId: options.functionId,
54
+ observers: options.observers,
53
55
  run: options.run,
54
56
  };
55
57
  }
56
58
  const run = options?.run;
57
59
  const settings = model.settings;
58
- const eventSource = new RunFunctionEventSource_js_1.RunFunctionEventSource({
59
- observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
60
+ const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
61
+ observers: [
62
+ ...(0, GlobalFunctionObservers_js_1.getGlobalFunctionObservers)(),
63
+ ...(settings.observers ?? []),
64
+ ...(run?.observers ?? []),
65
+ ...(options?.observers ?? []),
66
+ ],
60
67
  errorHandler: run?.errorHandler,
61
68
  });
62
69
  const durationMeasurement = (0, DurationMeasurement_js_1.startDurationMeasurement)();
@@ -67,11 +74,13 @@ async function doStreamText(model, prompt, options) {
67
74
  userId: run?.userId,
68
75
  functionId: options?.functionId,
69
76
  model: model.modelInformation,
70
- startEpochSeconds: durationMeasurement.startEpochSeconds,
77
+ timestamp: durationMeasurement.startDate,
78
+ startTimestamp: durationMeasurement.startDate,
71
79
  };
72
- eventSource.notifyRunFunctionStarted({
73
- type: "text-streaming-started",
74
- metadata: startMetadata,
80
+ eventSource.notify({
81
+ ...startMetadata,
82
+ functionType: "text-streaming",
83
+ eventType: "started",
75
84
  settings,
76
85
  prompt,
77
86
  });
@@ -85,12 +94,14 @@ async function doStreamText(model, prompt, options) {
85
94
  onDone: (fullText, lastFullDelta) => {
86
95
  const finishMetadata = {
87
96
  ...startMetadata,
97
+ eventType: "finished",
98
+ finishTimestamp: new Date(),
88
99
  durationInMs: durationMeasurement.durationInMs,
89
100
  };
90
- eventSource.notifyRunFunctionFinished({
91
- type: "text-streaming-finished",
101
+ eventSource.notify({
102
+ ...finishMetadata,
103
+ functionType: "text-streaming",
92
104
  status: "success",
93
- metadata: finishMetadata,
94
105
  settings,
95
106
  prompt,
96
107
  response: lastFullDelta,
@@ -100,20 +111,22 @@ async function doStreamText(model, prompt, options) {
100
111
  onError: (error) => {
101
112
  const finishMetadata = {
102
113
  ...startMetadata,
114
+ eventType: "finished",
115
+ finishTimestamp: new Date(),
103
116
  durationInMs: durationMeasurement.durationInMs,
104
117
  };
105
- eventSource.notifyRunFunctionFinished(error instanceof AbortError_js_1.AbortError
118
+ eventSource.notify(error instanceof AbortError_js_1.AbortError
106
119
  ? {
107
- type: "text-streaming-finished",
120
+ ...finishMetadata,
121
+ functionType: "text-streaming",
108
122
  status: "abort",
109
- metadata: finishMetadata,
110
123
  settings,
111
124
  prompt,
112
125
  }
113
126
  : {
114
- type: "text-streaming-finished",
115
- status: "failure",
116
- metadata: finishMetadata,
127
+ ...finishMetadata,
128
+ functionType: "text-streaming",
129
+ status: "error",
117
130
  settings,
118
131
  prompt,
119
132
  error,
@@ -123,22 +136,24 @@ async function doStreamText(model, prompt, options) {
123
136
  if (!result.ok) {
124
137
  const finishMetadata = {
125
138
  ...startMetadata,
139
+ eventType: "finished",
140
+ finishTimestamp: new Date(),
126
141
  durationInMs: durationMeasurement.durationInMs,
127
142
  };
128
143
  if (result.isAborted) {
129
- eventSource.notifyRunFunctionFinished({
130
- type: "text-streaming-finished",
144
+ eventSource.notify({
145
+ ...finishMetadata,
146
+ functionType: "text-streaming",
131
147
  status: "abort",
132
- metadata: finishMetadata,
133
148
  settings,
134
149
  prompt,
135
150
  });
136
151
  throw new AbortError_js_1.AbortError();
137
152
  }
138
- eventSource.notifyRunFunctionFinished({
139
- type: "text-streaming-finished",
140
- status: "failure",
141
- metadata: finishMetadata,
153
+ eventSource.notify({
154
+ ...finishMetadata,
155
+ functionType: "text-streaming",
156
+ status: "error",
142
157
  settings,
143
158
  prompt,
144
159
  error: result.error,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { CallMetadata } from "../executeCall.js";
3
3
  import { DeltaEvent } from "./DeltaEvent.js";
4
4
  import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
@@ -7,17 +7,17 @@ export declare class StreamTextPromise<PROMPT, FULL_DELTA, SETTINGS extends Text
7
7
  private outputPromise;
8
8
  constructor(fullPromise: Promise<{
9
9
  output: AsyncIterable<string>;
10
- metadata: Omit<CallMetadata<TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS>>, "durationInMs">;
10
+ metadata: Omit<CallMetadata<TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS>>, "durationInMs" | "finishTimestamp">;
11
11
  }>);
12
12
  asFullResponse(): Promise<{
13
13
  output: AsyncIterable<string>;
14
- metadata: Omit<CallMetadata<TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS>>, "durationInMs">;
14
+ metadata: Omit<CallMetadata<TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS>>, "durationInMs" | "finishTimestamp">;
15
15
  }>;
16
16
  then<TResult1 = AsyncIterable<string>, TResult2 = never>(onfulfilled?: ((value: AsyncIterable<string>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
17
17
  catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<AsyncIterable<string> | TResult>;
18
18
  finally(onfinally?: (() => void) | undefined | null): Promise<AsyncIterable<string>>;
19
19
  }
20
20
  export declare function streamText<PROMPT, FULL_DELTA, SETTINGS extends TextGenerationModelSettings>(model: TextGenerationModel<PROMPT, unknown, FULL_DELTA, SETTINGS> & {
21
- generateDeltaStreamResponse: (prompt: PROMPT, options: FunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
21
+ generateDeltaStreamResponse: (prompt: PROMPT, options: ModelFunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
22
22
  extractTextDelta: (fullDelta: FULL_DELTA) => string | undefined;
23
- }, prompt: PROMPT, options?: FunctionOptions<SETTINGS>): StreamTextPromise<PROMPT, FULL_DELTA, SETTINGS>;
23
+ }, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): StreamTextPromise<PROMPT, FULL_DELTA, SETTINGS>;
@@ -1,5 +1,6 @@
1
1
  import { nanoid as createId } from "nanoid";
2
- import { RunFunctionEventSource } from "../../run/RunFunctionEventSource.js";
2
+ import { FunctionEventSource } from "../../run/FunctionEventSource.js";
3
+ import { getGlobalFunctionObservers } from "../../run/GlobalFunctionObservers.js";
3
4
  import { startDurationMeasurement } from "../../util/DurationMeasurement.js";
4
5
  import { AbortError } from "../../util/api/AbortError.js";
5
6
  import { runSafe } from "../../util/runSafe.js";
@@ -45,13 +46,19 @@ async function doStreamText(model, prompt, options) {
45
46
  model = model.withSettings(options.settings);
46
47
  options = {
47
48
  functionId: options.functionId,
49
+ observers: options.observers,
48
50
  run: options.run,
49
51
  };
50
52
  }
51
53
  const run = options?.run;
52
54
  const settings = model.settings;
53
- const eventSource = new RunFunctionEventSource({
54
- observers: [...(settings.observers ?? []), ...(run?.observers ?? [])],
55
+ const eventSource = new FunctionEventSource({
56
+ observers: [
57
+ ...getGlobalFunctionObservers(),
58
+ ...(settings.observers ?? []),
59
+ ...(run?.observers ?? []),
60
+ ...(options?.observers ?? []),
61
+ ],
55
62
  errorHandler: run?.errorHandler,
56
63
  });
57
64
  const durationMeasurement = startDurationMeasurement();
@@ -62,11 +69,13 @@ async function doStreamText(model, prompt, options) {
62
69
  userId: run?.userId,
63
70
  functionId: options?.functionId,
64
71
  model: model.modelInformation,
65
- startEpochSeconds: durationMeasurement.startEpochSeconds,
72
+ timestamp: durationMeasurement.startDate,
73
+ startTimestamp: durationMeasurement.startDate,
66
74
  };
67
- eventSource.notifyRunFunctionStarted({
68
- type: "text-streaming-started",
69
- metadata: startMetadata,
75
+ eventSource.notify({
76
+ ...startMetadata,
77
+ functionType: "text-streaming",
78
+ eventType: "started",
70
79
  settings,
71
80
  prompt,
72
81
  });
@@ -80,12 +89,14 @@ async function doStreamText(model, prompt, options) {
80
89
  onDone: (fullText, lastFullDelta) => {
81
90
  const finishMetadata = {
82
91
  ...startMetadata,
92
+ eventType: "finished",
93
+ finishTimestamp: new Date(),
83
94
  durationInMs: durationMeasurement.durationInMs,
84
95
  };
85
- eventSource.notifyRunFunctionFinished({
86
- type: "text-streaming-finished",
96
+ eventSource.notify({
97
+ ...finishMetadata,
98
+ functionType: "text-streaming",
87
99
  status: "success",
88
- metadata: finishMetadata,
89
100
  settings,
90
101
  prompt,
91
102
  response: lastFullDelta,
@@ -95,20 +106,22 @@ async function doStreamText(model, prompt, options) {
95
106
  onError: (error) => {
96
107
  const finishMetadata = {
97
108
  ...startMetadata,
109
+ eventType: "finished",
110
+ finishTimestamp: new Date(),
98
111
  durationInMs: durationMeasurement.durationInMs,
99
112
  };
100
- eventSource.notifyRunFunctionFinished(error instanceof AbortError
113
+ eventSource.notify(error instanceof AbortError
101
114
  ? {
102
- type: "text-streaming-finished",
115
+ ...finishMetadata,
116
+ functionType: "text-streaming",
103
117
  status: "abort",
104
- metadata: finishMetadata,
105
118
  settings,
106
119
  prompt,
107
120
  }
108
121
  : {
109
- type: "text-streaming-finished",
110
- status: "failure",
111
- metadata: finishMetadata,
122
+ ...finishMetadata,
123
+ functionType: "text-streaming",
124
+ status: "error",
112
125
  settings,
113
126
  prompt,
114
127
  error,
@@ -118,22 +131,24 @@ async function doStreamText(model, prompt, options) {
118
131
  if (!result.ok) {
119
132
  const finishMetadata = {
120
133
  ...startMetadata,
134
+ eventType: "finished",
135
+ finishTimestamp: new Date(),
121
136
  durationInMs: durationMeasurement.durationInMs,
122
137
  };
123
138
  if (result.isAborted) {
124
- eventSource.notifyRunFunctionFinished({
125
- type: "text-streaming-finished",
139
+ eventSource.notify({
140
+ ...finishMetadata,
141
+ functionType: "text-streaming",
126
142
  status: "abort",
127
- metadata: finishMetadata,
128
143
  settings,
129
144
  prompt,
130
145
  });
131
146
  throw new AbortError();
132
147
  }
133
- eventSource.notifyRunFunctionFinished({
134
- type: "text-streaming-finished",
135
- status: "failure",
136
- metadata: finishMetadata,
148
+ eventSource.notify({
149
+ ...finishMetadata,
150
+ functionType: "text-streaming",
151
+ status: "error",
137
152
  settings,
138
153
  prompt,
139
154
  error: result.error,
@@ -14,9 +14,9 @@ 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("./FunctionOptions.cjs"), exports);
18
17
  __exportStar(require("./Model.cjs"), exports);
19
18
  __exportStar(require("./ModelCallEvent.cjs"), exports);
19
+ __exportStar(require("./ModelFunctionOptions.cjs"), exports);
20
20
  __exportStar(require("./ModelInformation.cjs"), exports);
21
21
  __exportStar(require("./SuccessfulModelCall.cjs"), exports);
22
22
  __exportStar(require("./embed-text/TextEmbeddingEvent.cjs"), exports);
@@ -1,6 +1,6 @@
1
- export * from "./FunctionOptions.js";
2
1
  export * from "./Model.js";
3
2
  export * from "./ModelCallEvent.js";
3
+ export * from "./ModelFunctionOptions.js";
4
4
  export * from "./ModelInformation.js";
5
5
  export * from "./SuccessfulModelCall.js";
6
6
  export * from "./embed-text/TextEmbeddingEvent.js";
@@ -1,6 +1,6 @@
1
- export * from "./FunctionOptions.js";
2
1
  export * from "./Model.js";
3
2
  export * from "./ModelCallEvent.js";
3
+ export * from "./ModelFunctionOptions.js";
4
4
  export * from "./ModelInformation.js";
5
5
  export * from "./SuccessfulModelCall.js";
6
6
  export * from "./embed-text/TextEmbeddingEvent.js";
@@ -1,21 +1,19 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
3
- export type SpeechSynthesisStartedEvent = {
4
- type: "speech-synthesis-started";
5
- metadata: ModelCallStartedEventMetadata;
2
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
3
+ export type SpeechSynthesisStartedEvent = BaseModelCallStartedEvent & {
4
+ functionType: "speech-synthesis";
6
5
  settings: unknown;
7
6
  text: string;
8
7
  };
9
- export type SpeechSynthesisFinishedEvent = {
10
- type: "speech-synthesis-finished";
11
- metadata: ModelCallFinishedEventMetadata;
8
+ export type SpeechSynthesisFinishedEvent = BaseModelCallFinishedEvent & {
9
+ functionType: "speech-synthesis";
12
10
  settings: unknown;
13
11
  text: string;
14
12
  } & ({
15
13
  status: "success";
16
14
  response: Buffer;
17
15
  } | {
18
- status: "failure";
16
+ status: "error";
19
17
  error: unknown;
20
18
  } | {
21
19
  status: "abort";
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { FunctionOptions } from "../FunctionOptions.js";
2
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
3
3
  import { Model, ModelSettings } from "../Model.js";
4
4
  export interface SpeechSynthesisModelSettings extends ModelSettings {
5
5
  }
@@ -7,5 +7,5 @@ export interface SpeechSynthesisModel<SETTINGS> extends Model<SETTINGS> {
7
7
  /**
8
8
  * Generates an mp3 audio buffer that contains the speech for the given text.
9
9
  */
10
- generateSpeechResponse: (text: string, options?: FunctionOptions<SETTINGS>) => PromiseLike<Buffer>;
10
+ generateSpeechResponse: (text: string, options?: ModelFunctionOptions<SETTINGS>) => PromiseLike<Buffer>;
11
11
  }
@@ -12,30 +12,28 @@ function synthesizeSpeech(model, text, options) {
12
12
  generateResponse: (options) => model.generateSpeechResponse(text, options),
13
13
  extractOutputValue: (buffer) => buffer,
14
14
  getStartEvent: (metadata, settings) => ({
15
- type: "speech-synthesis-started",
16
- metadata,
15
+ ...metadata,
16
+ functionType: "speech-synthesis",
17
17
  settings,
18
18
  text,
19
19
  }),
20
20
  getAbortEvent: (metadata, settings) => ({
21
- type: "speech-synthesis-finished",
21
+ ...metadata,
22
+ functionType: "speech-synthesis",
22
23
  status: "abort",
23
24
  settings,
24
- metadata,
25
25
  text,
26
26
  }),
27
27
  getFailureEvent: (metadata, settings, error) => ({
28
- type: "speech-synthesis-finished",
29
- status: "failure",
30
- metadata,
28
+ ...metadata,
29
+ functionType: "speech-synthesis",
31
30
  settings,
32
31
  text,
33
32
  error,
34
33
  }),
35
34
  getSuccessEvent: (metadata, settings, response, output) => ({
36
- type: "speech-synthesis-finished",
37
- status: "success",
38
- metadata,
35
+ ...metadata,
36
+ functionType: "speech-synthesis",
39
37
  settings,
40
38
  text,
41
39
  response,
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import { FunctionOptions } from "../FunctionOptions.js";
2
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
3
3
  import { ModelFunctionPromise } from "../executeCall.js";
4
4
  import { SpeechSynthesisModel, SpeechSynthesisModelSettings } from "./SpeechSynthesisModel.js";
5
5
  /**
6
6
  * Synthesizes speech from text.
7
7
  */
8
- export declare function synthesizeSpeech<SETTINGS extends SpeechSynthesisModelSettings>(model: SpeechSynthesisModel<SETTINGS>, text: string, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<SpeechSynthesisModel<SETTINGS>, Buffer, Buffer>;
8
+ export declare function synthesizeSpeech<SETTINGS extends SpeechSynthesisModelSettings>(model: SpeechSynthesisModel<SETTINGS>, text: string, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<SpeechSynthesisModel<SETTINGS>, Buffer, Buffer>;
@@ -9,30 +9,28 @@ export function synthesizeSpeech(model, text, options) {
9
9
  generateResponse: (options) => model.generateSpeechResponse(text, options),
10
10
  extractOutputValue: (buffer) => buffer,
11
11
  getStartEvent: (metadata, settings) => ({
12
- type: "speech-synthesis-started",
13
- metadata,
12
+ ...metadata,
13
+ functionType: "speech-synthesis",
14
14
  settings,
15
15
  text,
16
16
  }),
17
17
  getAbortEvent: (metadata, settings) => ({
18
- type: "speech-synthesis-finished",
18
+ ...metadata,
19
+ functionType: "speech-synthesis",
19
20
  status: "abort",
20
21
  settings,
21
- metadata,
22
22
  text,
23
23
  }),
24
24
  getFailureEvent: (metadata, settings, error) => ({
25
- type: "speech-synthesis-finished",
26
- status: "failure",
27
- metadata,
25
+ ...metadata,
26
+ functionType: "speech-synthesis",
28
27
  settings,
29
28
  text,
30
29
  error,
31
30
  }),
32
31
  getSuccessEvent: (metadata, settings, response, output) => ({
33
- type: "speech-synthesis-finished",
34
- status: "success",
35
- metadata,
32
+ ...metadata,
33
+ functionType: "speech-synthesis",
36
34
  settings,
37
35
  text,
38
36
  response,
@@ -1,13 +1,11 @@
1
- import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
2
- export type TranscriptionStartedEvent = {
3
- type: "transcription-started";
4
- metadata: ModelCallStartedEventMetadata;
1
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
+ export type TranscriptionStartedEvent = BaseModelCallStartedEvent & {
3
+ functionType: "transcription";
5
4
  settings: unknown;
6
5
  data: unknown;
7
6
  };
8
- export type TranscriptionFinishedEvent = {
9
- type: "transcription-finished";
10
- metadata: ModelCallFinishedEventMetadata;
7
+ export type TranscriptionFinishedEvent = BaseModelCallFinishedEvent & {
8
+ functionType: "transcription";
11
9
  settings: unknown;
12
10
  data: unknown;
13
11
  } & ({
@@ -15,7 +13,7 @@ export type TranscriptionFinishedEvent = {
15
13
  response: unknown;
16
14
  transcription: string;
17
15
  } | {
18
- status: "failure";
16
+ status: "error";
19
17
  error: unknown;
20
18
  } | {
21
19
  status: "abort";
@@ -1,8 +1,8 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { Model, ModelSettings } from "../Model.js";
3
3
  export interface TranscriptionModelSettings extends ModelSettings {
4
4
  }
5
5
  export interface TranscriptionModel<DATA, RESPONSE, SETTINGS> extends Model<SETTINGS> {
6
- generateTranscriptionResponse: (data: DATA, options?: FunctionOptions<SETTINGS>) => PromiseLike<RESPONSE>;
6
+ generateTranscriptionResponse: (data: DATA, options?: ModelFunctionOptions<SETTINGS>) => PromiseLike<RESPONSE>;
7
7
  extractTranscriptionText: (response: RESPONSE) => string;
8
8
  }
@@ -23,30 +23,27 @@ function transcribe(model, data, options) {
23
23
  generateResponse: (options) => model.generateTranscriptionResponse(data, options),
24
24
  extractOutputValue: model.extractTranscriptionText,
25
25
  getStartEvent: (metadata, settings) => ({
26
- type: "transcription-started",
27
- metadata,
26
+ ...metadata,
27
+ functionType: "transcription",
28
28
  settings,
29
29
  data,
30
30
  }),
31
31
  getAbortEvent: (metadata, settings) => ({
32
- type: "transcription-finished",
33
- status: "abort",
32
+ ...metadata,
33
+ functionType: "transcription",
34
34
  settings,
35
- metadata,
36
35
  data,
37
36
  }),
38
37
  getFailureEvent: (metadata, settings, error) => ({
39
- type: "transcription-finished",
40
- status: "failure",
41
- metadata,
38
+ ...metadata,
39
+ functionType: "transcription",
42
40
  settings,
43
41
  data,
44
42
  error,
45
43
  }),
46
44
  getSuccessEvent: (metadata, settings, response, output) => ({
47
- type: "transcription-finished",
48
- status: "success",
49
- metadata,
45
+ ...metadata,
46
+ functionType: "transcription",
50
47
  settings,
51
48
  data,
52
49
  response,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { ModelFunctionPromise } from "../executeCall.js";
3
3
  import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionModel.js";
4
4
  /**
@@ -15,4 +15,4 @@ import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionM
15
15
  * }
16
16
  * );
17
17
  */
18
- export declare function transcribe<DATA, RESPONSE, SETTINGS extends TranscriptionModelSettings>(model: TranscriptionModel<DATA, RESPONSE, SETTINGS>, data: DATA, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<TranscriptionModel<DATA, RESPONSE, SETTINGS>, string, RESPONSE>;
18
+ export declare function transcribe<DATA, RESPONSE, SETTINGS extends TranscriptionModelSettings>(model: TranscriptionModel<DATA, RESPONSE, SETTINGS>, data: DATA, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<TranscriptionModel<DATA, RESPONSE, SETTINGS>, string, RESPONSE>;
@@ -20,30 +20,27 @@ export function transcribe(model, data, options) {
20
20
  generateResponse: (options) => model.generateTranscriptionResponse(data, options),
21
21
  extractOutputValue: model.extractTranscriptionText,
22
22
  getStartEvent: (metadata, settings) => ({
23
- type: "transcription-started",
24
- metadata,
23
+ ...metadata,
24
+ functionType: "transcription",
25
25
  settings,
26
26
  data,
27
27
  }),
28
28
  getAbortEvent: (metadata, settings) => ({
29
- type: "transcription-finished",
30
- status: "abort",
29
+ ...metadata,
30
+ functionType: "transcription",
31
31
  settings,
32
- metadata,
33
32
  data,
34
33
  }),
35
34
  getFailureEvent: (metadata, settings, error) => ({
36
- type: "transcription-finished",
37
- status: "failure",
38
- metadata,
35
+ ...metadata,
36
+ functionType: "transcription",
39
37
  settings,
40
38
  data,
41
39
  error,
42
40
  }),
43
41
  getSuccessEvent: (metadata, settings, response, output) => ({
44
- type: "transcription-finished",
45
- status: "success",
46
- metadata,
42
+ ...metadata,
43
+ functionType: "transcription",
47
44
  settings,
48
45
  data,
49
46
  response,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
- import { FunctionOptions } from "../../model-function/FunctionOptions.js";
3
+ import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
4
4
  import { ImageGenerationModel, ImageGenerationModelSettings } from "../../model-function/generate-image/ImageGenerationModel.js";
5
5
  import { RetryFunction } from "../../util/api/RetryFunction.js";
6
6
  import { ThrottleFunction } from "../../util/api/ThrottleFunction.js";
@@ -13,8 +13,8 @@ export declare class Automatic1111ImageGenerationModel extends AbstractModel<Aut
13
13
  constructor(settings: Automatic1111ImageGenerationModelSettings);
14
14
  readonly provider: "Automatic1111";
15
15
  get modelName(): string;
16
- callAPI(input: A111ImageGenerationPrompt, options?: FunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<Automatic1111ImageGenerationResponse>;
17
- generateImageResponse(prompt: A111ImageGenerationPrompt, options?: FunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<{
16
+ callAPI(input: A111ImageGenerationPrompt, options?: ModelFunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<Automatic1111ImageGenerationResponse>;
17
+ generateImageResponse(prompt: A111ImageGenerationPrompt, options?: ModelFunctionOptions<Automatic1111ImageGenerationModelSettings>): Promise<{
18
18
  images: string[];
19
19
  parameters: {};
20
20
  info: string;
@@ -1,6 +1,6 @@
1
1
  import z from "zod";
2
2
  import { AbstractModel } from "../../model-function/AbstractModel.js";
3
- import { FunctionOptions } from "../../model-function/FunctionOptions.js";
3
+ import { ModelFunctionOptions } from "../../model-function/ModelFunctionOptions.js";
4
4
  import { TextEmbeddingModel, TextEmbeddingModelSettings } from "../../model-function/embed-text/TextEmbeddingModel.js";
5
5
  import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
6
6
  import { RetryFunction } from "../../util/api/RetryFunction.js";
@@ -61,8 +61,8 @@ export declare class CohereTextEmbeddingModel extends AbstractModel<CohereTextEm
61
61
  }>;
62
62
  detokenize(tokens: number[]): Promise<string>;
63
63
  private get apiKey();
64
- callAPI(texts: Array<string>, options?: FunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>;
65
- generateEmbeddingResponse(texts: string[], options?: FunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{
64
+ callAPI(texts: Array<string>, options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<CohereTextEmbeddingResponse>;
65
+ generateEmbeddingResponse(texts: string[], options?: ModelFunctionOptions<CohereTextEmbeddingModelSettings>): Promise<{
66
66
  texts: string[];
67
67
  id: string;
68
68
  meta: {