modelfusion 0.48.0 → 0.50.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 (149) hide show
  1. package/README.md +186 -183
  2. package/core/FunctionEvent.d.ts +9 -1
  3. package/core/FunctionOptions.d.ts +4 -0
  4. package/core/executeFunctionCall.cjs +85 -0
  5. package/core/executeFunctionCall.d.ts +10 -0
  6. package/core/executeFunctionCall.js +81 -0
  7. package/guard/GuardEvent.d.ts +7 -0
  8. package/guard/guard.cjs +60 -54
  9. package/guard/guard.d.ts +2 -1
  10. package/guard/guard.js +60 -54
  11. package/guard/index.cjs +1 -0
  12. package/guard/index.d.ts +1 -0
  13. package/guard/index.js +1 -0
  14. package/model-function/AsyncIterableResultPromise.cjs +5 -5
  15. package/model-function/AsyncIterableResultPromise.d.ts +3 -3
  16. package/model-function/AsyncIterableResultPromise.js +5 -5
  17. package/model-function/Model.d.ts +1 -1
  18. package/model-function/ModelCallEvent.d.ts +5 -7
  19. package/model-function/embed/EmbeddingEvent.d.ts +2 -2
  20. package/model-function/embed/embed.cjs +5 -5
  21. package/model-function/embed/embed.js +5 -5
  22. package/model-function/{executeCall.cjs → executeStandardCall.cjs} +5 -3
  23. package/model-function/{executeCall.d.ts → executeStandardCall.d.ts} +1 -1
  24. package/model-function/{executeCall.js → executeStandardCall.js} +3 -1
  25. package/model-function/executeStreamCall.cjs +134 -0
  26. package/model-function/executeStreamCall.d.ts +20 -0
  27. package/model-function/executeStreamCall.js +130 -0
  28. package/model-function/generate-image/ImageGenerationEvent.d.ts +2 -2
  29. package/model-function/generate-image/generateImage.cjs +3 -3
  30. package/model-function/generate-image/generateImage.js +3 -3
  31. package/model-function/generate-speech/SpeechGenerationEvent.d.ts +27 -0
  32. package/model-function/generate-speech/SpeechGenerationModel.d.ts +15 -0
  33. package/model-function/generate-speech/generateSpeech.cjs +24 -0
  34. package/model-function/generate-speech/generateSpeech.d.ts +8 -0
  35. package/model-function/generate-speech/generateSpeech.js +20 -0
  36. package/model-function/generate-speech/index.cjs +20 -0
  37. package/model-function/generate-speech/index.d.ts +4 -0
  38. package/model-function/generate-speech/index.js +4 -0
  39. package/model-function/generate-speech/streamSpeech.cjs +34 -0
  40. package/model-function/generate-speech/streamSpeech.d.ts +8 -0
  41. package/model-function/generate-speech/streamSpeech.js +30 -0
  42. package/model-function/generate-structure/StructureGenerationEvent.d.ts +2 -2
  43. package/model-function/generate-structure/StructureStreamingEvent.d.ts +2 -2
  44. package/model-function/generate-structure/generateStructure.cjs +3 -3
  45. package/model-function/generate-structure/generateStructure.js +3 -3
  46. package/model-function/generate-structure/generateStructureOrText.cjs +3 -3
  47. package/model-function/generate-structure/generateStructureOrText.js +3 -3
  48. package/model-function/generate-structure/index.cjs +27 -0
  49. package/model-function/generate-structure/index.d.ts +11 -0
  50. package/model-function/generate-structure/index.js +11 -0
  51. package/model-function/generate-structure/streamStructure.cjs +29 -137
  52. package/model-function/generate-structure/streamStructure.js +28 -136
  53. package/model-function/generate-text/TextGenerationEvent.d.ts +8 -2
  54. package/model-function/generate-text/generateText.cjs +4 -4
  55. package/model-function/generate-text/generateText.d.ts +1 -1
  56. package/model-function/generate-text/generateText.js +4 -4
  57. package/model-function/generate-text/index.cjs +0 -1
  58. package/model-function/generate-text/index.d.ts +0 -1
  59. package/model-function/generate-text/index.js +0 -1
  60. package/model-function/generate-text/streamText.cjs +22 -129
  61. package/model-function/generate-text/streamText.js +21 -128
  62. package/model-function/generate-text/trimChatPrompt.cjs +1 -1
  63. package/model-function/generate-text/trimChatPrompt.d.ts +1 -1
  64. package/model-function/generate-text/trimChatPrompt.js +1 -1
  65. package/model-function/{transcribe-speech → generate-transcription}/TranscriptionEvent.d.ts +2 -2
  66. package/model-function/{transcribe-speech/transcribe.cjs → generate-transcription/generateTranscription.cjs} +7 -7
  67. package/model-function/{transcribe-speech/transcribe.d.ts → generate-transcription/generateTranscription.d.ts} +2 -2
  68. package/model-function/{transcribe-speech/transcribe.js → generate-transcription/generateTranscription.js} +5 -5
  69. package/model-function/index.cjs +5 -20
  70. package/model-function/index.d.ts +5 -20
  71. package/model-function/index.js +5 -20
  72. package/model-provider/elevenlabs/{ElevenLabsSpeechSynthesisModel.cjs → ElevenLabsSpeechModel.cjs} +6 -6
  73. package/model-provider/elevenlabs/{ElevenLabsSpeechSynthesisModel.d.ts → ElevenLabsSpeechModel.d.ts} +8 -8
  74. package/model-provider/elevenlabs/{ElevenLabsSpeechSynthesisModel.js → ElevenLabsSpeechModel.js} +4 -4
  75. package/model-provider/elevenlabs/index.cjs +1 -1
  76. package/model-provider/elevenlabs/index.d.ts +1 -1
  77. package/model-provider/elevenlabs/index.js +1 -1
  78. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.cjs +21 -2
  79. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.d.ts +11 -6
  80. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.js +21 -2
  81. package/model-provider/lmnt/{LmntSpeechSynthesisModel.cjs → LmntSpeechModel.cjs} +5 -5
  82. package/model-provider/lmnt/LmntSpeechModel.d.ts +26 -0
  83. package/model-provider/lmnt/{LmntSpeechSynthesisModel.js → LmntSpeechModel.js} +3 -3
  84. package/model-provider/lmnt/index.cjs +1 -1
  85. package/model-provider/lmnt/index.d.ts +1 -1
  86. package/model-provider/lmnt/index.js +1 -1
  87. package/model-provider/openai/{OpenAITextGenerationModel.cjs → OpenAICompletionModel.cjs} +17 -17
  88. package/model-provider/openai/{OpenAITextGenerationModel.d.ts → OpenAICompletionModel.d.ts} +29 -29
  89. package/model-provider/openai/{OpenAITextGenerationModel.js → OpenAICompletionModel.js} +12 -12
  90. package/model-provider/openai/OpenAICostCalculator.cjs +8 -8
  91. package/model-provider/openai/OpenAICostCalculator.js +8 -8
  92. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
  93. package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -1
  94. package/model-provider/openai/TikTokenTokenizer.d.ts +2 -2
  95. package/model-provider/openai/chat/OpenAIChatModel.d.ts +7 -7
  96. package/model-provider/openai/index.cjs +1 -1
  97. package/model-provider/openai/index.d.ts +1 -1
  98. package/model-provider/openai/index.js +1 -1
  99. package/package.json +1 -1
  100. package/retriever/retrieve.cjs +7 -75
  101. package/retriever/retrieve.js +7 -75
  102. package/tool/UseToolEvent.d.ts +7 -0
  103. package/tool/UseToolOrGenerateTextEvent.d.ts +7 -0
  104. package/tool/executeTool.cjs +2 -0
  105. package/tool/executeTool.js +2 -0
  106. package/tool/index.cjs +2 -0
  107. package/tool/index.d.ts +2 -0
  108. package/tool/index.js +2 -0
  109. package/tool/useTool.cjs +18 -10
  110. package/tool/useTool.js +18 -10
  111. package/tool/useToolOrGenerateText.cjs +34 -26
  112. package/tool/useToolOrGenerateText.js +34 -26
  113. package/vector-index/UpsertIntoVectorIndexEvent.cjs +2 -0
  114. package/vector-index/UpsertIntoVectorIndexEvent.d.ts +9 -0
  115. package/vector-index/UpsertIntoVectorIndexEvent.js +1 -0
  116. package/vector-index/VectorIndexRetriever.cjs +1 -4
  117. package/vector-index/VectorIndexRetriever.js +1 -4
  118. package/vector-index/index.cjs +1 -0
  119. package/vector-index/index.d.ts +1 -0
  120. package/vector-index/index.js +1 -0
  121. package/vector-index/upsertIntoVectorIndex.cjs +16 -7
  122. package/vector-index/upsertIntoVectorIndex.js +16 -7
  123. package/model-function/describe-image/ImageDescriptionEvent.d.ts +0 -18
  124. package/model-function/describe-image/ImageDescriptionModel.d.ts +0 -10
  125. package/model-function/describe-image/describeImage.cjs +0 -26
  126. package/model-function/describe-image/describeImage.d.ts +0 -9
  127. package/model-function/describe-image/describeImage.js +0 -22
  128. package/model-function/generate-text/TextStreamingEvent.d.ts +0 -7
  129. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +0 -21
  130. package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +0 -15
  131. package/model-function/synthesize-speech/synthesizeSpeech.cjs +0 -67
  132. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +0 -14
  133. package/model-function/synthesize-speech/synthesizeSpeech.js +0 -63
  134. package/model-provider/lmnt/LmntSpeechSynthesisModel.d.ts +0 -26
  135. /package/{model-function/describe-image/ImageDescriptionEvent.cjs → guard/GuardEvent.cjs} +0 -0
  136. /package/{model-function/describe-image/ImageDescriptionEvent.js → guard/GuardEvent.js} +0 -0
  137. /package/model-function/{describe-image/ImageDescriptionModel.cjs → generate-speech/SpeechGenerationEvent.cjs} +0 -0
  138. /package/model-function/{describe-image/ImageDescriptionModel.js → generate-speech/SpeechGenerationEvent.js} +0 -0
  139. /package/model-function/{generate-text/TextStreamingEvent.cjs → generate-speech/SpeechGenerationModel.cjs} +0 -0
  140. /package/model-function/{generate-text/TextStreamingEvent.js → generate-speech/SpeechGenerationModel.js} +0 -0
  141. /package/model-function/{transcribe-speech → generate-transcription}/TranscriptionEvent.cjs +0 -0
  142. /package/model-function/{transcribe-speech → generate-transcription}/TranscriptionEvent.js +0 -0
  143. /package/model-function/{transcribe-speech → generate-transcription}/TranscriptionModel.cjs +0 -0
  144. /package/model-function/{transcribe-speech → generate-transcription}/TranscriptionModel.d.ts +0 -0
  145. /package/model-function/{transcribe-speech → generate-transcription}/TranscriptionModel.js +0 -0
  146. /package/{model-function/synthesize-speech/SpeechSynthesisEvent.cjs → tool/UseToolEvent.cjs} +0 -0
  147. /package/{model-function/synthesize-speech/SpeechSynthesisEvent.js → tool/UseToolEvent.js} +0 -0
  148. /package/{model-function/synthesize-speech/SpeechSynthesisModel.cjs → tool/UseToolOrGenerateTextEvent.cjs} +0 -0
  149. /package/{model-function/synthesize-speech/SpeechSynthesisModel.js → tool/UseToolOrGenerateTextEvent.js} +0 -0
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeStreamCall = void 0;
4
+ const nanoid_1 = require("nanoid");
5
+ const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
6
+ const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
+ const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
8
+ const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
+ const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../core/getRun.cjs");
11
+ const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
12
+ const runSafe_js_1 = require("../util/runSafe.cjs");
13
+ async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished, getResult, }) {
14
+ const run = await (0, getRun_js_1.getRun)(options?.run);
15
+ const settings = model.settings;
16
+ const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
17
+ observers: [
18
+ ...(0, getFunctionCallLogger_js_1.getFunctionCallLogger)(options?.logging ?? (0, GlobalFunctionLogging_js_1.getGlobalFunctionLogging)()),
19
+ ...(0, GlobalFunctionObservers_js_1.getGlobalFunctionObservers)(),
20
+ ...(settings.observers ?? []),
21
+ ...(run?.functionObserver != null ? [run.functionObserver] : []),
22
+ ...(options?.observers ?? []),
23
+ ],
24
+ errorHandler: run?.errorHandler,
25
+ });
26
+ const durationMeasurement = (0, DurationMeasurement_js_1.startDurationMeasurement)();
27
+ const startMetadata = {
28
+ functionType,
29
+ callId: `call-${(0, nanoid_1.nanoid)()}`,
30
+ parentCallId: options?.parentCallId,
31
+ runId: run?.runId,
32
+ sessionId: run?.sessionId,
33
+ userId: run?.userId,
34
+ functionId: options?.functionId,
35
+ model: model.modelInformation,
36
+ settings: model.settingsForEvent,
37
+ input,
38
+ timestamp: durationMeasurement.startDate,
39
+ startTimestamp: durationMeasurement.startDate,
40
+ };
41
+ eventSource.notify({
42
+ eventType: "started",
43
+ ...startMetadata,
44
+ });
45
+ const result = await (0, runSafe_js_1.runSafe)(async () => {
46
+ const deltaIterable = await startStream({
47
+ functionId: options?.functionId,
48
+ logging: options?.logging,
49
+ observers: options?.observers,
50
+ run,
51
+ parentCallId: startMetadata.callId,
52
+ });
53
+ return (async function* () {
54
+ for await (const event of deltaIterable) {
55
+ if (event?.type === "error") {
56
+ const error = event.error;
57
+ const finishMetadata = {
58
+ eventType: "finished",
59
+ ...startMetadata,
60
+ finishTimestamp: new Date(),
61
+ durationInMs: durationMeasurement.durationInMs,
62
+ };
63
+ eventSource.notify(error instanceof AbortError_js_1.AbortError
64
+ ? {
65
+ ...finishMetadata,
66
+ result: { status: "abort" },
67
+ }
68
+ : {
69
+ ...finishMetadata,
70
+ result: { status: "error", error },
71
+ });
72
+ throw error;
73
+ }
74
+ if (event?.type === "delta") {
75
+ const value = processDelta(event);
76
+ if (value !== undefined) {
77
+ yield value;
78
+ }
79
+ }
80
+ }
81
+ if (processFinished != null) {
82
+ const value = processFinished();
83
+ if (value !== undefined) {
84
+ yield value;
85
+ }
86
+ }
87
+ const finishMetadata = {
88
+ eventType: "finished",
89
+ ...startMetadata,
90
+ finishTimestamp: new Date(),
91
+ durationInMs: durationMeasurement.durationInMs,
92
+ };
93
+ eventSource.notify({
94
+ ...finishMetadata,
95
+ result: {
96
+ status: "success",
97
+ ...getResult(),
98
+ },
99
+ });
100
+ })();
101
+ });
102
+ if (!result.ok) {
103
+ const finishMetadata = {
104
+ eventType: "finished",
105
+ ...startMetadata,
106
+ finishTimestamp: new Date(),
107
+ durationInMs: durationMeasurement.durationInMs,
108
+ };
109
+ if (result.isAborted) {
110
+ eventSource.notify({
111
+ ...finishMetadata,
112
+ eventType: "finished",
113
+ result: {
114
+ status: "abort",
115
+ },
116
+ });
117
+ throw new AbortError_js_1.AbortError();
118
+ }
119
+ eventSource.notify({
120
+ ...finishMetadata,
121
+ eventType: "finished",
122
+ result: {
123
+ status: "error",
124
+ error: result.error,
125
+ },
126
+ });
127
+ throw result.error;
128
+ }
129
+ return {
130
+ value: result.value,
131
+ metadata: startMetadata,
132
+ };
133
+ }
134
+ exports.executeStreamCall = executeStreamCall;
@@ -0,0 +1,20 @@
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
+ import { Delta } from "./Delta.js";
3
+ import { Model, ModelSettings } from "./Model.js";
4
+ import { ModelCallStartedEvent } from "./ModelCallEvent.js";
5
+ import { ModelCallMetadata } from "./ModelCallMetadata.js";
6
+ export declare function executeStreamCall<DELTA_VALUE, VALUE, MODEL extends Model<ModelSettings>>({ model, options, input, functionType, startStream, processDelta, processFinished, getResult, }: {
7
+ model: MODEL;
8
+ options?: FunctionOptions;
9
+ input: unknown;
10
+ functionType: ModelCallStartedEvent["functionType"];
11
+ startStream: (options?: FunctionOptions) => PromiseLike<AsyncIterable<Delta<DELTA_VALUE>>>;
12
+ processDelta: (delta: Delta<DELTA_VALUE> & {
13
+ type: "delta";
14
+ }) => VALUE | undefined;
15
+ processFinished?: () => VALUE | undefined;
16
+ getResult: () => Record<string, unknown>;
17
+ }): Promise<{
18
+ value: AsyncIterable<VALUE>;
19
+ metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
20
+ }>;
@@ -0,0 +1,130 @@
1
+ import { nanoid as createId } from "nanoid";
2
+ import { FunctionEventSource } from "../core/FunctionEventSource.js";
3
+ import { getGlobalFunctionLogging } from "../core/GlobalFunctionLogging.js";
4
+ import { getGlobalFunctionObservers } from "../core/GlobalFunctionObservers.js";
5
+ import { AbortError } from "../core/api/AbortError.js";
6
+ import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
7
+ import { getRun } from "../core/getRun.js";
8
+ import { startDurationMeasurement } from "../util/DurationMeasurement.js";
9
+ import { runSafe } from "../util/runSafe.js";
10
+ export async function executeStreamCall({ model, options, input, functionType, startStream, processDelta, processFinished, getResult, }) {
11
+ const run = await getRun(options?.run);
12
+ const settings = model.settings;
13
+ const eventSource = new FunctionEventSource({
14
+ observers: [
15
+ ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
16
+ ...getGlobalFunctionObservers(),
17
+ ...(settings.observers ?? []),
18
+ ...(run?.functionObserver != null ? [run.functionObserver] : []),
19
+ ...(options?.observers ?? []),
20
+ ],
21
+ errorHandler: run?.errorHandler,
22
+ });
23
+ const durationMeasurement = startDurationMeasurement();
24
+ const startMetadata = {
25
+ functionType,
26
+ callId: `call-${createId()}`,
27
+ parentCallId: options?.parentCallId,
28
+ runId: run?.runId,
29
+ sessionId: run?.sessionId,
30
+ userId: run?.userId,
31
+ functionId: options?.functionId,
32
+ model: model.modelInformation,
33
+ settings: model.settingsForEvent,
34
+ input,
35
+ timestamp: durationMeasurement.startDate,
36
+ startTimestamp: durationMeasurement.startDate,
37
+ };
38
+ eventSource.notify({
39
+ eventType: "started",
40
+ ...startMetadata,
41
+ });
42
+ const result = await runSafe(async () => {
43
+ const deltaIterable = await startStream({
44
+ functionId: options?.functionId,
45
+ logging: options?.logging,
46
+ observers: options?.observers,
47
+ run,
48
+ parentCallId: startMetadata.callId,
49
+ });
50
+ return (async function* () {
51
+ for await (const event of deltaIterable) {
52
+ if (event?.type === "error") {
53
+ const error = event.error;
54
+ const finishMetadata = {
55
+ eventType: "finished",
56
+ ...startMetadata,
57
+ finishTimestamp: new Date(),
58
+ durationInMs: durationMeasurement.durationInMs,
59
+ };
60
+ eventSource.notify(error instanceof AbortError
61
+ ? {
62
+ ...finishMetadata,
63
+ result: { status: "abort" },
64
+ }
65
+ : {
66
+ ...finishMetadata,
67
+ result: { status: "error", error },
68
+ });
69
+ throw error;
70
+ }
71
+ if (event?.type === "delta") {
72
+ const value = processDelta(event);
73
+ if (value !== undefined) {
74
+ yield value;
75
+ }
76
+ }
77
+ }
78
+ if (processFinished != null) {
79
+ const value = processFinished();
80
+ if (value !== undefined) {
81
+ yield value;
82
+ }
83
+ }
84
+ const finishMetadata = {
85
+ eventType: "finished",
86
+ ...startMetadata,
87
+ finishTimestamp: new Date(),
88
+ durationInMs: durationMeasurement.durationInMs,
89
+ };
90
+ eventSource.notify({
91
+ ...finishMetadata,
92
+ result: {
93
+ status: "success",
94
+ ...getResult(),
95
+ },
96
+ });
97
+ })();
98
+ });
99
+ if (!result.ok) {
100
+ const finishMetadata = {
101
+ eventType: "finished",
102
+ ...startMetadata,
103
+ finishTimestamp: new Date(),
104
+ durationInMs: durationMeasurement.durationInMs,
105
+ };
106
+ if (result.isAborted) {
107
+ eventSource.notify({
108
+ ...finishMetadata,
109
+ eventType: "finished",
110
+ result: {
111
+ status: "abort",
112
+ },
113
+ });
114
+ throw new AbortError();
115
+ }
116
+ eventSource.notify({
117
+ ...finishMetadata,
118
+ eventType: "finished",
119
+ result: {
120
+ status: "error",
121
+ error: result.error,
122
+ },
123
+ });
124
+ throw result.error;
125
+ }
126
+ return {
127
+ value: result.value,
128
+ metadata: startMetadata,
129
+ };
130
+ }
@@ -1,6 +1,6 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
2
  export interface ImageGenerationStartedEvent extends BaseModelCallStartedEvent {
3
- functionType: "image-generation";
3
+ functionType: "generate-image";
4
4
  }
