modelfusion 0.21.0 → 0.22.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 (86) hide show
  1. package/composed-function/summarize/SummarizationFunction.d.ts +1 -1
  2. package/composed-function/summarize/summarizeRecursively.d.ts +1 -1
  3. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +1 -1
  4. package/{run → core}/DefaultRun.cjs +1 -1
  5. package/{run → core}/DefaultRun.js +1 -1
  6. package/{run → core}/FunctionEvent.d.ts +30 -6
  7. package/index.cjs +1 -1
  8. package/index.d.ts +1 -1
  9. package/index.js +1 -1
  10. package/model-function/Model.d.ts +1 -1
  11. package/model-function/ModelCallEvent.d.ts +20 -5
  12. package/model-function/ModelFunctionOptions.d.ts +1 -1
  13. package/model-function/SuccessfulModelCall.cjs +4 -2
  14. package/model-function/SuccessfulModelCall.d.ts +1 -1
  15. package/model-function/SuccessfulModelCall.js +4 -2
  16. package/model-function/embed-text/TextEmbeddingEvent.d.ts +12 -12
  17. package/model-function/embed-text/TextEmbeddingModel.d.ts +1 -1
  18. package/model-function/embed-text/embedText.cjs +6 -61
  19. package/model-function/embed-text/embedText.d.ts +1 -1
  20. package/model-function/embed-text/embedText.js +6 -61
  21. package/model-function/executeCall.cjs +32 -19
  22. package/model-function/executeCall.d.ts +4 -12
  23. package/model-function/executeCall.js +32 -19
  24. package/model-function/generate-image/ImageGenerationEvent.d.ts +9 -11
  25. package/model-function/generate-image/generateImage.cjs +2 -27
  26. package/model-function/generate-image/generateImage.js +2 -27
  27. package/model-function/generate-json/JsonGenerationEvent.d.ts +3 -16
  28. package/model-function/generate-json/generateJson.cjs +2 -27
  29. package/model-function/generate-json/generateJson.js +2 -27
  30. package/model-function/generate-json/generateJsonOrText.cjs +2 -27
  31. package/model-function/generate-json/generateJsonOrText.js +2 -27
  32. package/model-function/generate-text/TextGenerationEvent.d.ts +10 -10
  33. package/model-function/generate-text/TextStreamingEvent.d.ts +4 -17
  34. package/model-function/generate-text/generateText.cjs +2 -27
  35. package/model-function/generate-text/generateText.js +2 -27
  36. package/model-function/generate-text/streamText.cjs +24 -29
  37. package/model-function/generate-text/streamText.js +24 -29
  38. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +11 -10
  39. package/model-function/synthesize-speech/synthesizeSpeech.cjs +2 -28
  40. package/model-function/synthesize-speech/synthesizeSpeech.js +2 -28
  41. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +9 -11
  42. package/model-function/transcribe-speech/transcribe.cjs +2 -27
  43. package/model-function/transcribe-speech/transcribe.js +2 -27
  44. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
  45. package/model-provider/cohere/CohereTokenizer.d.ts +1 -1
  46. package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +1 -1
  47. package/package.json +1 -1
  48. package/text-chunk/split/SplitFunction.d.ts +1 -1
  49. package/tool/ExecuteToolEvent.d.ts +7 -16
  50. package/tool/Tool.d.ts +1 -1
  51. package/tool/WebSearchTool.cjs +25 -0
  52. package/tool/WebSearchTool.d.ts +56 -1
  53. package/tool/WebSearchTool.js +25 -0
  54. package/tool/executeTool.cjs +14 -8
  55. package/tool/executeTool.d.ts +1 -1
  56. package/tool/executeTool.js +14 -8
  57. package/vector-index/VectorIndex.d.ts +1 -1
  58. package/vector-index/memory/MemoryVectorIndex.d.ts +1 -1
  59. package/vector-index/pinecone/PineconeVectorIndex.d.ts +1 -1
  60. /package/{run → core}/ConsoleLogger.cjs +0 -0
  61. /package/{run → core}/ConsoleLogger.d.ts +0 -0
  62. /package/{run → core}/ConsoleLogger.js +0 -0
  63. /package/{run → core}/DefaultRun.d.ts +0 -0
  64. /package/{run → core}/FunctionEvent.cjs +0 -0
  65. /package/{run → core}/FunctionEvent.js +0 -0
  66. /package/{run → core}/FunctionEventSource.cjs +0 -0
  67. /package/{run → core}/FunctionEventSource.d.ts +0 -0
  68. /package/{run → core}/FunctionEventSource.js +0 -0
  69. /package/{run → core}/FunctionObserver.cjs +0 -0
  70. /package/{run → core}/FunctionObserver.d.ts +0 -0
  71. /package/{run → core}/FunctionObserver.js +0 -0
  72. /package/{run → core}/FunctionOptions.cjs +0 -0
  73. /package/{run → core}/FunctionOptions.d.ts +0 -0
  74. /package/{run → core}/FunctionOptions.js +0 -0
  75. /package/{run → core}/GlobalFunctionObservers.cjs +0 -0
  76. /package/{run → core}/GlobalFunctionObservers.d.ts +0 -0
  77. /package/{run → core}/GlobalFunctionObservers.js +0 -0
  78. /package/{run → core}/Run.cjs +0 -0
  79. /package/{run → core}/Run.d.ts +0 -0
  80. /package/{run → core}/Run.js +0 -0
  81. /package/{run → core}/Vector.cjs +0 -0
  82. /package/{run → core}/Vector.d.ts +0 -0
  83. /package/{run → core}/Vector.js +0 -0
  84. /package/{run → core}/index.cjs +0 -0
  85. /package/{run → core}/index.d.ts +0 -0
  86. /package/{run → core}/index.js +0 -0
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../../run/FunctionOptions.js";
1
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
2
2
  export type SummarizationFunction = (input: {
3
3
  text: string;
4
4
  }, options?: FunctionOptions) => PromiseLike<string>;
