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,81 @@
1
+ import { nanoid as createId } from "nanoid";
2
+ import { FunctionEventSource } from "./FunctionEventSource.js";
3
+ import { getGlobalFunctionLogging } from "./GlobalFunctionLogging.js";
4
+ import { getGlobalFunctionObservers } from "./GlobalFunctionObservers.js";
5
+ import { AbortError } from "./api/AbortError.js";
6
+ import { getFunctionCallLogger } from "./getFunctionCallLogger.js";
7
+ import { getRun } from "./getRun.js";
8
+ import { startDurationMeasurement } from "../util/DurationMeasurement.js";
9
+ import { runSafe } from "../util/runSafe.js";
10
+ export async function executeFunctionCall({ options, input, functionType, execute, inputPropertyName = "input", outputPropertyName = "value", }) {
11
+ const run = await getRun(options?.run);
12
+ const eventSource = new FunctionEventSource({
13
+ observers: [
14
+ ...getFunctionCallLogger(options?.logging ?? getGlobalFunctionLogging()),
15
+ ...getGlobalFunctionObservers(),
16
+ ...(run?.functionObserver != null ? [run.functionObserver] : []),
17
+ ...(options?.observers ?? []),
18
+ ],
19
+ errorHandler: run?.errorHandler,
20
+ });
21
+ const durationMeasurement = startDurationMeasurement();
22
+ const startMetadata = {
23
+ functionType,
24
+ callId: `call-${createId()}`,
25
+ parentCallId: options?.parentCallId,
26
+ runId: run?.runId,
27
+ sessionId: run?.sessionId,
28
+ userId: run?.userId,
29
+ functionId: options?.functionId,
30
+ [inputPropertyName]: input,
31
+ timestamp: durationMeasurement.startDate,
32
+ startTimestamp: durationMeasurement.startDate,
33
+ };
34
+ eventSource.notify({
35
+ eventType: "started",
36
+ ...startMetadata,
37
+ });
38
+ const result = await runSafe(() => execute({
39
+ functionId: options?.functionId,
40
+ logging: options?.logging,
41
+ observers: options?.observers,
42
+ run,
43
+ parentCallId: startMetadata.callId,
44
+ }));
45
+ const finishMetadata = {
46
+ eventType: "finished",
47
+ ...startMetadata,
48
+ finishTimestamp: new Date(),
49
+ durationInMs: durationMeasurement.durationInMs,
50
+ };
51
+ if (!result.ok) {
52
+ if (result.isAborted) {
53
+ eventSource.notify({
54
+ ...finishMetadata,
55
+ eventType: "finished",
56
+ result: {
57
+ status: "abort",
58
+ },
59
+ });
60
+ throw new AbortError();
61
+ }
62
+ eventSource.notify({
63
+ ...finishMetadata,
64
+ eventType: "finished",
65
+ result: {
66
+ status: "error",
67
+ error: result.error,
68
+ },
69
+ });
70
+ throw result.error;
71
+ }
72
+ eventSource.notify({
73
+ ...finishMetadata,
74
+ eventType: "finished",
75
+ result: {
76
+ status: "success",
77
+ [outputPropertyName]: result.value,
78
+ },
79
+ });
80
+ return result.value;
81
+ }
@@ -0,0 +1,7 @@
1
+ import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
2
+ export interface GuardStartedEvent extends BaseFunctionStartedEvent {
3
+ functionType: "guard";
4
+ }
5
+ export interface GuardFinishedEvent extends BaseFunctionFinishedEvent {
6
+ functionType: "guard";
7
+ }
package/guard/guard.cjs CHANGED
@@ -1,72 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.guard = void 0;
4
+ const executeFunctionCall_js_1 = require("../core/executeFunctionCall.cjs");
4
5
  async function guard(execute, input, guards, options) {
5
- if (typeof guards === "function") {
6
- guards = [guards];
7
- }
6
+ const guardList = Array.isArray(guards) ? guards : [guards];
8
7
  const maxRetries = options?.maxRetries ?? 1;
9
- let attempts = 0;
10
- while (attempts <= maxRetries) {
11
- let result;
12
- try {
13
- result = {
14
- type: "value",
15
- input,
16
- output: await execute(input),
17
- };
18
- }
19
- catch (error) {
20
- result = {
21
- type: "error",
22
- input,
23
- error,
24
- };
25
- }
26
- let isValid = true;
27
- for (const guard of guards) {
28
- const guardResult = await guard(result);
29
- if (guardResult === undefined) {
30
- continue;
31
- }
32
- switch (guardResult.action) {
33
- case "passThrough": {
34
- break;
35
- }
36
- case "retry": {
37
- input = guardResult.input;
38
- isValid = false;
39
- break;
40
- }
41
- case "return": {
8
+ return (0, executeFunctionCall_js_1.executeFunctionCall)({
9
+ options,
10
+ input,
11
+ functionType: "guard",
12
+ execute: async (options) => {
13
+ let attempts = 0;
14
+ while (attempts <= maxRetries) {
15
+ let result;
16
+ try {
42
17
  result = {
43
18
  type: "value",
44
19
  input,
45
- output: guardResult.output,
20
+ output: await execute(input, options),
46
21
  };
47
- break;
48
22
  }
49
- case "throwError": {
23
+ catch (error) {
50
24
  result = {
51
25
  type: "error",
52
26
  input,
53
- error: guardResult.error,
27
+ error,
54
28
  };
55
- break;
56
29
  }
30
+ let isValid = true;
31
+ for (const guard of guardList) {
32
+ const guardResult = await guard(result);
33
+ if (guardResult === undefined) {
34
+ continue;
35
+ }
36
+ switch (guardResult.action) {
37
+ case "passThrough": {
38
+ break;
39
+ }
40
+ case "retry": {
41
+ input = guardResult.input;
42
+ isValid = false;
43
+ break;
44
+ }
45
+ case "return": {
46
+ result = {
47
+ type: "value",
48
+ input,
49
+ output: guardResult.output,
50
+ };
51
+ break;
52
+ }
53
+ case "throwError": {
54
+ result = {
55
+ type: "error",
56
+ input,
57
+ error: guardResult.error,
58
+ };
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ if (isValid) {
64
+ if (result.type === "value") {
65
+ return result.output;
66
+ }
67
+ else {
68
+ throw result.error;
69
+ }
70
+ }
71
+ attempts++;
57
72
  }
58
- }
59
- if (isValid) {
60
- if (result.type === "value") {
61
- return result.output;
62
- }
63
- else {
64
- throw result.error;
65
- }
66
- }
67
- attempts++;
68
- }
69
- throw new Error(`Maximum retry attempts of ${maxRetries} reached ` +
70
- `without producing a valid output or handling an error after ${attempts} attempts.`);
73
+ throw new Error(`Maximum retry attempts of ${maxRetries} reached ` +
74
+ `without producing a valid output or handling an error after ${attempts} attempts.`);
75
+ },
76
+ });
71
77
  }
72
78
  exports.guard = guard;
package/guard/guard.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
1
2
  type OutputResult<INPUT, OUTPUT> = {
2
3
  type: "value";
3
4
  input: INPUT;
@@ -22,7 +23,7 @@ export type Guard<INPUT, OUTPUT> = ({ type, input, output, error, }: OutputResul
22
23
  } | {
23
24
  action: "passThrough";
24
25
  } | undefined>;
25
- export declare function guard<INPUT, OUTPUT>(execute: (input: INPUT) => PromiseLike<OUTPUT>, input: INPUT, guards: Guard<INPUT, OUTPUT> | Array<Guard<INPUT, OUTPUT>>, options?: {
26
+ export declare function guard<INPUT, OUTPUT>(execute: (input: INPUT, options?: FunctionOptions) => PromiseLike<OUTPUT>, input: INPUT, guards: Guard<INPUT, OUTPUT> | Array<Guard<INPUT, OUTPUT>>, options?: FunctionOptions & {
26
27
  maxRetries: number;
27
28
  }): Promise<OUTPUT | undefined>;
28
29
  export {};
package/guard/guard.js CHANGED
@@ -1,68 +1,74 @@
1
+ import { executeFunctionCall } from "../core/executeFunctionCall.js";
1
2
  export async function guard(execute, input, guards, options) {
2
- if (typeof guards === "function") {
3
- guards = [guards];
4
- }
3
+ const guardList = Array.isArray(guards) ? guards : [guards];
5
4
  const maxRetries = options?.maxRetries ?? 1;
6
- let attempts = 0;
7
- while (attempts <= maxRetries) {
8
- let result;
9
- try {
10
- result = {
11
- type: "value",
12
- input,
13
- output: await execute(input),
14
- };
15
- }
16
- catch (error) {
17
- result = {
18
- type: "error",
19
- input,
20
- error,
21
- };
22
- }
23
- let isValid = true;
24
- for (const guard of guards) {
25
- const guardResult = await guard(result);
26
- if (guardResult === undefined) {
27
- continue;
28
- }
29
- switch (guardResult.action) {
30
- case "passThrough": {
31
- break;
32
- }
33
- case "retry": {
34
- input = guardResult.input;
35
- isValid = false;
36
- break;
37
- }
38
- case "return": {
5
+ return executeFunctionCall({
6
+ options,
7
+ input,
8
+ functionType: "guard",
9
+ execute: async (options) => {
10
+ let attempts = 0;
11
+ while (attempts <= maxRetries) {
12
+ let result;
13
+ try {
39
14
  result = {
40
15
  type: "value",
41
16
  input,
42
- output: guardResult.output,
17
+ output: await execute(input, options),
43
18
  };
44
- break;
45
19
  }
46
- case "throwError": {
20
+ catch (error) {
47
21
  result = {
48
22
  type: "error",
49
23
  input,
50
- error: guardResult.error,
24
+ error,
51
25
  };
52
- break;
53
26
  }
27
+ let isValid = true;
28
+ for (const guard of guardList) {
29
+ const guardResult = await guard(result);
30
+ if (guardResult === undefined) {
31
+ continue;
32
+ }
33
+ switch (guardResult.action) {
34
+ case "passThrough": {
35
+ break;
36
+ }
37
+ case "retry": {
38
+ input = guardResult.input;
39
+ isValid = false;
40
+ break;
41
+ }
42
+ case "return": {
43
+ result = {
44
+ type: "value",
45
+ input,
46
+ output: guardResult.output,
47
+ };
48
+ break;
49
+ }
50
+ case "throwError": {
51
+ result = {
52
+ type: "error",
53
+ input,
54
+ error: guardResult.error,
55
+ };
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ if (isValid) {
61
+ if (result.type === "value") {
62
+ return result.output;
63
+ }
64
+ else {
65
+ throw result.error;
66
+ }
67
+ }
68
+ attempts++;
54
69
  }
55
- }
56
- if (isValid) {
57
- if (result.type === "value") {
58
- return result.output;
59
- }
60
- else {
61
- throw result.error;
62
- }
63
- }
64
- attempts++;
65
- }
66
- throw new Error(`Maximum retry attempts of ${maxRetries} reached ` +
67
- `without producing a valid output or handling an error after ${attempts} attempts.`);
70
+ throw new Error(`Maximum retry attempts of ${maxRetries} reached ` +
71
+ `without producing a valid output or handling an error after ${attempts} attempts.`);
72
+ },
73
+ });
68
74
  }
package/guard/index.cjs CHANGED
@@ -14,5 +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("./GuardEvent.cjs"), exports);
17
18
  __exportStar(require("./fixStructure.cjs"), exports);
18
19
  __exportStar(require("./guard.cjs"), exports);
package/guard/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./GuardEvent.js";
1
2
  export * from "./fixStructure.js";
2
3
  export * from "./guard.js";
package/guard/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export * from "./GuardEvent.js";
1
2
  export * from "./fixStructure.js";
2
3
  export * from "./guard.js";
@@ -13,25 +13,25 @@ class AsyncIterableResultPromise extends Promise {
13
13
  writable: true,
14
14
  value: fullPromise
15
15
  });
16
- Object.defineProperty(this, "outputPromise", {
16
+ Object.defineProperty(this, "valuePromise", {
17
17
  enumerable: true,
18
18
  configurable: true,
19
19
  writable: true,
20
20
  value: void 0
21
21
  });
22
- this.outputPromise = fullPromise.then((result) => result.output);
22
+ this.valuePromise = fullPromise.then((result) => result.value);
23
23
  }
24
24
  asFullResponse() {
25
25
  return this.fullPromise;
26
26
  }
27
27
  then(onfulfilled, onrejected) {
28
- return this.outputPromise.then(onfulfilled, onrejected);
28
+ return this.valuePromise.then(onfulfilled, onrejected);
29
29
  }
30
30
  catch(onrejected) {
31
- return this.outputPromise.catch(onrejected);
31
+ return this.valuePromise.catch(onrejected);
32
32
  }
33
33
  finally(onfinally) {
34
- return this.outputPromise.finally(onfinally);
34
+ return this.valuePromise.finally(onfinally);
35
35
  }
36
36
  }
37
37
  exports.AsyncIterableResultPromise = AsyncIterableResultPromise;
@@ -1,13 +1,13 @@
1
1
  import { ModelCallMetadata } from "./ModelCallMetadata.js";
2
2
  export declare class AsyncIterableResultPromise<T> extends Promise<AsyncIterable<T>> {
3
3
  private fullPromise;
4
- private outputPromise;
4
+ private valuePromise;
5
5
  constructor(fullPromise: Promise<{
6
- output: AsyncIterable<T>;
6
+ value: AsyncIterable<T>;
7
7
  metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
8
8
  }>);
9
9
  asFullResponse(): Promise<{
10
- output: AsyncIterable<T>;
10
+ value: AsyncIterable<T>;
11
11
  metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
12
12
  }>;
13
13
  then<TResult1 = AsyncIterable<T>, TResult2 = never>(onfulfilled?: ((value: AsyncIterable<T>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
@@ -10,24 +10,24 @@ export class AsyncIterableResultPromise extends Promise {
10
10
  writable: true,
11
11
  value: fullPromise
12
12
  });
13
- Object.defineProperty(this, "outputPromise", {
13
+ Object.defineProperty(this, "valuePromise", {
14
14
  enumerable: true,
15
15
  configurable: true,
16
16
  writable: true,
17
17
  value: void 0
18
18
  });
19
- this.outputPromise = fullPromise.then((result) => result.output);
19
+ this.valuePromise = fullPromise.then((result) => result.value);
20
20
  }
21
21
  asFullResponse() {
22
22
  return this.fullPromise;
23
23
  }
24
24
  then(onfulfilled, onrejected) {
25
- return this.outputPromise.then(onfulfilled, onrejected);
25
+ return this.valuePromise.then(onfulfilled, onrejected);
26
26
  }
27
27
  catch(onrejected) {
28
- return this.outputPromise.catch(onrejected);
28
+ return this.valuePromise.catch(onrejected);
29
29
  }
30
30
  finally(onfinally) {
31
- return this.outputPromise.finally(onfinally);
31
+ return this.valuePromise.finally(onfinally);
32
32
  }
33
33
  }
@@ -18,7 +18,7 @@ export interface Model<SETTINGS extends ModelSettings> {
18
18
  * The `withSettings` method creates a new model with the same configuration as the original model, but with the specified settings changed.
19
19
  *
20
20
  * @example
21
- * const model = new OpenAITextGenerationModel({
21
+ * const model = new OpenAICompletionModel({
22
22
  * model: "gpt-3.5-turbo-instruct",
23
23
  * maxCompletionTokens: 500,
24
24
  * });
@@ -1,14 +1,12 @@
1
1
  import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
2
2
  import { ModelInformation } from "./ModelInformation.js";
3
- import { ImageDescriptionFinishedEvent, ImageDescriptionStartedEvent } from "./describe-image/ImageDescriptionEvent.js";
4
3
  import { EmbeddingFinishedEvent, EmbeddingStartedEvent } from "./embed/EmbeddingEvent.js";
5
4
  import { ImageGenerationFinishedEvent, ImageGenerationStartedEvent } from "./generate-image/ImageGenerationEvent.js";
5
+ import { SpeechGenerationFinishedEvent, SpeechGenerationStartedEvent, SpeechStreamingFinishedEvent, SpeechStreamingStartedEvent } from "./generate-speech/SpeechGenerationEvent.js";
6
6
  import { StructureGenerationFinishedEvent, StructureGenerationStartedEvent } from "./generate-structure/StructureGenerationEvent.js";
7
7
  import { StructureStreamingFinishedEvent, StructureStreamingStartedEvent } from "./generate-structure/StructureStreamingEvent.js";
8
- import { TextGenerationFinishedEvent, TextGenerationStartedEvent } from "./generate-text/TextGenerationEvent.js";
9
- import { TextStreamingFinishedEvent, TextStreamingStartedEvent } from "./generate-text/TextStreamingEvent.js";
10
- import { SpeechSynthesisFinishedEvent, SpeechSynthesisStartedEvent } from "./synthesize-speech/SpeechSynthesisEvent.js";
11
- import { TranscriptionFinishedEvent, TranscriptionStartedEvent } from "./transcribe-speech/TranscriptionEvent.js";
8
+ import { TextGenerationFinishedEvent, TextGenerationStartedEvent, TextStreamingFinishedEvent, TextStreamingStartedEvent } from "./generate-text/TextGenerationEvent.js";
9
+ import { TranscriptionFinishedEvent, TranscriptionStartedEvent } from "./generate-transcription/TranscriptionEvent.js";
12
10
  export interface BaseModelCallStartedEvent extends BaseFunctionStartedEvent {
13
11
  model: ModelInformation;
14
12
  /**
@@ -49,5 +47,5 @@ export interface BaseModelCallFinishedEvent extends BaseFunctionFinishedEvent {
49
47
  */
50
48
  result: BaseModelCallFinishedEventResult;
51
49
  }
52
- export type ModelCallStartedEvent = EmbeddingStartedEvent | ImageDescriptionStartedEvent | ImageGenerationStartedEvent | StructureGenerationStartedEvent | StructureStreamingStartedEvent | SpeechSynthesisStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
53
- export type ModelCallFinishedEvent = EmbeddingFinishedEvent | ImageDescriptionFinishedEvent | ImageGenerationFinishedEvent | StructureGenerationFinishedEvent | StructureStreamingFinishedEvent | SpeechSynthesisFinishedEvent | TextGenerationFinishedEvent | TextStreamingFinishedEvent | TranscriptionFinishedEvent;
50
+ export type ModelCallStartedEvent = EmbeddingStartedEvent | ImageGenerationStartedEvent | SpeechGenerationStartedEvent | SpeechStreamingStartedEvent | StructureGenerationStartedEvent | StructureStreamingStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
51
+ export type ModelCallFinishedEvent = EmbeddingFinishedEvent | ImageGenerationFinishedEvent | SpeechGenerationFinishedEvent | SpeechStreamingFinishedEvent | StructureGenerationFinishedEvent | StructureStreamingFinishedEvent | TextGenerationFinishedEvent | TextStreamingFinishedEvent | TranscriptionFinishedEvent;
@@ -1,7 +1,7 @@
1
1
  import { Vector } from "../../core/Vector.js";
2
2
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
3
3
  export interface EmbeddingStartedEvent extends BaseModelCallStartedEvent {
4
- functionType: "embedding";
4
+ functionType: "embed";
5
5
  input: unknown | Array<unknown>;
6
6
  }
7
7
  export type EmbeddingFinishedEventResult = {
@@ -15,7 +15,7 @@ export type EmbeddingFinishedEventResult = {
15
15
  status: "abort";
16
16
  };
17
17
  export interface EmbeddingFinishedEvent extends BaseModelCallFinishedEvent {
18
- functionType: "embedding";
18
+ functionType: "embed";
19
19
  input: unknown | Array<unknown>;
20
20
  result: EmbeddingFinishedEventResult;
21
21
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.embed = exports.embedMany = 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
  /**
7
7
  * Generate embeddings for multiple values.
@@ -16,8 +16,8 @@ const ModelFunctionPromise_js_1 = require("../ModelFunctionPromise.cjs");
16
16
  * );
17
17
  */
18
18
  function embedMany(model, values, options) {
19
- return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
20
- functionType: "embedding",
19
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
20
+ functionType: "embed",
21
21
  input: values,
22
22
  model,
23
23
  options,
@@ -57,8 +57,8 @@ exports.embedMany = embedMany;
57
57
  * );
58
58
  */
59
59
  function embed(model, value, options) {
60
- return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeCall_js_1.executeCall)({
61
- functionType: "embedding",
60
+ return new ModelFunctionPromise_js_1.ModelFunctionPromise((0, executeStandardCall_js_1.executeStandardCall)({
61
+ functionType: "embed",
62
62
  input: value,
63
63
  model,
64
64
  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
  /**
4
4
  * Generate embeddings for multiple values.
@@ -13,8 +13,8 @@ import { ModelFunctionPromise } from "../ModelFunctionPromise.js";
13
13
  * );
14
14
  */
15
15
  export function embedMany(model, values, options) {
16
- return new ModelFunctionPromise(executeCall({
17
- functionType: "embedding",
16
+ return new ModelFunctionPromise(executeStandardCall({
17
+ functionType: "embed",
18
18
  input: values,
19
19
  model,
20
20
  options,
@@ -53,8 +53,8 @@ export function embedMany(model, values, options) {
53
53
  * );
54
54
  */
55
55
  export function embed(model, value, options) {
56
- return new ModelFunctionPromise(executeCall({
57
- functionType: "embedding",
56
+ return new ModelFunctionPromise(executeStandardCall({
57
+ functionType: "embed",
58
58
  input: value,
59
59
  model,
60
60
  options,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeCall = void 0;
3
+ exports.executeStandardCall = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
5
  const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
6
6
  const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
@@ -10,7 +10,7 @@ const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
10
  const getRun_js_1 = require("../core/getRun.cjs");
11
11
  const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
12
12
  const runSafe_js_1 = require("../util/runSafe.cjs");
13
- async function executeCall({ model, options, input, functionType, generateResponse, }) {
13
+ async function executeStandardCall({ model, options, input, functionType, generateResponse, }) {
14
14
  const run = await (0, getRun_js_1.getRun)(options?.run);
15
15
  const settings = model.settings;
16
16
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
@@ -27,6 +27,7 @@ async function executeCall({ model, options, input, functionType, generateRespon
27
27
  const startMetadata = {
28
28
  functionType,
29
29
  callId: `call-${(0, nanoid_1.nanoid)()}`,
30
+ parentCallId: options?.parentCallId,
30
31
  runId: run?.runId,
31
32
  sessionId: run?.sessionId,
32
33
  userId: run?.userId,
@@ -46,6 +47,7 @@ async function executeCall({ model, options, input, functionType, generateRespon
46
47
  logging: options?.logging,
47
48
  observers: options?.observers,
48
49
  run,
50
+ parentCallId: startMetadata.callId,
49
51
  }));
50
52
  const finishMetadata = {
51
53
  eventType: "finished",
@@ -104,4 +106,4 @@ async function executeCall({ model, options, input, functionType, generateRespon
104
106
  },
105
107
  };
106
108
  }
107
- exports.executeCall = executeCall;
109
+ exports.executeStandardCall = executeStandardCall;
@@ -2,7 +2,7 @@ import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  import { Model, ModelSettings } from "./Model.js";
3
3
  import { ModelCallStartedEvent } from "./ModelCallEvent.js";
4
4
  import { ModelCallMetadata } from "./ModelCallMetadata.js";
5
- export declare function executeCall<VALUE, MODEL extends Model<ModelSettings>>({ model, options, input, functionType, generateResponse, }: {
5
+ export declare function executeStandardCall<VALUE, MODEL extends Model<ModelSettings>>({ model, options, input, functionType, generateResponse, }: {
6
6
  model: MODEL;
7
7
  options?: FunctionOptions;
8
8
  input: unknown;
@@ -7,7 +7,7 @@ import { getFunctionCallLogger } from "../core/getFunctionCallLogger.js";
7
7
  import { getRun } from "../core/getRun.js";
8
8
  import { startDurationMeasurement } from "../util/DurationMeasurement.js";
9
9
  import { runSafe } from "../util/runSafe.js";
10
- export async function executeCall({ model, options, input, functionType, generateResponse, }) {
10
+ export async function executeStandardCall({ model, options, input, functionType, generateResponse, }) {
11
11
  const run = await getRun(options?.run);
12
12
  const settings = model.settings;
13
13
  const eventSource = new FunctionEventSource({
@@ -24,6 +24,7 @@ export async function executeCall({ model, options, input, functionType, generat
24
24
  const startMetadata = {
25
25
  functionType,
26
26
  callId: `call-${createId()}`,
27
+ parentCallId: options?.parentCallId,
27
28
  runId: run?.runId,
28
29
  sessionId: run?.sessionId,
29
30
  userId: run?.userId,
@@ -43,6 +44,7 @@ export async function executeCall({ model, options, input, functionType, generat
43
44
  logging: options?.logging,
44
45
  observers: options?.observers,
45
46
  run,
47
+ parentCallId: startMetadata.callId,
46
48
  }));
47
49
  const finishMetadata = {
48
50
  eventType: "finished",