modelfusion 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +5 -7
  2. package/composed-function/summarize/SummarizationFunction.d.ts +3 -3
  3. package/model-function/Model.d.ts +5 -2
  4. package/model-function/ModelCallEvent.d.ts +3 -3
  5. package/model-function/ModelFunctionOptions.d.ts +4 -0
  6. package/model-function/SuccessfulModelCall.cjs +3 -15
  7. package/model-function/SuccessfulModelCall.d.ts +2 -2
  8. package/model-function/SuccessfulModelCall.js +3 -15
  9. package/model-function/embed-text/TextEmbeddingEvent.d.ts +6 -8
  10. package/model-function/embed-text/TextEmbeddingModel.d.ts +2 -2
  11. package/model-function/embed-text/embedText.cjs +16 -22
  12. package/model-function/embed-text/embedText.d.ts +3 -3
  13. package/model-function/embed-text/embedText.js +16 -22
  14. package/model-function/executeCall.cjs +30 -8
  15. package/model-function/executeCall.d.ts +16 -9
  16. package/model-function/executeCall.js +30 -8
  17. package/model-function/generate-image/ImageGenerationEvent.d.ts +6 -8
  18. package/model-function/generate-image/ImageGenerationModel.d.ts +2 -2
  19. package/model-function/generate-image/generateImage.cjs +8 -11
  20. package/model-function/generate-image/generateImage.d.ts +2 -2
  21. package/model-function/generate-image/generateImage.js +8 -11
  22. package/model-function/generate-json/GenerateJsonModel.d.ts +2 -2
  23. package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +2 -2
  24. package/model-function/generate-json/JsonGenerationEvent.d.ts +6 -8
  25. package/model-function/generate-json/JsonTextGenerationModel.d.ts +2 -2
  26. package/model-function/generate-json/generateJson.cjs +8 -11
  27. package/model-function/generate-json/generateJson.d.ts +2 -2
  28. package/model-function/generate-json/generateJson.js +8 -11
  29. package/model-function/generate-json/generateJsonOrText.cjs +8 -11
  30. package/model-function/generate-json/generateJsonOrText.d.ts +2 -2
  31. package/model-function/generate-json/generateJsonOrText.js +8 -11
  32. package/model-function/generate-text/TextGenerationEvent.d.ts +6 -8
  33. package/model-function/generate-text/TextGenerationModel.d.ts +3 -3
  34. package/model-function/generate-text/TextStreamingEvent.d.ts +6 -8
  35. package/model-function/generate-text/generateText.cjs +8 -11
  36. package/model-function/generate-text/generateText.d.ts +2 -2
  37. package/model-function/generate-text/generateText.js +8 -11
  38. package/model-function/generate-text/streamText.cjs +38 -23
  39. package/model-function/generate-text/streamText.d.ts +5 -5
  40. package/model-function/generate-text/streamText.js +38 -23
  41. package/model-function/index.cjs +1 -1
  42. package/model-function/index.d.ts +1 -1
  43. package/model-function/index.js +1 -1
  44. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +6 -8
  45. package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +2 -2
  46. package/model-function/synthesize-speech/synthesizeSpeech.cjs +8 -10
  47. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
  48. package/model-function/synthesize-speech/synthesizeSpeech.js +8 -10
  49. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +6 -8
  50. package/model-function/transcribe-speech/TranscriptionModel.d.ts +2 -2
  51. package/model-function/transcribe-speech/transcribe.cjs +8 -11
  52. package/model-function/transcribe-speech/transcribe.d.ts +2 -2
  53. package/model-function/transcribe-speech/transcribe.js +8 -11
  54. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  55. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
  56. package/model-provider/cohere/CohereTextGenerationModel.d.ts +4 -4
  57. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
  58. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +3 -3
  59. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +3 -3
  60. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +3 -3
  61. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +4 -4
  62. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +3 -3
  63. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +3 -3
  64. package/model-provider/openai/OpenAITextGenerationModel.d.ts +4 -4
  65. package/model-provider/openai/OpenAITranscriptionModel.d.ts +3 -3
  66. package/model-provider/openai/chat/OpenAIChatModel.d.ts +5 -5
  67. package/model-provider/stability/StabilityImageGenerationModel.d.ts +3 -3
  68. package/package.json +1 -1
  69. package/prompt/PromptFormatTextGenerationModel.d.ts +3 -3
  70. package/run/ConsoleLogger.cjs +1 -4
  71. package/run/ConsoleLogger.d.ts +4 -5
  72. package/run/ConsoleLogger.js +1 -4
  73. package/run/DefaultRun.cjs +1 -4
  74. package/run/DefaultRun.d.ts +5 -5
  75. package/run/DefaultRun.js +1 -4
  76. package/run/FunctionEvent.d.ts +51 -0
  77. package/run/{RunFunctionEventSource.js → FunctionEventSource.cjs} +7 -13
  78. package/run/FunctionEventSource.d.ts +12 -0
  79. package/run/{RunFunctionEventSource.cjs → FunctionEventSource.js} +3 -17
  80. package/run/FunctionObserver.d.ts +7 -0
  81. package/run/FunctionOptions.d.ts +19 -0
  82. package/run/GlobalFunctionObservers.cjs +12 -0
  83. package/run/GlobalFunctionObservers.d.ts +3 -0
  84. package/run/GlobalFunctionObservers.js +7 -0
  85. package/run/Run.d.ts +2 -2
  86. package/run/index.cjs +5 -5
  87. package/run/index.d.ts +5 -5
  88. package/run/index.js +5 -5
  89. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -0
  90. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.d.ts +2 -2
  91. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -0
  92. package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +2 -2
  93. package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +2 -2
  94. package/text-chunk/split/SplitFunction.d.ts +3 -3
  95. package/text-chunk/upsertTextChunks.d.ts +2 -2
  96. package/tool/ExecuteToolEvent.d.ts +6 -8
  97. package/tool/Tool.d.ts +3 -3
  98. package/tool/WebSearchTool.d.ts +2 -1
  99. package/tool/executeTool.cjs +28 -26
  100. package/tool/executeTool.d.ts +5 -4
  101. package/tool/executeTool.js +28 -26
  102. package/tool/useTool.cjs +2 -6
  103. package/tool/useTool.d.ts +2 -2
  104. package/tool/useTool.js +2 -6
  105. package/tool/useToolOrGenerateText.cjs +1 -3
  106. package/tool/useToolOrGenerateText.d.ts +2 -2
  107. package/tool/useToolOrGenerateText.js +1 -3
  108. package/util/DurationMeasurement.cjs +6 -0
  109. package/util/DurationMeasurement.d.ts +1 -0
  110. package/util/DurationMeasurement.js +6 -0
  111. package/util/api/postToApi.cjs +8 -0
  112. package/util/api/postToApi.js +8 -0
  113. package/model-function/FunctionOptions.d.ts +0 -6
  114. package/run/IdMetadata.d.ts +0 -7
  115. package/run/RunFunction.d.ts +0 -9
  116. package/run/RunFunctionEvent.d.ts +0 -12
  117. package/run/RunFunctionEventSource.d.ts +0 -13
  118. package/run/RunFunctionObserver.cjs +0 -2
  119. package/run/RunFunctionObserver.d.ts +0 -5
  120. package/run/RunFunctionObserver.js +0 -1
  121. /package/model-function/{FunctionOptions.cjs → ModelFunctionOptions.cjs} +0 -0
  122. /package/model-function/{FunctionOptions.js → ModelFunctionOptions.js} +0 -0
  123. /package/run/{IdMetadata.cjs → FunctionEvent.cjs} +0 -0
  124. /package/run/{IdMetadata.js → FunctionEvent.js} +0 -0
  125. /package/run/{RunFunction.cjs → FunctionObserver.cjs} +0 -0
  126. /package/run/{RunFunction.js → FunctionObserver.js} +0 -0
  127. /package/run/{RunFunctionEvent.cjs → FunctionOptions.cjs} +0 -0
  128. /package/run/{RunFunctionEvent.js → FunctionOptions.js} +0 -0