@@ -1,4 +1,4 @@
1
- import { Run } from "../../run/Run.js";
1
+ import { Run } from "../../core/Run.js";
2
2
  import { SplitFunction } from "../../text-chunk/split/SplitFunction.js";
3
3
  import { SummarizationFunction } from "./SummarizationFunction.js";
4
4
  export declare function summarizeRecursively({ summarize, split, join, text, }: {
@@ -1,6 +1,6 @@
1
1
  import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
2
2
  import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
3
- import { Run } from "../../run/Run.js";
3
+ import { Run } from "../../core/Run.js";
4
4
  /**
5
5
  * Recursively summarizes a text using a text generation model, e.g. for summarization or text extraction.
6
6
  * It automatically splits the text into optimal chunks that are small enough to be processed by the model,
@@ -5,7 +5,7 @@ const nanoid_1 = require("nanoid");
5
5
  const calculateCost_js_1 = require("../cost/calculateCost.cjs");
6
6
  const SuccessfulModelCall_js_1 = require("../model-function/SuccessfulModelCall.cjs");
7
7
  class DefaultRun {
8
- constructor({ runId = (0, nanoid_1.nanoid)(), sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
8
+ constructor({ runId = `run-${(0, nanoid_1.nanoid)()}`, sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
9
9
  Object.defineProperty(this, "runId", {
10
10
  enumerable: true,
11
11
  configurable: true,
@@ -2,7 +2,7 @@ import { nanoid as createId } from "nanoid";
2
2
  import { calculateCost } from "../cost/calculateCost.js";
3
3
  import { extractSuccessfulModelCalls, } from "../model-function/SuccessfulModelCall.js";
4
4
  export class DefaultRun {
5
- constructor({ runId = createId(), sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
5
+ constructor({ runId = `run-${createId()}`, sessionId, userId, abortSignal, observers, costCalculators = [], } = {}) {
6
6
  Object.defineProperty(this, "runId", {
7
7
  enumerable: true,
8
8
  configurable: true,
@@ -1,6 +1,6 @@
1
1
  import { ExecuteToolFinishedEvent, ExecuteToolStartedEvent } from "../tool/ExecuteToolEvent.js";
2
2
  import { ModelCallFinishedEvent, ModelCallStartedEvent } from "../model-function/ModelCallEvent.js";
3
- export type BaseFunctionEvent = {
3
+ export interface BaseFunctionEvent {
4
4
  /**
5
5
  * Unique identifier for the function call.
6
6
  */
@@ -36,16 +36,40 @@ export type BaseFunctionEvent = {
36
36
  * Type of the function. Defined in the subclasses.
37
37
  */
38
38
  functionType: string;
39
- };
40
- export type BaseFunctionStartedEvent = BaseFunctionEvent & {
39
+ }
40
+ export interface BaseFunctionStartedEvent extends BaseFunctionEvent {
41
41
  eventType: "started";
42
+ /**
43
+ * Timestamp when the function call started.
44
+ */
42
45
  startTimestamp: Date;
46
+ }
47
+ export type BaseFunctionFinishedEventResult = {
48
+ status: "success";
49
+ output: unknown;
50
+ } | {
51
+ status: "error";
52
+ error: unknown;
53
+ } | {
54
+ status: "abort";
43
55
  };
44
- export type BaseFunctionFinishedEvent = BaseFunctionEvent & {
56
+ export interface BaseFunctionFinishedEvent extends BaseFunctionEvent {
45
57
  eventType: "finished";
46
- status: "success" | "error" | "abort";
58
+ /**
59
+ * Timestamp when the function call started.
60
+ */
47
61
  startTimestamp: Date;
62
+ /**
63
+ * Timestamp when the function call finished.
64
+ */
48
65
  finishTimestamp: Date;
66
+ /**
67
+ * Duration of the function call in milliseconds.
68
+ */
49
69
  durationInMs: number;
50
- };
70
+ /**
71
+ * Result of the function call.
72
+ */
73
+ result: BaseFunctionFinishedEventResult;
74
+ }
51
75
  export type FunctionEvent = ModelCallStartedEvent | ExecuteToolStartedEvent | ModelCallFinishedEvent | ExecuteToolFinishedEvent;
package/index.cjs CHANGED
@@ -15,11 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./composed-function/index.cjs"), exports);
18
+ __exportStar(require("./core/index.cjs"), exports);
18
19
  __exportStar(require("./cost/index.cjs"), exports);
19
20
  __exportStar(require("./model-function/index.cjs"), exports);
20
21
  __exportStar(require("./model-provider/index.cjs"), exports);
21
22
  __exportStar(require("./prompt/index.cjs"), exports);
22
- __exportStar(require("./run/index.cjs"), exports);
23
23
  __exportStar(require("./text-chunk/index.cjs"), exports);
24
24
  __exportStar(require("./tool/index.cjs"), exports);
25
25
  __exportStar(require("./util/index.cjs"), exports);
package/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export * from "./composed-function/index.js";
2
+ export * from "./core/index.js";
2
3
  export * from "./cost/index.js";
3
4
  export * from "./model-function/index.js";
4
5
  export * from "./model-provider/index.js";
5
6
  export * from "./prompt/index.js";
6
- export * from "./run/index.js";
7
7
  export * from "./text-chunk/index.js";
8
8
  export * from "./tool/index.js";
9
9
  export * from "./util/index.js";
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export * from "./composed-function/index.js";
2
+ export * from "./core/index.js";
2
3
  export * from "./cost/index.js";
3
4
  export * from "./model-function/index.js";
4
5
  export * from "./model-provider/index.js";
5
6
  export * from "./prompt/index.js";
6
- export * from "./run/index.js";
7
7
  export * from "./text-chunk/index.js";
8
8
  export * from "./tool/index.js";
9
9
  export * from "./util/index.js";
@@ -1,5 +1,5 @@
1
1
  import { ModelInformation } from "./ModelInformation.js";
2
- import { FunctionObserver } from "../run/FunctionObserver.js";
2
+ import { FunctionObserver } from "../core/FunctionObserver.js";
3
3
  export interface ModelSettings {
4
4
  /**
5
5
  * Observers that are called when the model is used in run functions.
@@ -1,4 +1,4 @@
1
- import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../run/FunctionEvent.js";
1
+ import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
2
2
  import { ModelInformation } from "./ModelInformation.js";
3
3
  import { TextEmbeddingFinishedEvent, TextEmbeddingStartedEvent } from "./embed-text/TextEmbeddingEvent.js";
4
4
  import { ImageGenerationFinishedEvent, ImageGenerationStartedEvent } from "./generate-image/ImageGenerationEvent.js";
@@ -7,11 +7,26 @@ import { TextGenerationFinishedEvent, TextGenerationStartedEvent } from "./gener
7
7
  import { TextStreamingFinishedEvent, TextStreamingStartedEvent } from "./generate-text/TextStreamingEvent.js";
8
8
  import { SpeechSynthesisFinishedEvent, SpeechSynthesisStartedEvent } from "./synthesize-speech/SpeechSynthesisEvent.js";
9
9
  import { TranscriptionFinishedEvent, TranscriptionStartedEvent } from "./transcribe-speech/TranscriptionEvent.js";
10
- export type BaseModelCallStartedEvent = BaseFunctionStartedEvent & {
10
+ export interface BaseModelCallStartedEvent extends BaseFunctionStartedEvent {
11
11
  model: ModelInformation;
12
+ settings: unknown;
13
+ input: unknown;
14
+ }
15
+ export type BaseModelCallFinishedEventResult = {
16
+ status: "success";
17
+ response: unknown;
18
+ output: unknown;
19
+ } | {
20
+ status: "error";
21
+ error: unknown;
22
+ } | {
23
+ status: "abort";
12
24
  };
13
- export type ModelCallStartedEvent = ImageGenerationStartedEvent | JsonGenerationStartedEvent | SpeechSynthesisStartedEvent | TextEmbeddingStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
14
- export type BaseModelCallFinishedEvent = BaseFunctionFinishedEvent & {
25
+ export interface BaseModelCallFinishedEvent extends BaseFunctionFinishedEvent {
15
26
  model: ModelInformation;
16
- };
27
+ settings: unknown;
28
+ input: unknown;
29
+ result: BaseModelCallFinishedEventResult;
30
+ }
31
+ export type ModelCallStartedEvent = ImageGenerationStartedEvent | JsonGenerationStartedEvent | SpeechSynthesisStartedEvent | TextEmbeddingStartedEvent | TextGenerationStartedEvent | TextStreamingStartedEvent | TranscriptionStartedEvent;
17
32
  export type ModelCallFinishedEvent = ImageGenerationFinishedEvent | JsonGenerationFinishedEvent | SpeechSynthesisFinishedEvent | TextEmbeddingFinishedEvent | TextGenerationFinishedEvent | TextStreamingFinishedEvent | TranscriptionFinishedEvent;
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../run/FunctionOptions.js";
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  export interface ModelFunctionOptions<SETTINGS> extends FunctionOptions {
3
3
  settings?: Partial<SETTINGS>;
4
4
  }
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractSuccessfulModelCalls = void 0;
4
4
  function extractSuccessfulModelCalls(runFunctionEvents) {
5
5
  return runFunctionEvents
6
- .filter((event) => "status" in event && event.status === "success")
6
+ .filter((event) => "result" in event &&
7
+ "status" in event.result &&
8
+ event.result.status === "success")
7
9
  .map((event) => ({
8
10
  model: event.model,
9
11
  settings: event.settings,
10
- response: event.response,
12
+ response: event.result.response,
11
13
  type: event.functionType,
12
14
  }));
13
15
  }
@@ -1,4 +1,4 @@
1
- import { FunctionEvent } from "../run/FunctionEvent.js";
1
+ import { FunctionEvent } from "../core/FunctionEvent.js";
2
2
  import { ModelInformation } from "./ModelInformation.js";
3
3
  export type SuccessfulModelCall = {
4
4
  type: "image-generation" | "json-generation" | "json-or-text-generation" | "speech-synthesis" | "text-embedding" | "text-generation" | "text-streaming" | "transcription";
@@ -1,10 +1,12 @@
1
1
  export function extractSuccessfulModelCalls(runFunctionEvents) {
2
2
  return runFunctionEvents
3
- .filter((event) => "status" in event && event.status === "success")
3
+ .filter((event) => "result" in event &&
4
+ "status" in event.result &&
5
+ event.result.status === "success")
4
6
  .map((event) => ({
5
7
  model: event.model,
6
8
  settings: event.settings,
7
- response: event.response,
9
+ response: event.result.response,
8
10
  type: event.functionType,
9
11
  }));
10
12
  }
@@ -1,21 +1,21 @@
1
- import { Vector } from "../../run/Vector.js";
1
+ import { Vector } from "../../core/Vector.js";
2
2
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
3
- export type TextEmbeddingStartedEvent = BaseModelCallStartedEvent & {
3
+ export interface TextEmbeddingStartedEvent extends BaseModelCallStartedEvent {
4
4
  functionType: "text-embedding";
5
- settings: unknown;
6
- texts: Array<string>;
7
- };
8
- export type TextEmbeddingFinishedEvent = BaseModelCallFinishedEvent & {
9
- functionType: "text-embedding";
10
- settings: unknown;
11
- texts: Array<string>;
12
- } & ({
5
+ input: string | Array<string>;
6
+ }
7
+ export type TextEmbeddingFinishedEventResult = {
13
8
  status: "success";
14
9
  response: unknown;
15
- generatedEmbeddings: Array<Vector>;
10
+ output: Vector | Array<Vector>;
16
11
  } | {
17
12
  status: "error";
18
13
  error: unknown;
19
14
  } | {
20
15
  status: "abort";
21
- });
16
+ };
17
+ export interface TextEmbeddingFinishedEvent extends BaseModelCallFinishedEvent {
18
+ functionType: "text-embedding";
19
+ input: string | Array<string>;
20
+ result: TextEmbeddingFinishedEventResult;
21
+ }
@@ -1,4 +1,4 @@
1
- import { Vector } from "../../run/Vector.js";
1
+ import { Vector } from "../../core/Vector.js";
2
2
  import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
3
3
  import { Model, ModelSettings } from "../Model.js";
4
4
  export interface TextEmbeddingModelSettings extends ModelSettings {
@@ -16,6 +16,8 @@ const executeCall_js_1 = require("../executeCall.cjs");
16
16
  */
17
17
  function embedTexts(model, texts, options) {
18
18
  return (0, executeCall_js_1.executeCall)({
19
+ functionType: "text-embedding",
20
+ input: texts,
19
21
  model,
20
22
  options,
21
23
  generateResponse: (options) => {
@@ -34,33 +36,6 @@ function embedTexts(model, texts, options) {
34
36
  }
35
37
  return embeddings;
36
38
  },
37
- getStartEvent: (metadata, settings) => ({
38
- ...metadata,
39
- functionType: "text-embedding",
40
- settings,
41
- texts,
42
- }),
43
- getAbortEvent: (metadata, settings) => ({
44
- ...metadata,
45
- functionType: "text-embedding",
46
- settings,
47
- texts,
48
- }),
49
- getFailureEvent: (metadata, settings, error) => ({
50
- ...metadata,
51
- functionType: "text-embedding",
52
- settings,
53
- error,
54
- texts,
55
- }),
56
- getSuccessEvent: (metadata, settings, response, output) => ({
57
- ...metadata,
58
- functionType: "text-embedding",
59
- settings,
60
- texts,
61
- response,
62
- generatedEmbeddings: output,
63
- }),
64
39
  });
65
40
  }
66
41
  exports.embedTexts = embedTexts;
@@ -74,43 +49,13 @@ exports.embedTexts = embedTexts;
74
49
  * );
75
50
  */
76
51
  function embedText(model, text, options) {
77
- const texts = [text];
78
52
  return (0, executeCall_js_1.executeCall)({
53
+ functionType: "text-embedding",
54
+ input: text,
79
55
  model,
80
56
  options,
81
- generateResponse: (options) => {
82
- return model.generateEmbeddingResponse(texts, options);
83
- },
84
- extractOutputValue: (result) => {
85
- return model.extractEmbeddings(result)[0];
86
- },
87
- getStartEvent: (metadata, settings) => ({
88
- ...metadata,
89
- functionType: "text-embedding",
90
- settings,
91
- texts,
92
- }),
93
- getAbortEvent: (metadata, settings) => ({
94
- ...metadata,
95
- functionType: "text-embedding",
96
- settings,
97
- texts,
98
- }),
99
- getFailureEvent: (metadata, settings, error) => ({
100
- ...metadata,
101
- functionType: "text-embedding",
102
- settings,
103
- error,
104
- texts,
105
- }),
106
- getSuccessEvent: (metadata, settings, response, output) => ({
107
- ...metadata,
108
- functionType: "text-embedding",
109
- settings,
110
- texts,
111
- response,
112
- generatedEmbeddings: [output],
113
- }),
57
+ generateResponse: (options) => model.generateEmbeddingResponse([text], options),
58
+ extractOutputValue: (result) => model.extractEmbeddings(result)[0],
114
59
  });
115
60
  }
116
61
  exports.embedText = embedText;
@@ -1,4 +1,4 @@
1
- import { Vector } from "../../run/Vector.js";
1
+ import { Vector } from "../../core/Vector.js";
2
2
  import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
3
3
  import { ModelFunctionPromise } from "../executeCall.js";
4
4
  import { TextEmbeddingModel, TextEmbeddingModelSettings } from "./TextEmbeddingModel.js";
@@ -13,6 +13,8 @@ import { executeCall } from "../executeCall.js";
13
13
  */
14
14
  export function embedTexts(model, texts, options) {
15
15
  return executeCall({
16
+ functionType: "text-embedding",
17
+ input: texts,
16
18
  model,
17
19
  options,
18
20
  generateResponse: (options) => {
@@ -31,33 +33,6 @@ export function embedTexts(model, texts, options) {
31
33
  }
32
34
  return embeddings;
33
35
  },
34
- getStartEvent: (metadata, settings) => ({
35
- ...metadata,
36
- functionType: "text-embedding",
37
- settings,
38
- texts,
39
- }),
40
- getAbortEvent: (metadata, settings) => ({
41
- ...metadata,
42
- functionType: "text-embedding",
43
- settings,
44
- texts,
45
- }),
46
- getFailureEvent: (metadata, settings, error) => ({
47
- ...metadata,
48
- functionType: "text-embedding",
49
- settings,
50
- error,
51
- texts,
52
- }),
53
- getSuccessEvent: (metadata, settings, response, output) => ({
54
- ...metadata,
55
- functionType: "text-embedding",
56
- settings,
57
- texts,
58
- response,
59
- generatedEmbeddings: output,
60
- }),
61
36
  });
62
37
  }
63
38
  /**
@@ -70,42 +45,12 @@ export function embedTexts(model, texts, options) {
70
45
  * );
71
46
  */
72
47
  export function embedText(model, text, options) {
73
- const texts = [text];
74
48
  return executeCall({
49
+ functionType: "text-embedding",
50
+ input: text,
75
51
  model,
76
52
  options,
77
- generateResponse: (options) => {
78
- return model.generateEmbeddingResponse(texts, options);
79
- },
80
- extractOutputValue: (result) => {
81
- return model.extractEmbeddings(result)[0];
82
- },
83
- getStartEvent: (metadata, settings) => ({
84
- ...metadata,
85
- functionType: "text-embedding",
86
- settings,
87
- texts,
88
- }),
89
- getAbortEvent: (metadata, settings) => ({
90
- ...metadata,
91
- functionType: "text-embedding",
92
- settings,
93
- texts,
94
- }),
95
- getFailureEvent: (metadata, settings, error) => ({
96
- ...metadata,
97
- functionType: "text-embedding",
98
- settings,
99
- error,
100
- texts,
101
- }),
102
- getSuccessEvent: (metadata, settings, response, output) => ({
103
- ...metadata,
104
- functionType: "text-embedding",
105
- settings,
106
- texts,
107
- response,
108
- generatedEmbeddings: [output],
109
- }),
53
+ generateResponse: (options) => model.generateEmbeddingResponse([text], options),
54
+ extractOutputValue: (result) => model.extractEmbeddings(result)[0],
110
55
  });
111
56
  }
@@ -2,19 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModelFunctionPromise = exports.executeCall = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
- const FunctionEventSource_js_1 = require("../run/FunctionEventSource.cjs");
6
- const GlobalFunctionObservers_js_1 = require("../run/GlobalFunctionObservers.cjs");
5
+ const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
6
+ const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
7
7
  const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
8
8
  const AbortError_js_1 = require("../util/api/AbortError.cjs");
9
9
  const runSafe_js_1 = require("../util/runSafe.cjs");
10
- function executeCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
10
+ function executeCall({ model, options, input, functionType, generateResponse, extractOutputValue, }) {
11
11
  return new ModelFunctionPromise(doExecuteCall({
12
12
  model,
13
13
  options,
14
- getStartEvent,
15
- getAbortEvent,
16
- getFailureEvent,
17
- getSuccessEvent,
14
+ input,
15
+ functionType,
18
16
  generateResponse,
19
17
  extractOutputValue,
20
18
  }));
@@ -54,7 +52,7 @@ class ModelFunctionPromise extends Promise {
54
52
  }
55
53
  }
56
54
  exports.ModelFunctionPromise = ModelFunctionPromise;
57
- async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }) {
55
+ async function doExecuteCall({ model, options, input, functionType, generateResponse, extractOutputValue, }) {
58
56
  if (options?.settings != null) {
59
57
  model = model.withSettings(options.settings);
60
58
  options = {
@@ -82,13 +80,16 @@ async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, get
82
80
  userId: run?.userId,
83
81
  functionId: options?.functionId,
84
82
  model: model.modelInformation,
83
+ functionType,
84
+ input,
85
+ settings,
85
86
  timestamp: durationMeasurement.startDate,
86
87
  startTimestamp: durationMeasurement.startDate,
87
88
  };
88
- eventSource.notify(getStartEvent({
89
+ eventSource.notify({
89
90
  ...startMetadata,
90
91
  eventType: "started",
91
- }, settings));
92
+ });
92
93
  const result = await (0, runSafe_js_1.runSafe)(() => generateResponse({
93
94
  functionId: options?.functionId,
94
95
  settings,
@@ -102,24 +103,36 @@ async function doExecuteCall({ model, options, getStartEvent, getAbortEvent, get
102
103
  };
103
104
  if (!result.ok) {
104
105
  if (result.isAborted) {
105
- eventSource.notify(getAbortEvent({
106
+ eventSource.notify({
106
107
  ...finishMetadata,
107
- status: "abort",
108
- }, settings));
108
+ eventType: "finished",
109
+ result: {
110
+ status: "abort",
111
+ },
112
+ });
109
113
  throw new AbortError_js_1.AbortError();
110
114
  }
111
- eventSource.notify(getFailureEvent({
115
+ eventSource.notify({
112
116
  ...finishMetadata,
113
- status: "error",
114
- }, settings, result.error));
117
+ eventType: "finished",
118
+ result: {
119
+ status: "error",
120
+ error: result.error,
121
+ },
122
+ });
115
123
  throw result.error;
116
124
  }
117
125
  const response = result.output;
118
126
  const output = extractOutputValue(response);
119
- eventSource.notify(getSuccessEvent({
127
+ eventSource.notify({
120
128
  ...finishMetadata,
121
- status: "success",
122
- }, settings, response, output));
129
+ eventType: "finished",
130
+ result: {
131
+ status: "success",
132
+ response,
133
+ output,
134
+ },
135
+ });
123
136
  return {
124
137
  output,
125
138
  response,
@@ -1,5 +1,5 @@
1
1
  import { Model, ModelSettings } from "./Model.js";
2
- import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent, ModelCallFinishedEvent, ModelCallStartedEvent } from "./ModelCallEvent.js";
2
+ import { ModelCallStartedEvent } from "./ModelCallEvent.js";
3
3
  import { ModelFunctionOptions } from "./ModelFunctionOptions.js";
4
4
  export type CallMetadata<MODEL extends Model<unknown>> = {
5
5
  callId: string;
@@ -12,19 +12,11 @@ export type CallMetadata<MODEL extends Model<unknown>> = {
12
12
  finishTimestamp: Date;
13
13
  durationInMs: number;
14
14
  };
15
- export declare function executeCall<SETTINGS extends ModelSettings, MODEL extends Model<SETTINGS>, OUTPUT, RESPONSE>({ model, options, getStartEvent, getAbortEvent, getFailureEvent, getSuccessEvent, generateResponse, extractOutputValue, }: {
15
+ export declare function executeCall<SETTINGS extends ModelSettings, MODEL extends Model<SETTINGS>, OUTPUT, RESPONSE>({ model, options, input, functionType, generateResponse, extractOutputValue, }: {
16
16
  model: MODEL;
17
17
  options?: ModelFunctionOptions<SETTINGS>;
18
- getStartEvent: (metadata: Omit<BaseModelCallStartedEvent, "functionType">, settings: SETTINGS) => ModelCallStartedEvent;
19
- getAbortEvent: (metadata: Omit<BaseModelCallFinishedEvent & {
20
- status: "abort";
21
- }, "functionType">, settings: SETTINGS) => ModelCallFinishedEvent;
22
- getFailureEvent: (metadata: Omit<BaseModelCallFinishedEvent & {
23
- status: "error";
24
- }, "functionType">, settings: SETTINGS, error: unknown) => ModelCallFinishedEvent;
25
- getSuccessEvent: (metadata: Omit<BaseModelCallFinishedEvent & {
26
- status: "success";
27
- }, "functionType">, settings: SETTINGS, response: RESPONSE, output: OUTPUT) => ModelCallFinishedEvent;
18
+ input: unknown;
19
+ functionType: ModelCallStartedEvent["functionType"];
28
20
  generateResponse: (options: ModelFunctionOptions<SETTINGS>) => PromiseLike<RESPONSE>;
29
21
  extractOutputValue: (response: RESPONSE) => OUTPUT;
30
22
  }): ModelFunctionPromise<MODEL, OUTPUT, RESPONSE>;