5
5
  export type ImageGenerationFinishedEventResult = {
6
6
  status: "success";
@@ -13,6 +13,6 @@ export type ImageGenerationFinishedEventResult = {
13
13
  status: "abort";
14
14
  };
15
15
  export interface ImageGenerationFinishedEvent extends BaseModelCallFinishedEvent {
16
- functionType: "image-generation";
16
+ functionType: "generate-image";
17
17
  result: ImageGenerationFinishedEventResult;
18
18
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateImage = void 0;
4
- const executeCall_js_1 = require("../executeCall.cjs");
4
+ const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
5
5
  const ImageGenerationPromise_js_1 = require("./ImageGenerationPromise.cjs");
6
6
  /**
7
7
  * Generates a base64-encoded image using a prompt.
@@ -19,8 +19,8 @@ const ImageGenerationPromise_js_1 = require("./ImageGenerationPromise.cjs");
19
19
  * );
20
20
  */
21
21
  function generateImage(model, prompt, options) {
22
- return new ImageGenerationPromise_js_1.ImageGenerationPromise((0, executeCall_js_1.executeCall)({
23
- functionType: "image-generation",
22
+ return new ImageGenerationPromise_js_1.ImageGenerationPromise((0, executeStandardCall_js_1.executeStandardCall)({
23
+ functionType: "generate-image",
24
24
  input: prompt,
25
25
  model,
26
26
  options,
@@ -1,4 +1,4 @@
1
- import { executeCall } from "../executeCall.js";
1
+ import { executeStandardCall } from "../executeStandardCall.js";
2
2
  import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
3
3
  /**
4
4
  * Generates a base64-encoded image using a prompt.
@@ -16,8 +16,8 @@ import { ImageGenerationPromise } from "./ImageGenerationPromise.js";
16
16
  * );
17
17
  */
18
18
  export function generateImage(model, prompt, options) {
19
- return new ImageGenerationPromise(executeCall({
20
- functionType: "image-generation",
19
+ return new ImageGenerationPromise(executeStandardCall({
20
+ functionType: "generate-image",
21
21
  input: prompt,
22
22
  model,
23
23
  options,
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
3
+ export interface SpeechGenerationStartedEvent extends BaseModelCallStartedEvent {
4
+ functionType: "generate-speech";
5
+ input: string;
6
+ }
7
+ export type SpeechGenerationFinishedEventResult = {
8
+ status: "success";
9
+ response: unknown;
10
+ value: Buffer;
11
+ } | {
12
+ status: "error";
13
+ error: unknown;
14
+ } | {
15
+ status: "abort";
16
+ };
17
+ export interface SpeechGenerationFinishedEvent extends BaseModelCallFinishedEvent {
18
+ functionType: "generate-speech";
19
+ input: string;
20
+ result: SpeechGenerationFinishedEventResult;
21
+ }
22
+ export interface SpeechStreamingStartedEvent extends BaseModelCallStartedEvent {
23
+ functionType: "stream-speech";
24
+ }
25
+ export interface SpeechStreamingFinishedEvent extends BaseModelCallFinishedEvent {
26
+ functionType: "stream-speech";
27
+ }
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
+ import { Delta } from "../Delta.js";
4
+ import { Model, ModelSettings } from "../Model.js";
5
+ export interface SpeechGenerationModelSettings extends ModelSettings {
6
+ }
7
+ export interface SpeechGenerationModel<SETTINGS extends SpeechGenerationModelSettings = SpeechGenerationModelSettings> extends Model<SETTINGS> {
8
+ /**
9
+ * Generates an mp3 audio buffer that contains the speech for the given text.
10
+ */
11
+ doGenerateSpeechStandard(text: string, options?: FunctionOptions): PromiseLike<Buffer>;
12
+ }
13
+ export interface StreamingSpeechGenerationModel<SETTINGS extends SpeechGenerationModelSettings = SpeechGenerationModelSettings> extends SpeechGenerationModel<SETTINGS> {
14
+ doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>, options?: FunctionOptions): PromiseLike<AsyncIterable<Delta<Buffer>>>;
15
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateSpeech = void 0;
4
+ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
5
+ const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
6
+ /**
7
+ * Synthesizes speech from text.
8
+ */
9
+ function generateSpeech(model, text, options) {
10
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
11
+ functionType: "generate-speech",
12
+ input: text,
13
+ model,
14
+ options,
15
+ generateResponse: async (options) => {
16
+ const response = await model.doGenerateSpeechStandard(text, options);
17
+ return {
18
+ response,
19
+ extractedValue: response,
20
+ };
21
+ },
22
+ }));
23
+ }
24
+ exports.generateSpeech = generateSpeech;
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
4
+ import { SpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGenerationModel.js";
5
+ /**
6
+ * Synthesizes speech from text.
7
+ */
8
+ export declare function generateSpeech(model: SpeechGenerationModel<SpeechGenerationModelSettings>, text: string, options?: FunctionOptions): ModelFunctionPromise<Buffer>;
@@ -0,0 +1,20 @@
1
+ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
2
+ import { executeStandardCall } from "../executeStandardCall.js";
3
+ /**
4
+ * Synthesizes speech from text.
5
+ */
6
+ export function generateSpeech(model, text, options) {
7
+ return new ModelFunctionPromise(executeStandardCall({
8
+ functionType: "generate-speech",
9
+ input: text,
10
+ model,
11
+ options,
12
+ generateResponse: async (options) => {
13
+ const response = await model.doGenerateSpeechStandard(text, options);
14
+ return {
15
+ response,
16
+ extractedValue: response,
17
+ };
18
+ },
19
+ }));
20
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./SpeechGenerationEvent.cjs"), exports);
18
+ __exportStar(require("./SpeechGenerationModel.cjs"), exports);
19
+ __exportStar(require("./generateSpeech.cjs"), exports);
20
+ __exportStar(require("./streamSpeech.cjs"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./SpeechGenerationEvent.js";
2
+ export * from "./SpeechGenerationModel.js";
3
+ export * from "./generateSpeech.js";
4
+ export * from "./streamSpeech.js";
@@ -0,0 +1,4 @@
1
+ export * from "./SpeechGenerationEvent.js";
2
+ export * from "./SpeechGenerationModel.js";
3
+ export * from "./generateSpeech.js";
4
+ export * from "./streamSpeech.js";
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.streamSpeech = void 0;
4
+ const AsyncQueue_js_1 = require("../../event-source/AsyncQueue.cjs");
5
+ const AsyncIterableResultPromise_js_1 = require("../AsyncIterableResultPromise.cjs");
6
+ const executeStreamCall_js_1 = require("../executeStreamCall.cjs");
7
+ /**
8
+ * Synthesizes speech from text.
9
+ */
10
+ function streamSpeech(model, text, options) {
11
+ let textStream;
12
+ // simulate a stream with a single value for a string input:
13
+ if (typeof text === "string") {
14
+ const queue = new AsyncQueue_js_1.AsyncQueue();
15
+ queue.push(text);
16
+ queue.close();
17
+ textStream = queue;
18
+ }
19
+ else {
20
+ textStream = text;
21
+ }
22
+ return new AsyncIterableResultPromise_js_1.AsyncIterableResultPromise((0, executeStreamCall_js_1.executeStreamCall)({
23
+ functionType: "stream-speech",
24
+ input: text,
25
+ model,
26
+ options,
27
+ startStream: async (options) => model.doGenerateSpeechStreamDuplex(textStream, options),
28
+ processDelta: (delta) => {
29
+ return delta.valueDelta;
30
+ },
31
+ getResult: () => ({}),
32
+ }));
33
+ }
34
+ exports.streamSpeech = streamSpeech;
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
+ import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
4
+ import { StreamingSpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGenerationModel.js";
5
+ /**
6
+ * Synthesizes speech from text.
7
+ */
8
+ export declare function streamSpeech(model: StreamingSpeechGenerationModel<SpeechGenerationModelSettings>, text: AsyncIterable<string> | string, options?: FunctionOptions): AsyncIterableResultPromise<Buffer>;
@@ -0,0 +1,30 @@
1
+ import { AsyncQueue } from "../../event-source/AsyncQueue.js";
2
+ import { AsyncIterableResultPromise } from "../AsyncIterableResultPromise.js";
3
+ import { executeStreamCall } from "../executeStreamCall.js";
4
+ /**
5
+ * Synthesizes speech from text.
6
+ */
7
+ export function streamSpeech(model, text, options) {
8
+ let textStream;
9
+ // simulate a stream with a single value for a string input:
10
+ if (typeof text === "string") {
11
+ const queue = new AsyncQueue();
12
+ queue.push(text);
13
+ queue.close();
14
+ textStream = queue;
15
+ }
16
+ else {
17
+ textStream = text;
18
+ }
19
+ return new AsyncIterableResultPromise(executeStreamCall({
20
+ functionType: "stream-speech",
21
+ input: text,
22
+ model,
23
+ options,
24
+ startStream: async (options) => model.doGenerateSpeechStreamDuplex(textStream, options),
25
+ processDelta: (delta) => {
26
+ return delta.valueDelta;
27
+ },
28
+ getResult: () => ({}),
29
+ }));
30
+ }
@@ -1,6 +1,6 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
2
  export interface StructureGenerationStartedEvent extends BaseModelCallStartedEvent {
3
- functionType: "structure-generation" | "structure-or-text-generation";
3
+ functionType: "generate-structure" | "generate-structure-or-text";
4
4
  }
5
5
  export type StructureGenerationFinishedEventResult = {
6
6
  status: "success";
@@ -18,6 +18,6 @@ export type StructureGenerationFinishedEventResult = {
18
18
  status: "abort";
19
19
  };
20
20
  export type StructureGenerationFinishedEvent = BaseModelCallFinishedEvent & {
21
- functionType: "structure-generation" | "structure-or-text-generation";
21
+ functionType: "generate-structure" | "generate-structure-or-text";
22
22
  result: StructureGenerationFinishedEventResult;
23
23
  };
@@ -1,7 +1,7 @@
1
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
2
  export interface StructureStreamingStartedEvent extends BaseModelCallStartedEvent {
3
- functionType: "structure-streaming";
3
+ functionType: "stream-structure";
4
4
  }
5
5
  export interface StructureStreamingFinishedEvent extends BaseModelCallFinishedEvent {
6
- functionType: "structure-streaming";
6
+ functionType: "stream-structure";
7
7
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStructure = void 0;
4
- const executeCall_js_1 = require("../executeCall.cjs");
4
+ const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
5
5
  const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
6
6
  const StructureValidationError_js_1 = require("./StructureValidationError.cjs");
7
7
  function generateStructure(model, structureDefinition, prompt, options) {
@@ -9,8 +9,8 @@ function generateStructure(model, structureDefinition, prompt, options) {
9
9
  const expandedPrompt = typeof prompt === "function"
10
10
  ? prompt(structureDefinition)
11
11
  : prompt;
12
- return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
13
- functionType: "structure-generation",
12
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
13
+ functionType: "generate-structure",
14
14
  input: expandedPrompt,
15
15
  model,
16
16
  options,
@@ -1,4 +1,4 @@
1
- import { executeCall } from "../executeCall.js";
1
+ import { executeStandardCall } from "../executeStandardCall.js";
2
2
  import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
3
3
  import { StructureValidationError } from "./StructureValidationError.js";
4
4
  export function generateStructure(model, structureDefinition, prompt, options) {
@@ -6,8 +6,8 @@ export function generateStructure(model, structureDefinition, prompt, options) {
6
6
  const expandedPrompt = typeof prompt === "function"
7
7
  ? prompt(structureDefinition)
8
8
  : prompt;
9
- return new ModelFunctionPromise(executeCall({
10
- functionType: "structure-generation",
9
+ return new ModelFunctionPromise(executeStandardCall({
10
+ functionType: "generate-structure",
11
11
  input: expandedPrompt,
12
12
  model,
13
13
  options,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateStructureOrText = void 0;
4
- const executeCall_js_1 = require("../executeCall.cjs");
4
+ const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
5
5
  const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
6
6
  const NoSuchStructureError_js_1 = require("./NoSuchStructureError.cjs");
7
7
  const StructureValidationError_js_1 = require("./StructureValidationError.cjs");
@@ -10,8 +10,8 @@ function generateStructureOrText(model, structureDefinitions, prompt, options) {
10
10
  const expandedPrompt = typeof prompt === "function"
11
11
  ? prompt(structureDefinitions)
12
12
  : prompt;
13
- return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
14
- functionType: "structure-or-text-generation",
13
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
14
+ functionType: "generate-structure-or-text",
15
15
  input: expandedPrompt,
16
16
  model,
17
17
  options,
@@ -1,4 +1,4 @@
1
- import { executeCall } from "../executeCall.js";
1
+ import { executeStandardCall } from "../executeStandardCall.js";
2
2
  import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
3
3
  import { NoSuchStructureError } from "./NoSuchStructureError.js";
4
4
  import { StructureValidationError } from "./StructureValidationError.js";
@@ -7,8 +7,8 @@ export function generateStructureOrText(model, structureDefinitions, prompt, opt
7
7
  const expandedPrompt = typeof prompt === "function"
8
8
  ? prompt(structureDefinitions)
9
9
  : prompt;
10
- return new ModelFunctionPromise(executeCall({
11
- functionType: "structure-or-text-generation",
10
+ return new ModelFunctionPromise(executeStandardCall({
11
+ functionType: "generate-structure-or-text",
12
12
  input: expandedPrompt,
13
13
  model,
14
14
  options,