@@ -24,30 +24,27 @@ function generateImage(model, prompt, options) {
24
24
  generateResponse: (options) => model.generateImageResponse(prompt, options),
25
25
  extractOutputValue: model.extractBase64Image,
26
26
  getStartEvent: (metadata, settings) => ({
27
- type: "image-generation-started",
28
- metadata,
27
+ ...metadata,
28
+ functionType: "image-generation",
29
29
  settings,
30
30
  prompt,
31
31
  }),
32
32
  getAbortEvent: (metadata, settings) => ({
33
- type: "image-generation-finished",
34
- status: "abort",
35
- metadata,
33
+ ...metadata,
34
+ functionType: "image-generation",
36
35
  settings,
37
36
  prompt,
38
37
  }),
39
38
  getFailureEvent: (metadata, settings, error) => ({
40
- type: "image-generation-finished",
41
- status: "failure",
42
- metadata,
39
+ ...metadata,
40
+ functionType: "image-generation",
43
41
  settings,
44
42
  prompt,
45
43
  error,
46
44
  }),
47
45
  getSuccessEvent: (metadata, settings, response, output) => ({
48
- type: "image-generation-finished",
49
- status: "success",
50
- metadata,
46
+ ...metadata,
47
+ functionType: "image-generation",
51
48
  settings,
52
49
  prompt,
53
50
  response,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { ModelFunctionPromise } from "../executeCall.js";
3
3
  import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGenerationModel.js";
4
4
  /**
@@ -16,4 +16,4 @@ import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGener
16
16
  * ]
17
17
  * );
18
18
  */
19
- export declare function generateImage<PROMPT, RESPONSE, SETTINGS extends ImageGenerationModelSettings>(model: ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>, prompt: PROMPT, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>, string, RESPONSE>;
19
+ export declare function generateImage<PROMPT, RESPONSE, SETTINGS extends ImageGenerationModelSettings>(model: ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>, string, RESPONSE>;
@@ -21,30 +21,27 @@ export function generateImage(model, prompt, options) {
21
21
  generateResponse: (options) => model.generateImageResponse(prompt, options),
22
22
  extractOutputValue: model.extractBase64Image,
23
23
  getStartEvent: (metadata, settings) => ({
24
- type: "image-generation-started",
25
- metadata,
24
+ ...metadata,
25
+ functionType: "image-generation",
26
26
  settings,
27
27
  prompt,
28
28
  }),
29
29
  getAbortEvent: (metadata, settings) => ({
30
- type: "image-generation-finished",
31
- status: "abort",
32
- metadata,
30
+ ...metadata,
31
+ functionType: "image-generation",
33
32
  settings,
34
33
  prompt,
35
34
  }),
36
35
  getFailureEvent: (metadata, settings, error) => ({
37
- type: "image-generation-finished",
38
- status: "failure",
39
- metadata,
36
+ ...metadata,
37
+ functionType: "image-generation",
40
38
  settings,
41
39
  prompt,
42
40
  error,
43
41
  }),
44
42
  getSuccessEvent: (metadata, settings, response, output) => ({
45
- type: "image-generation-finished",
46
- status: "success",
47
- metadata,
43
+ ...metadata,
44
+ functionType: "image-generation",
48
45
  settings,
49
46
  prompt,
50
47
  response,
@@ -1,8 +1,8 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { Model, ModelSettings } from "../Model.js";
3
3
  export interface GenerateJsonModelSettings extends ModelSettings {
4
4
  }
5
5
  export interface GenerateJsonModel<PROMPT, RESPONSE, SETTINGS extends GenerateJsonModelSettings> extends Model<SETTINGS> {
6
- generateJsonResponse(prompt: PROMPT, options?: FunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
6
+ generateJsonResponse(prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
7
7
  extractJson(response: RESPONSE): unknown;
8
8
  }
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { Model, ModelSettings } from "../Model.js";
3
3
  export interface GenerateJsonOrTextModelSettings extends ModelSettings {
4
4
  }
@@ -14,5 +14,5 @@ export interface GenerateJsonOrTextPrompt<RESPONSE> {
14
14
  };
15
15
  }
16
16
  export interface GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings> extends Model<SETTINGS> {
17
- generateJsonResponse(prompt: PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
17
+ generateJsonResponse(prompt: PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: ModelFunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
18
18
  }
@@ -1,13 +1,11 @@
1
- import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
2
- export type JsonGenerationStartedEvent = {
3
- type: "json-generation-started" | "json-or-text-generation-started";
4
- metadata: ModelCallStartedEventMetadata;
1
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
+ export type JsonGenerationStartedEvent = BaseModelCallStartedEvent & {
3
+ functionType: "json-generation" | "json-or-text-generation";
5
4
  settings: unknown;
6
5
  prompt: unknown;
7
6
  };
8
- export type JsonGenerationFinishedEvent = {
9
- type: "json-generation-finished" | "json-or-text-generation-finished";
10
- metadata: ModelCallFinishedEventMetadata;
7
+ export type JsonGenerationFinishedEvent = BaseModelCallFinishedEvent & {
8
+ functionType: "json-generation" | "json-or-text-generation";
11
9
  settings: unknown;
12
10
  prompt: unknown;
13
11
  } & ({
@@ -15,7 +13,7 @@ export type JsonGenerationFinishedEvent = {
15
13
  response: unknown;
16
14
  generatedJson: unknown;
17
15
  } | {
18
- status: "failure";
16
+ status: "error";
19
17
  error: unknown;
20
18
  } | {
21
19
  status: "abort";
@@ -2,7 +2,7 @@ import { TextGenerationModel, TextGenerationModelSettings } from "../generate-te
2
2
  import { SchemaDefinition } from "./SchemaDefinition.js";
3
3
  import { InstructionWithSchema } from "./InstructionWithSchemaPrompt.js";
4
4
  import { GenerateJsonModel } from "./GenerateJsonModel.js";
5
- import { FunctionOptions } from "../FunctionOptions.js";
5
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
6
6
  export type JsonTextPromptFormat = {
7
7
  createPrompt: (prompt: {
8
8
  instruction: string;
@@ -19,7 +19,7 @@ export declare class JsonTextGenerationModel<SETTINGS extends TextGenerationMode
19
19
  });
20
20
  get modelInformation(): import("../ModelInformation.js").ModelInformation;
21
21
  get settings(): SETTINGS;
22
- generateJsonResponse(prompt: InstructionWithSchema<string, unknown>, options?: FunctionOptions<SETTINGS> | undefined): Promise<string>;
22
+ generateJsonResponse(prompt: InstructionWithSchema<string, unknown>, options?: ModelFunctionOptions<SETTINGS> | undefined): Promise<string>;
23
23
  extractJson(response: string): unknown;
24
24
  withSettings(additionalSettings: Partial<SETTINGS>): this;
25
25
  }
@@ -22,30 +22,27 @@ function generateJson(model, schemaDefinition, prompt, options) {
22
22
  return parseResult.data;
23
23
  },
24
24
  getStartEvent: (metadata, settings) => ({
25
- type: "json-generation-started",
26
- metadata,
25
+ ...metadata,
26
+ functionType: "json-generation",
27
27
  settings,
28
28
  prompt,
29
29
  }),
30
30
  getAbortEvent: (metadata, settings) => ({
31
- type: "json-generation-finished",
32
- status: "abort",
33
- metadata,
31
+ ...metadata,
32
+ functionType: "json-generation",
34
33
  settings,
35
34
  prompt,
36
35
  }),
37
36
  getFailureEvent: (metadata, settings, error) => ({
38
- type: "json-generation-finished",
39
- status: "failure",
40
- metadata,
37
+ ...metadata,
38
+ functionType: "json-generation",
41
39
  settings,
42
40
  prompt,
43
41
  error,
44
42
  }),
45
43
  getSuccessEvent: (metadata, settings, response, output) => ({
46
- type: "json-generation-finished",
47
- status: "success",
48
- metadata,
44
+ ...metadata,
45
+ functionType: "json-generation",
49
46
  settings,
50
47
  prompt,
51
48
  response,
@@ -1,5 +1,5 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { ModelFunctionPromise } from "../executeCall.js";
3
3
  import { GenerateJsonModel, GenerateJsonModelSettings } from "./GenerateJsonModel.js";
4
4
  import { SchemaDefinition } from "./SchemaDefinition.js";
5
- export declare function generateJson<STRUCTURE, PROMPT, RESPONSE, NAME extends string, SETTINGS extends GenerateJsonModelSettings>(model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinition: SchemaDefinition<NAME, STRUCTURE>, prompt: (schemaDefinition: SchemaDefinition<NAME, STRUCTURE>) => PROMPT, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, STRUCTURE, RESPONSE>;
5
+ export declare function generateJson<STRUCTURE, PROMPT, RESPONSE, NAME extends string, SETTINGS extends GenerateJsonModelSettings>(model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinition: SchemaDefinition<NAME, STRUCTURE>, prompt: (schemaDefinition: SchemaDefinition<NAME, STRUCTURE>) => PROMPT, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, STRUCTURE, RESPONSE>;
@@ -19,30 +19,27 @@ export function generateJson(model, schemaDefinition, prompt, options) {
19
19
  return parseResult.data;
20
20
  },
21
21
  getStartEvent: (metadata, settings) => ({
22
- type: "json-generation-started",
23
- metadata,
22
+ ...metadata,
23
+ functionType: "json-generation",
24
24
  settings,
25
25
  prompt,
26
26
  }),
27
27
  getAbortEvent: (metadata, settings) => ({
28
- type: "json-generation-finished",
29
- status: "abort",
30
- metadata,
28
+ ...metadata,
29
+ functionType: "json-generation",
31
30
  settings,
32
31
  prompt,
33
32
  }),
34
33
  getFailureEvent: (metadata, settings, error) => ({
35
- type: "json-generation-finished",
36
- status: "failure",
37
- metadata,
34
+ ...metadata,
35
+ functionType: "json-generation",
38
36
  settings,
39
37
  prompt,
40
38
  error,
41
39
  }),
42
40
  getSuccessEvent: (metadata, settings, response, output) => ({
43
- type: "json-generation-finished",
44
- status: "success",
45
- metadata,
41
+ ...metadata,
42
+ functionType: "json-generation",
46
43
  settings,
47
44
  prompt,
48
45
  response,
@@ -35,30 +35,27 @@ function generateJsonOrText(model, schemaDefinitions, prompt, options) {
35
35
  };
36
36
  },
37
37
  getStartEvent: (metadata, settings) => ({
38
- type: "json-or-text-generation-started",
39
- metadata,
38
+ ...metadata,
39
+ functionType: "json-or-text-generation",
40
40
  settings,
41
41
  prompt,
42
42
  }),
43
43
  getAbortEvent: (metadata, settings) => ({
44
- type: "json-or-text-generation-finished",
45
- status: "abort",
46
- metadata,
44
+ ...metadata,
45
+ functionType: "json-or-text-generation",
47
46
  settings,
48
47
  prompt,
49
48
  }),
50
49
  getFailureEvent: (metadata, settings, error) => ({
51
- type: "json-or-text-generation-finished",
52
- status: "failure",
53
- metadata,
50
+ ...metadata,
51
+ functionType: "json-or-text-generation",
54
52
  settings,
55
53
  prompt,
56
54
  error,
57
55
  }),
58
56
  getSuccessEvent: (metadata, settings, response, output) => ({
59
- type: "json-or-text-generation-finished",
60
- status: "success",
61
- metadata,
57
+ ...metadata,
58
+ functionType: "json-or-text-generation",
62
59
  settings,
63
60
  prompt,
64
61
  response,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { ModelFunctionPromise } from "../executeCall.js";
3
3
  import { GenerateJsonOrTextModel, GenerateJsonOrTextModelSettings, GenerateJsonOrTextPrompt } from "./GenerateJsonOrTextModel.js";
4
4
  import { SchemaDefinition } from "./SchemaDefinition.js";
@@ -14,7 +14,7 @@ type ToSchemaUnion<T> = {
14
14
  } : never;
15
15
  }[keyof T];
16
16
  type ToOutputValue<SCHEMAS extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>> = ToSchemaUnion<ToSchemaDefinitionsMap<SCHEMAS>>;
17
- export declare function generateJsonOrText<SCHEMAS extends SchemaDefinition<any, any>[], PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings>(model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinitions: SCHEMAS, prompt: (schemaDefinitions: SCHEMAS) => PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, {
17
+ export declare function generateJsonOrText<SCHEMAS extends SchemaDefinition<any, any>[], PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings>(model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinitions: SCHEMAS, prompt: (schemaDefinitions: SCHEMAS) => PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, {
18
18
  schema: null;
19
19
  value: null;
20
20
  text: string;
@@ -32,30 +32,27 @@ export function generateJsonOrText(model, schemaDefinitions, prompt, options) {
32
32
  };
33
33
  },
34
34
  getStartEvent: (metadata, settings) => ({
35
- type: "json-or-text-generation-started",
36
- metadata,
35
+ ...metadata,
36
+ functionType: "json-or-text-generation",
37
37
  settings,
38
38
  prompt,
39
39
  }),
40
40
  getAbortEvent: (metadata, settings) => ({
41
- type: "json-or-text-generation-finished",
42
- status: "abort",
43
- metadata,
41
+ ...metadata,
42
+ functionType: "json-or-text-generation",
44
43
  settings,
45
44
  prompt,
46
45
  }),
47
46
  getFailureEvent: (metadata, settings, error) => ({
48
- type: "json-or-text-generation-finished",
49
- status: "failure",
50
- metadata,
47
+ ...metadata,
48
+ functionType: "json-or-text-generation",
51
49
  settings,
52
50
  prompt,
53
51
  error,
54
52
  }),
55
53
  getSuccessEvent: (metadata, settings, response, output) => ({
56
- type: "json-or-text-generation-finished",
57
- status: "success",
58
- metadata,
54
+ ...metadata,
55
+ functionType: "json-or-text-generation",
59
56
  settings,
60
57
  prompt,
61
58
  response,
@@ -1,13 +1,11 @@
1
- import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
2
- export type TextGenerationStartedEvent = {
3
- type: "text-generation-started";
4
- metadata: ModelCallStartedEventMetadata;
1
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
+ export type TextGenerationStartedEvent = BaseModelCallStartedEvent & {
3
+ functionType: "text-generation";
5
4
  settings: unknown;
6
5
  prompt: unknown;
7
6
  };
8
- export type TextGenerationFinishedEvent = {
9
- type: "text-generation-finished";
10
- metadata: ModelCallFinishedEventMetadata;
7
+ export type TextGenerationFinishedEvent = BaseModelCallFinishedEvent & {
8
+ functionType: "text-generation";
11
9
  settings: unknown;
12
10
  prompt: unknown;
13
11
  } & ({
@@ -15,7 +13,7 @@ export type TextGenerationFinishedEvent = {
15
13
  response: unknown;
16
14
  generatedText: string;
17
15
  } | {
18
- status: "failure";
16
+ status: "error";
19
17
  error: unknown;
20
18
  } | {
21
19
  status: "abort";
@@ -1,6 +1,6 @@
1
1
  import { PromptFormat } from "../../prompt/PromptFormat.js";
2
2
  import { PromptFormatTextGenerationModel } from "../../prompt/PromptFormatTextGenerationModel.js";
3
- import { FunctionOptions } from "../FunctionOptions.js";
3
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
4
4
  import { Model, ModelSettings } from "../Model.js";
5
5
  import { BasicTokenizer, FullTokenizer } from "../tokenize-text/Tokenizer.js";
6
6
  import { DeltaEvent } from "./DeltaEvent.js";
@@ -28,12 +28,12 @@ export interface TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS exte
28
28
  * Optional. Implement if you have a tokenizer and want to count the number of tokens in a prompt.
29
29
  */
30
30
  readonly countPromptTokens: ((prompt: PROMPT) => PromiseLike<number>) | undefined;
31
- generateTextResponse(prompt: PROMPT, options?: FunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
31
+ generateTextResponse(prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
32
32
  extractText(response: RESPONSE): string;
33
33
  /**
34
34
  * Optional. Implement for streaming support.
35
35
  */
36
- readonly generateDeltaStreamResponse: ((prompt: PROMPT, options: FunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>) | undefined;
36
+ readonly generateDeltaStreamResponse: ((prompt: PROMPT, options: ModelFunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>) | undefined;
37
37
  /**
38
38
  * Optional. Implement for streaming support.
39
39
  */
@@ -1,13 +1,11 @@
1
- import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
2
- export type TextStreamingStartedEvent = {
3
- type: "text-streaming-started";
4
- metadata: ModelCallStartedEventMetadata;
1
+ import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
2
+ export type TextStreamingStartedEvent = BaseModelCallStartedEvent & {
3
+ functionType: "text-streaming";
5
4
  settings: unknown;
6
5
  prompt: unknown;
7
6
  };
8
- export type TextStreamingFinishedEvent = {
9
- type: "text-streaming-finished";
10
- metadata: ModelCallFinishedEventMetadata;
7
+ export type TextStreamingFinishedEvent = BaseModelCallFinishedEvent & {
8
+ functionType: "text-streaming";
11
9
  settings: unknown;
12
10
  prompt: unknown;
13
11
  } & ({
@@ -15,7 +13,7 @@ export type TextStreamingFinishedEvent = {
15
13
  response: unknown;
16
14
  generatedText: string;
17
15
  } | {
18
- status: "failure";
16
+ status: "error";
19
17
  error: unknown;
20
18
  } | {
21
19
  status: "abort";
@@ -28,30 +28,27 @@ model, prompt, options) {
28
28
  : model.extractText(result);
29
29
  },
30
30
  getStartEvent: (metadata, settings) => ({
31
- type: "text-generation-started",
32
- metadata,
31
+ ...metadata,
32
+ functionType: "text-generation",
33
33
  settings,
34
34
  prompt,
35
35
  }),
36
36
  getAbortEvent: (metadata, settings) => ({
37
- type: "text-generation-finished",
38
- status: "abort",
39
- metadata,
37
+ ...metadata,
38
+ functionType: "text-generation",
40
39
  settings,
41
40
  prompt,
42
41
  }),
43
42
  getFailureEvent: (metadata, settings, error) => ({
44
- type: "text-generation-finished",
45
- status: "failure",
46
- metadata,
43
+ ...metadata,
44
+ functionType: "text-generation",
47
45
  settings,
48
46
  prompt,
49
47
  error,
50
48
  }),
51
49
  getSuccessEvent: (metadata, settings, response, output) => ({
52
- type: "text-generation-finished",
53
- status: "success",
54
- metadata,
50
+ ...metadata,
51
+ functionType: "text-generation",
55
52
  settings,
56
53
  prompt,
57
54
  response,
@@ -1,4 +1,4 @@
1
- import { FunctionOptions } from "../FunctionOptions.js";
1
+ import { ModelFunctionOptions } from "../ModelFunctionOptions.js";
2
2
  import { ModelFunctionPromise } from "../executeCall.js";
3
3
  import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerationModel.js";
4
4
  /**
@@ -13,4 +13,4 @@ import { TextGenerationModel, TextGenerationModelSettings } from "./TextGenerati
13
13
  * "Write a short story about a robot learning to love:\n\n"
14
14
  * );
15
15
  */
16
- export declare function generateText<PROMPT, RESPONSE, SETTINGS extends TextGenerationModelSettings>(model: TextGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, prompt: PROMPT, options?: FunctionOptions<SETTINGS>): ModelFunctionPromise<TextGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, string, RESPONSE>;
16
+ export declare function generateText<PROMPT, RESPONSE, SETTINGS extends TextGenerationModelSettings>(model: TextGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): ModelFunctionPromise<TextGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, string, RESPONSE>;
@@ -25,30 +25,27 @@ model, prompt, options) {
25
25
  : model.extractText(result);
26
26
  },
27
27
  getStartEvent: (metadata, settings) => ({
28
- type: "text-generation-started",
29
- metadata,
28
+ ...metadata,
29
+ functionType: "text-generation",
30
30
  settings,
31
31
  prompt,
32
32
  }),
33
33
  getAbortEvent: (metadata, settings) => ({
34
- type: "text-generation-finished",
35
- status: "abort",
36
- metadata,
34
+ ...metadata,
35
+ functionType: "text-generation",
37
36
  settings,
38
37
  prompt,
39
38
  }),
40
39
  getFailureEvent: (metadata, settings, error) => ({
41
- type: "text-generation-finished",
42
- status: "failure",
43
- metadata,
40
+ ...metadata,
41
+ functionType: "text-generation",
44
42
  settings,
45
43
  prompt,
46
44
  error,
47
45
  }),
48
46
  getSuccessEvent: (metadata, settings, response, output) => ({
49
- type: "text-generation-finished",
50
- status: "success",
51
- metadata,
47
+ ...metadata,
48
+ functionType: "text-generation",
52
49
  settings,
53
50
  prompt,
54
51
  response,