modelfusion 0.40.1 → 0.41.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 (146) hide show
  1. package/README.md +14 -7
  2. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +3 -3
  3. package/core/FunctionEvent.d.ts +1 -1
  4. package/model-function/AsyncIterableResultPromise.d.ts +1 -1
  5. package/model-function/Delta.d.ts +8 -0
  6. package/model-function/ModelCallEvent.d.ts +1 -1
  7. package/model-function/ModelCallMetadata.d.ts +13 -0
  8. package/model-function/describe-image/ImageDescriptionEvent.d.ts +1 -1
  9. package/model-function/describe-image/ImageDescriptionModel.d.ts +6 -4
  10. package/model-function/describe-image/describeImage.cjs +7 -2
  11. package/model-function/describe-image/describeImage.d.ts +2 -2
  12. package/model-function/describe-image/describeImage.js +7 -2
  13. package/model-function/embed/EmbeddingEvent.d.ts +1 -1
  14. package/model-function/embed/EmbeddingModel.d.ts +6 -4
  15. package/model-function/embed/embed.cjs +16 -11
  16. package/model-function/embed/embed.d.ts +3 -3
  17. package/model-function/embed/embed.js +16 -11
  18. package/model-function/executeCall.cjs +26 -30
  19. package/model-function/executeCall.d.ts +19 -28
  20. package/model-function/executeCall.js +26 -30
  21. package/model-function/generate-image/ImageGenerationEvent.d.ts +1 -1
  22. package/model-function/generate-image/ImageGenerationModel.d.ts +6 -4
  23. package/model-function/generate-image/generateImage.cjs +7 -2
  24. package/model-function/generate-image/generateImage.d.ts +2 -2
  25. package/model-function/generate-image/generateImage.js +7 -2
  26. package/model-function/generate-structure/StructureFromTextGenerationModel.cjs +6 -5
  27. package/model-function/generate-structure/StructureFromTextGenerationModel.d.ts +7 -5
  28. package/model-function/generate-structure/StructureFromTextGenerationModel.js +6 -5
  29. package/model-function/generate-structure/StructureGenerationEvent.d.ts +1 -1
  30. package/model-function/generate-structure/StructureGenerationModel.d.ts +15 -18
  31. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +19 -17
  32. package/model-function/generate-structure/generateStructure.cjs +10 -8
  33. package/model-function/generate-structure/generateStructure.d.ts +2 -2
  34. package/model-function/generate-structure/generateStructure.js +10 -8
  35. package/model-function/generate-structure/generateStructureOrText.cjs +15 -8
  36. package/model-function/generate-structure/generateStructureOrText.d.ts +4 -4
  37. package/model-function/generate-structure/generateStructureOrText.js +15 -8
  38. package/model-function/generate-structure/streamStructure.cjs +4 -16
  39. package/model-function/generate-structure/streamStructure.d.ts +3 -7
  40. package/model-function/generate-structure/streamStructure.js +4 -16
  41. package/model-function/generate-text/TextGenerationEvent.d.ts +1 -1
  42. package/model-function/generate-text/TextGenerationModel.d.ts +18 -19
  43. package/model-function/generate-text/generateText.cjs +8 -9
  44. package/model-function/generate-text/generateText.d.ts +2 -2
  45. package/model-function/generate-text/generateText.js +8 -9
  46. package/model-function/generate-text/streamText.cjs +8 -21
  47. package/model-function/generate-text/streamText.d.ts +3 -7
  48. package/model-function/generate-text/streamText.js +8 -21
  49. package/model-function/index.cjs +2 -2
  50. package/model-function/index.d.ts +2 -2
  51. package/model-function/index.js +2 -2
  52. package/model-function/synthesize-speech/SpeechSynthesisEvent.d.ts +1 -1
  53. package/model-function/synthesize-speech/SpeechSynthesisModel.d.ts +3 -3
  54. package/model-function/synthesize-speech/synthesizeSpeech.cjs +7 -2
  55. package/model-function/synthesize-speech/synthesizeSpeech.d.ts +2 -2
  56. package/model-function/synthesize-speech/synthesizeSpeech.js +7 -2
  57. package/model-function/transcribe-speech/TranscriptionEvent.d.ts +1 -1
  58. package/model-function/transcribe-speech/TranscriptionModel.d.ts +6 -4
  59. package/model-function/transcribe-speech/transcribe.cjs +7 -2
  60. package/model-function/transcribe-speech/transcribe.d.ts +2 -2
  61. package/model-function/transcribe-speech/transcribe.js +7 -2
  62. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +14 -18
  63. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +11 -9
  64. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +14 -18
  65. package/model-provider/cohere/CohereTextEmbeddingModel.cjs +13 -16
  66. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +12 -10
  67. package/model-provider/cohere/CohereTextEmbeddingModel.js +13 -16
  68. package/model-provider/cohere/CohereTextGenerationModel.cjs +25 -28
  69. package/model-provider/cohere/CohereTextGenerationModel.d.ts +24 -22
  70. package/model-provider/cohere/CohereTextGenerationModel.js +25 -28
  71. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.cjs +10 -17
  72. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.d.ts +2 -2
  73. package/model-provider/elevenlabs/ElevenLabsSpeechSynthesisModel.js +10 -17
  74. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.cjs +13 -16
  75. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.d.ts +9 -7
  76. package/model-provider/huggingface/HuggingFaceImageDescriptionModel.js +13 -16
  77. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +19 -25
  78. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +8 -6
  79. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +19 -25
  80. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +18 -24
  81. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +10 -8
  82. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +18 -24
  83. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +13 -16
  84. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +8 -6
  85. package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +13 -16
  86. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +27 -33
  87. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +62 -60
  88. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +27 -33
  89. package/model-provider/lmnt/LmntSpeechSynthesisModel.cjs +7 -12
  90. package/model-provider/lmnt/LmntSpeechSynthesisModel.d.ts +2 -2
  91. package/model-provider/lmnt/LmntSpeechSynthesisModel.js +7 -12
  92. package/model-provider/openai/OpenAIImageGenerationModel.cjs +8 -16
  93. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +11 -11
  94. package/model-provider/openai/OpenAIImageGenerationModel.js +8 -16
  95. package/model-provider/openai/OpenAITextEmbeddingModel.cjs +18 -24
  96. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +18 -16
  97. package/model-provider/openai/OpenAITextEmbeddingModel.js +18 -24
  98. package/model-provider/openai/OpenAITextGenerationModel.cjs +19 -26
  99. package/model-provider/openai/OpenAITextGenerationModel.d.ts +31 -33
  100. package/model-provider/openai/OpenAITextGenerationModel.js +19 -26
  101. package/model-provider/openai/OpenAITranscriptionModel.cjs +19 -28
  102. package/model-provider/openai/OpenAITranscriptionModel.d.ts +27 -7
  103. package/model-provider/openai/OpenAITranscriptionModel.js +19 -28
  104. package/model-provider/openai/chat/OpenAIChatModel.cjs +76 -85
  105. package/model-provider/openai/chat/OpenAIChatModel.d.ts +127 -50
  106. package/model-provider/openai/chat/OpenAIChatModel.js +77 -86
  107. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +4 -3
  108. package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +2 -2
  109. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +2 -1
  110. package/model-provider/stability/StabilityImageGenerationModel.cjs +16 -21
  111. package/model-provider/stability/StabilityImageGenerationModel.d.ts +13 -11
  112. package/model-provider/stability/StabilityImageGenerationModel.js +16 -21
  113. package/package.json +1 -1
  114. package/prompt/PromptFormatTextGenerationModel.cjs +2 -18
  115. package/prompt/PromptFormatTextGenerationModel.d.ts +14 -10
  116. package/prompt/PromptFormatTextGenerationModel.js +2 -18
  117. package/prompt/PromptFormatTextStreamingModel.cjs +31 -0
  118. package/prompt/PromptFormatTextStreamingModel.d.ts +13 -0
  119. package/prompt/PromptFormatTextStreamingModel.js +27 -0
  120. package/prompt/chat/trimChatPrompt.d.ts +2 -2
  121. package/prompt/index.cjs +1 -0
  122. package/prompt/index.d.ts +1 -0
  123. package/prompt/index.js +1 -0
  124. package/retriever/Retriever.d.ts +3 -6
  125. package/retriever/retrieve.cjs +2 -2
  126. package/retriever/retrieve.d.ts +3 -3
  127. package/retriever/retrieve.js +2 -2
  128. package/tool/executeTool.cjs +2 -2
  129. package/tool/executeTool.js +2 -2
  130. package/tool/useTool.cjs +2 -4
  131. package/tool/useTool.d.ts +2 -2
  132. package/tool/useTool.js +2 -4
  133. package/tool/useToolOrGenerateText.d.ts +2 -2
  134. package/util/SafeResult.d.ts +1 -1
  135. package/util/runSafe.cjs +1 -1
  136. package/util/runSafe.js +1 -1
  137. package/vector-index/VectorIndexRetriever.cjs +0 -7
  138. package/vector-index/VectorIndexRetriever.d.ts +5 -5
  139. package/vector-index/VectorIndexRetriever.js +0 -7
  140. package/vector-index/upsertIntoVectorIndex.d.ts +4 -4
  141. package/model-function/DeltaEvent.d.ts +0 -7
  142. package/model-function/ModelFunctionOptions.d.ts +0 -4
  143. /package/model-function/{DeltaEvent.cjs → Delta.cjs} +0 -0
  144. /package/model-function/{DeltaEvent.js → Delta.js} +0 -0
  145. /package/model-function/{ModelFunctionOptions.cjs → ModelCallMetadata.cjs} +0 -0
  146. /package/model-function/{ModelFunctionOptions.js → ModelCallMetadata.js} +0 -0
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
- import { AbstractModel } from "../../model-function/AbstractModel.js";
3
2
  import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
4
3
  import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
5
- import { failedStabilityCallResponseHandler } from "./StabilityError.js";
4
+ import { AbstractModel } from "../../model-function/AbstractModel.js";
6
5
  import { StabilityApiConfiguration } from "./StabilityApiConfiguration.js";
6
+ import { failedStabilityCallResponseHandler } from "./StabilityError.js";
7
7
  /**
8
8
  * Create an image generation model that calls the Stability AI image generation API.
9
9
  *
@@ -40,21 +40,15 @@ export class StabilityImageGenerationModel extends AbstractModel {
40
40
  return this.settings.model;
41
41
  }
42
42
  async callAPI(input, options) {
43
- const run = options?.run;
44
- const settings = options?.settings;
45
- const callSettings = {
46
- // copied settings:
47
- ...this.settings,
48
- ...settings,
49
- // other settings:
50
- abortSignal: run?.abortSignal,
51
- engineId: this.settings.model,
52
- textPrompts: input,
53
- };
54
43
  return callWithRetryAndThrottle({
55
- retry: callSettings.api?.retry,
56
- throttle: callSettings.api?.throttle,
57
- call: async () => callStabilityImageGenerationAPI(callSettings),
44
+ retry: this.settings.api?.retry,
45
+ throttle: this.settings.api?.throttle,
46
+ call: async () => callStabilityImageGenerationAPI({
47
+ ...this.settings,
48
+ abortSignal: options?.run?.abortSignal,
49
+ engineId: this.settings.model,
50
+ textPrompts: input,
51
+ }),
58
52
  });
59
53
  }
60
54
  get settingsForEvent() {
@@ -72,11 +66,12 @@ export class StabilityImageGenerationModel extends AbstractModel {
72
66
  ];
73
67
  return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
74
68
  }
75
- generateImageResponse(prompt, options) {
76
- return this.callAPI(prompt, options);
77
- }
78
- extractBase64Image(response) {
79
- return response.artifacts[0].base64;
69
+ async doGenerateImage(prompt, options) {
70
+ const response = await this.callAPI(prompt, options);
71
+ return {
72
+ response,
73
+ base64Image: response.artifacts[0].base64,
74
+ };
80
75
  }
81
76
  withSettings(additionalSettings) {
82
77
  return new StabilityImageGenerationModel(Object.assign({}, this.settings, additionalSettings));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "Build multimodal applications, chatbots, and agents with JavaScript and TypeScript.",
4
- "version": "0.40.1",
4
+ "version": "0.41.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -37,25 +37,9 @@ class PromptFormatTextGenerationModel {
37
37
  }
38
38
  return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
39
39
  }
40
- generateTextResponse(prompt, options) {
40
+ doGenerateText(prompt, options) {
41
41
  const mappedPrompt = this.promptFormat.format(prompt);
42
- return this.model.generateTextResponse(mappedPrompt, options);
43
- }
44
- extractText(response) {
45
- return this.model.extractText(response);
46
- }
47
- get generateDeltaStreamResponse() {
48
- const originalGenerateDeltaStreamResponse = this.model.generateDeltaStreamResponse?.bind(this.model);
49
- if (originalGenerateDeltaStreamResponse === undefined) {
50
- return undefined;
51
- }
52
- return ((prompt, options) => {
53
- const mappedPrompt = this.promptFormat.format(prompt);
54
- return originalGenerateDeltaStreamResponse(mappedPrompt, options);
55
- });
56
- }
57
- get extractTextDelta() {
58
- return this.model.extractTextDelta;
42
+ return this.model.doGenerateText(mappedPrompt, options);
59
43
  }
60
44
  withPromptFormat(promptFormat) {
61
45
  return new PromptFormatTextGenerationModel({
@@ -1,10 +1,9 @@
1
- import { DeltaEvent } from "../model-function/DeltaEvent.js";
2
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
3
2
  import { TextGenerationModel, TextGenerationModelSettings } from "../model-function/generate-text/TextGenerationModel.js";
4
3
  import { PromptFormat } from "./PromptFormat.js";
5
- export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, RESPONSE, FULL_DELTA, SETTINGS>> implements TextGenerationModel<PROMPT, RESPONSE, FULL_DELTA, SETTINGS> {
6
- private readonly model;
7
- private readonly promptFormat;
4
+ export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS extends TextGenerationModelSettings, MODEL extends TextGenerationModel<MODEL_PROMPT, SETTINGS>> implements TextGenerationModel<PROMPT, SETTINGS> {
5
+ readonly model: MODEL;
6
+ readonly promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
8
7
  constructor({ model, promptFormat, }: {
9
8
  model: MODEL;
10
9
  promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
@@ -14,11 +13,16 @@ export declare class PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, RESPO
14
13
  get tokenizer(): MODEL["tokenizer"];
15
14
  get contextWindowSize(): MODEL["contextWindowSize"];
16
15
  get countPromptTokens(): MODEL["countPromptTokens"] extends undefined ? undefined : (prompt: PROMPT) => PromiseLike<number>;
17
- generateTextResponse(prompt: PROMPT, options?: ModelFunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
18
- extractText(response: RESPONSE): string;
19
- get generateDeltaStreamResponse(): MODEL["generateDeltaStreamResponse"] extends undefined ? undefined : (prompt: PROMPT, options: ModelFunctionOptions<SETTINGS>) => PromiseLike<AsyncIterable<DeltaEvent<FULL_DELTA>>>;
20
- get extractTextDelta(): MODEL["extractTextDelta"];
21
- withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, RESPONSE, FULL_DELTA, SETTINGS, this>;
16
+ doGenerateText(prompt: PROMPT, options?: FunctionOptions): PromiseLike<{
17
+ response: unknown;
18
+ text: string;
19
+ usage?: {
20
+ promptTokens: number;
21
+ completionTokens: number;
22
+ totalTokens: number;
23
+ } | undefined;
24
+ }>;
25
+ withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextGenerationModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
22
26
  get settingsForEvent(): Partial<SETTINGS>;
23
27
  withSettings(additionalSettings: Partial<SETTINGS>): this;
24
28
  }
@@ -34,25 +34,9 @@ export class PromptFormatTextGenerationModel {
34
34
  }
35
35
  return ((prompt) => originalCountPromptTokens(this.promptFormat.format(prompt)));
36
36
  }
37
- generateTextResponse(prompt, options) {
37
+ doGenerateText(prompt, options) {
38
38
  const mappedPrompt = this.promptFormat.format(prompt);
39
- return this.model.generateTextResponse(mappedPrompt, options);
40
- }
41
- extractText(response) {
42
- return this.model.extractText(response);
43
- }
44
- get generateDeltaStreamResponse() {
45
- const originalGenerateDeltaStreamResponse = this.model.generateDeltaStreamResponse?.bind(this.model);
46
- if (originalGenerateDeltaStreamResponse === undefined) {
47
- return undefined;
48
- }
49
- return ((prompt, options) => {
50
- const mappedPrompt = this.promptFormat.format(prompt);
51
- return originalGenerateDeltaStreamResponse(mappedPrompt, options);
52
- });
53
- }
54
- get extractTextDelta() {
55
- return this.model.extractTextDelta;
39
+ return this.model.doGenerateText(mappedPrompt, options);
56
40
  }
57
41
  withPromptFormat(promptFormat) {
58
42
  return new PromptFormatTextGenerationModel({
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptFormatTextStreamingModel = void 0;
4
+ const PromptFormatTextGenerationModel_js_1 = require("./PromptFormatTextGenerationModel.cjs");
5
+ class PromptFormatTextStreamingModel extends PromptFormatTextGenerationModel_js_1.PromptFormatTextGenerationModel {
6
+ constructor(options) {
7
+ super(options);
8
+ }
9
+ doStreamText(prompt, options) {
10
+ const mappedPrompt = this.promptFormat.format(prompt);
11
+ return this.model.doStreamText(mappedPrompt, options);
12
+ }
13
+ withPromptFormat(promptFormat) {
14
+ return new PromptFormatTextStreamingModel({
15
+ model: this.withSettings({
16
+ stopSequences: [
17
+ ...(this.settings.stopSequences ?? []),
18
+ ...promptFormat.stopSequences,
19
+ ],
20
+ }),
21
+ promptFormat,
22
+ });
23
+ }
24
+ withSettings(additionalSettings) {
25
+ return new PromptFormatTextStreamingModel({
26
+ model: this.model.withSettings(additionalSettings),
27
+ promptFormat: this.promptFormat,
28
+ });
29
+ }
30
+ }
31
+ exports.PromptFormatTextStreamingModel = PromptFormatTextStreamingModel;
@@ -0,0 +1,13 @@
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
+ import { TextGenerationModelSettings, TextStreamingModel } from "../model-function/generate-text/TextGenerationModel.js";
3
+ import { PromptFormat } from "./PromptFormat.js";
4
+ import { PromptFormatTextGenerationModel } from "./PromptFormatTextGenerationModel.js";
5
+ export declare class PromptFormatTextStreamingModel<PROMPT, MODEL_PROMPT, SETTINGS extends TextGenerationModelSettings, MODEL extends TextStreamingModel<MODEL_PROMPT, SETTINGS>> extends PromptFormatTextGenerationModel<PROMPT, MODEL_PROMPT, SETTINGS, MODEL> implements TextStreamingModel<PROMPT, SETTINGS> {
6
+ constructor(options: {
7
+ model: MODEL;
8
+ promptFormat: PromptFormat<PROMPT, MODEL_PROMPT>;
9
+ });
10
+ doStreamText(prompt: PROMPT, options?: FunctionOptions): PromiseLike<AsyncIterable<import("../index.js").Delta<string>>>;
11
+ withPromptFormat<INPUT_PROMPT>(promptFormat: PromptFormat<INPUT_PROMPT, PROMPT>): PromptFormatTextStreamingModel<INPUT_PROMPT, PROMPT, SETTINGS, this>;
12
+ withSettings(additionalSettings: Partial<SETTINGS>): this;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { PromptFormatTextGenerationModel } from "./PromptFormatTextGenerationModel.js";
2
+ export class PromptFormatTextStreamingModel extends PromptFormatTextGenerationModel {
3
+ constructor(options) {
4
+ super(options);
5
+ }
6
+ doStreamText(prompt, options) {
7
+ const mappedPrompt = this.promptFormat.format(prompt);
8
+ return this.model.doStreamText(mappedPrompt, options);
9
+ }
10
+ withPromptFormat(promptFormat) {
11
+ return new PromptFormatTextStreamingModel({
12
+ model: this.withSettings({
13
+ stopSequences: [
14
+ ...(this.settings.stopSequences ?? []),
15
+ ...promptFormat.stopSequences,
16
+ ],
17
+ }),
18
+ promptFormat,
19
+ });
20
+ }
21
+ withSettings(additionalSettings) {
22
+ return new PromptFormatTextStreamingModel({
23
+ model: this.model.withSettings(additionalSettings),
24
+ promptFormat: this.promptFormat,
25
+ });
26
+ }
27
+ }
@@ -1,4 +1,4 @@
1
- import { TextGenerationModel } from "../../model-function/generate-text/TextGenerationModel.js";
1
+ import { TextGenerationModel, TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
2
2
  import { ChatPrompt } from "./ChatPrompt.js";
3
3
  /**
4
4
  * Keeps only the most recent messages in the prompt, while leaving enough space for the completion.
@@ -12,7 +12,7 @@ import { ChatPrompt } from "./ChatPrompt.js";
12
12
  */
13
13
  export declare function trimChatPrompt({ prompt, model, tokenLimit, }: {
14
14
  prompt: ChatPrompt;
15
- model: TextGenerationModel<ChatPrompt, any, any, any> & {
15
+ model: TextGenerationModel<ChatPrompt, TextGenerationModelSettings> & {
16
16
  contextWindowSize: number;
17
17
  countPromptTokens: (prompt: ChatPrompt) => PromiseLike<number>;
18
18
  };
package/prompt/index.cjs CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./InstructionPrompt.cjs"), exports);
19
19
  __exportStar(require("./Llama2PromptFormat.cjs"), exports);
20
20
  __exportStar(require("./PromptFormat.cjs"), exports);
21
21
  __exportStar(require("./PromptFormatTextGenerationModel.cjs"), exports);
22
+ __exportStar(require("./PromptFormatTextStreamingModel.cjs"), exports);
22
23
  __exportStar(require("./TextPromptFormat.cjs"), exports);
23
24
  __exportStar(require("./VicunaPromptFormat.cjs"), exports);
24
25
  __exportStar(require("./chat/ChatPrompt.cjs"), exports);
package/prompt/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./InstructionPrompt.js";
3
3
  export * from "./Llama2PromptFormat.js";
4
4
  export * from "./PromptFormat.js";
5
5
  export * from "./PromptFormatTextGenerationModel.js";
6
+ export * from "./PromptFormatTextStreamingModel.js";
6
7
  export * from "./TextPromptFormat.js";
7
8
  export * from "./VicunaPromptFormat.js";
8
9
  export * from "./chat/ChatPrompt.js";
package/prompt/index.js CHANGED
@@ -3,6 +3,7 @@ export * from "./InstructionPrompt.js";
3
3
  export * from "./Llama2PromptFormat.js";
4
4
  export * from "./PromptFormat.js";
5
5
  export * from "./PromptFormatTextGenerationModel.js";
6
+ export * from "./PromptFormatTextStreamingModel.js";
6
7
  export * from "./TextPromptFormat.js";
7
8
  export * from "./VicunaPromptFormat.js";
8
9
  export * from "./chat/ChatPrompt.js";
@@ -1,7 +1,4 @@
1
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
2
- export interface RetrieverSettings {
3
- }
4
- export interface Retriever<OBJECT, QUERY, SETTINGS extends RetrieverSettings> {
5
- retrieve(query: QUERY, options?: ModelFunctionOptions<RetrieverSettings>): Promise<OBJECT[]>;
6
- withSettings(additionalSettings: Partial<SETTINGS>): this;
1
+ import { FunctionOptions } from "core";
2
+ export interface Retriever<OBJECT, QUERY> {
3
+ retrieve(query: QUERY, options?: FunctionOptions): Promise<OBJECT[]>;
7
4
  }
@@ -69,9 +69,9 @@ async function retrieve(retriever, query, options) {
69
69
  eventType: "finished",
70
70
  result: {
71
71
  status: "success",
72
- output: result.output,
72
+ value: result.value,
73
73
  },
74
74
  });
75
- return result.output;
75
+ return result.value;
76
76
  }
77
77
  exports.retrieve = retrieve;
@@ -1,3 +1,3 @@
1
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
2
- import { Retriever, RetrieverSettings } from "./Retriever.js";
3
- export declare function retrieve<OBJECT, QUERY, SETTINGS extends RetrieverSettings>(retriever: Retriever<OBJECT, QUERY, SETTINGS>, query: QUERY, options?: ModelFunctionOptions<SETTINGS>): Promise<OBJECT[]>;
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
+ import { Retriever } from "./Retriever.js";
3
+ export declare function retrieve<OBJECT, QUERY>(retriever: Retriever<OBJECT, QUERY>, query: QUERY, options?: FunctionOptions): Promise<OBJECT[]>;
@@ -66,8 +66,8 @@ export async function retrieve(retriever, query, options) {
66
66
  eventType: "finished",
67
67
  result: {
68
68
  status: "success",
69
- output: result.output,
69
+ value: result.value,
70
70
  },
71
71
  });
72
- return result.output;
72
+ return result.value;
73
73
  }
@@ -115,12 +115,12 @@ async function doExecuteTool(tool, input, options) {
115
115
  message: result.error?.message,
116
116
  });
117
117
  }
118
- const output = result.output;
118
+ const output = result.value;
119
119
  eventSource.notify({
120
120
  ...finishMetadata,
121
121
  result: {
122
122
  status: "success",
123
- output,
123
+ value: output,
124
124
  },
125
125
  });
126
126
  return {
@@ -110,12 +110,12 @@ async function doExecuteTool(tool, input, options) {
110
110
  message: result.error?.message,
111
111
  });
112
112
  }
113
- const output = result.output;
113
+ const output = result.value;
114
114
  eventSource.notify({
115
115
  ...finishMetadata,
116
116
  result: {
117
117
  status: "success",
118
- output,
118
+ value: output,
119
119
  },
120
120
  });
121
121
  return {
package/tool/useTool.cjs CHANGED
@@ -10,14 +10,12 @@ const executeTool_js_1 = require("./executeTool.cjs");
10
10
  * the parameters (`parameters` property, typed),
11
11
  * and the result of the tool execution (`result` property, typed).
12
12
  */
13
- async function useTool(
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- model, tool, prompt, options) {
13
+ async function useTool(model, tool, prompt, options) {
16
14
  // Note: PROMPT must not be a function.
17
15
  const expandedPrompt = typeof prompt === "function"
18
16
  ? prompt(tool)
19
17
  : prompt;
20
- const { output: value } = await (0, generateStructure_js_1.generateStructure)(model, {
18
+ const { value } = await (0, generateStructure_js_1.generateStructure)(model, {
21
19
  name: tool.name,
22
20
  description: tool.description,
23
21
  schema: tool.inputSchema,
package/tool/useTool.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  import { StructureGenerationModel, StructureGenerationModelSettings } from "../model-function/generate-structure/StructureGenerationModel.js";
3
3
  import { Tool } from "./Tool.js";
4
4
  /**
@@ -8,7 +8,7 @@ import { Tool } from "./Tool.js";
8
8
  * the parameters (`parameters` property, typed),
9
9
  * and the result of the tool execution (`result` property, typed).
10
10
  */
11
- export declare function useTool<PROMPT, RESPONSE, SETTINGS extends StructureGenerationModelSettings, TOOL extends Tool<any, any, any>>(model: StructureGenerationModel<PROMPT, RESPONSE, any, SETTINGS>, tool: TOOL, prompt: PROMPT | ((tool: TOOL) => PROMPT), options?: ModelFunctionOptions<SETTINGS>): Promise<{
11
+ export declare function useTool<PROMPT, TOOL extends Tool<any, any, any>>(model: StructureGenerationModel<PROMPT, StructureGenerationModelSettings>, tool: TOOL, prompt: PROMPT | ((tool: TOOL) => PROMPT), options?: FunctionOptions): Promise<{
12
12
  tool: TOOL["name"];
13
13
  parameters: TOOL["inputSchema"];
14
14
  result: Awaited<ReturnType<TOOL["execute"]>>;
package/tool/useTool.js CHANGED
@@ -7,14 +7,12 @@ import { executeTool } from "./executeTool.js";
7
7
  * the parameters (`parameters` property, typed),
8
8
  * and the result of the tool execution (`result` property, typed).
9
9
  */
10
- export async function useTool(
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- model, tool, prompt, options) {
10
+ export async function useTool(model, tool, prompt, options) {
13
11
  // Note: PROMPT must not be a function.
14
12
  const expandedPrompt = typeof prompt === "function"
15
13
  ? prompt(tool)
16
14
  : prompt;
17
- const { output: value } = await generateStructure(model, {
15
+ const { value } = await generateStructure(model, {
18
16
  name: tool.name,
19
17
  description: tool.description,
20
18
  schema: tool.inputSchema,
@@ -1,4 +1,4 @@
1
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  import { StructureOrTextGenerationModel, StructureOrTextGenerationModelSettings } from "../model-function/generate-structure/StructureOrTextGenerationModel.js";
3
3
  import { Tool } from "./Tool.js";
4
4
  type ToolArray<T extends Tool<any, any, any>[]> = T;
@@ -14,7 +14,7 @@ type ToToolUnion<T> = {
14
14
  } : never;
15
15
  }[keyof T];
16
16
  type ToOutputValue<TOOLS extends ToolArray<Tool<any, any, any>[]>> = ToToolUnion<ToToolMap<TOOLS>>;
17
- export declare function useToolOrGenerateText<PROMPT, RESPONSE, SETTINGS extends StructureOrTextGenerationModelSettings, TOOLS extends Array<Tool<any, any, any>>>(model: StructureOrTextGenerationModel<PROMPT, RESPONSE, SETTINGS>, tools: TOOLS, prompt: PROMPT | ((tools: TOOLS) => PROMPT), options?: ModelFunctionOptions<SETTINGS>): Promise<{
17
+ export declare function useToolOrGenerateText<PROMPT, SETTINGS extends StructureOrTextGenerationModelSettings, TOOLS extends Array<Tool<any, any, any>>>(model: StructureOrTextGenerationModel<PROMPT, SETTINGS>, tools: TOOLS, prompt: PROMPT | ((tools: TOOLS) => PROMPT), options?: FunctionOptions): Promise<{
18
18
  tool: null;
19
19
  parameters: null;
20
20
  result: null;
@@ -1,6 +1,6 @@
1
1
  export type SafeResult<OUTPUT> = {
2
2
  ok: true;
3
- output: OUTPUT;
3
+ value: OUTPUT;
4
4
  } | {
5
5
  ok: false;
6
6
  isAborted?: boolean;
package/util/runSafe.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runSafe = void 0;
4
4
  const runSafe = async (f) => {
5
5
  try {
6
- return { ok: true, output: await f() };
6
+ return { ok: true, value: await f() };
7
7
  }
8
8
  catch (error) {
9
9
  if (error instanceof Error && error.name === "AbortError") {
package/util/runSafe.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const runSafe = async (f) => {
2
2
  try {
3
- return { ok: true, output: await f() };
3
+ return { ok: true, value: await f() };
4
4
  }
5
5
  catch (error) {
6
6
  if (error instanceof Error && error.name === "AbortError") {
@@ -31,13 +31,6 @@ class VectorIndexRetriever {
31
31
  };
32
32
  }
33
33
  async retrieve(query, options) {
34
- if (options?.settings != null) {
35
- return this.withSettings(options.settings).retrieve(query, {
36
- functionId: options.functionId,
37
- observers: options.observers,
38
- run: options.run,
39
- });
40
- }
41
34
  const embedding = await (0, embed_js_1.embed)(this.embeddingModel, query, {
42
35
  functionId: options?.functionId,
43
36
  run: options?.run,
@@ -1,20 +1,20 @@
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
1
2
  import { EmbeddingModel, EmbeddingModelSettings } from "../model-function/embed/EmbeddingModel.js";
2
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
3
- import { Retriever, RetrieverSettings } from "../retriever/Retriever.js";
3
+ import { Retriever } from "../retriever/Retriever.js";
4
4
  import { VectorIndex } from "./VectorIndex.js";
5
5
  export interface VectorIndexRetrieverSettings<FILTER> {
6
6
  maxResults?: number;
7
7
  similarityThreshold?: number;
8
8
  filter?: FILTER;
9
9
  }
10
- export declare class VectorIndexRetriever<OBJECT, VALUE, INDEX, FILTER> implements Retriever<OBJECT, VALUE, VectorIndexRetrieverSettings<FILTER>> {
10
+ export declare class VectorIndexRetriever<OBJECT, VALUE, INDEX, FILTER> implements Retriever<OBJECT, VALUE> {
11
11
  private readonly vectorIndex;
12
12
  private readonly embeddingModel;
13
13
  private readonly settings;
14
14
  constructor({ vectorIndex, embeddingModel, maxResults, similarityThreshold, filter, }: {
15
15
  vectorIndex: VectorIndex<OBJECT, INDEX, FILTER>;
16
- embeddingModel: EmbeddingModel<VALUE, unknown, EmbeddingModelSettings>;
16
+ embeddingModel: EmbeddingModel<VALUE, EmbeddingModelSettings>;
17
17
  } & VectorIndexRetrieverSettings<FILTER>);
18
- retrieve(query: VALUE, options?: ModelFunctionOptions<RetrieverSettings>): Promise<OBJECT[]>;
18
+ retrieve(query: VALUE, options?: FunctionOptions): Promise<OBJECT[]>;
19
19
  withSettings(additionalSettings: Partial<VectorIndexRetrieverSettings<FILTER>>): this;
20
20
  }
@@ -28,13 +28,6 @@ export class VectorIndexRetriever {
28
28
  };
29
29
  }
30
30
  async retrieve(query, options) {
31
- if (options?.settings != null) {
32
- return this.withSettings(options.settings).retrieve(query, {
33
- functionId: options.functionId,
34
- observers: options.observers,
35
- run: options.run,
36
- });
37
- }
38
31
  const embedding = await embed(this.embeddingModel, query, {
39
32
  functionId: options?.functionId,
40
33
  run: options?.run,
@@ -1,11 +1,11 @@
1
- import { ModelFunctionOptions } from "../model-function/ModelFunctionOptions.js";
1
+ import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  import { EmbeddingModel, EmbeddingModelSettings } from "../model-function/embed/EmbeddingModel.js";
3
3
  import { VectorIndex } from "./VectorIndex.js";
4
- export declare function upsertIntoVectorIndex<VALUE, OBJECT, SETTINGS extends EmbeddingModelSettings>({ vectorIndex, embeddingModel, generateId, objects, getValueToEmbed, getId, }: {
4
+ export declare function upsertIntoVectorIndex<VALUE, OBJECT>({ vectorIndex, embeddingModel, generateId, objects, getValueToEmbed, getId, }: {
5
5
  vectorIndex: VectorIndex<OBJECT, unknown, unknown>;
6
- embeddingModel: EmbeddingModel<VALUE, unknown, SETTINGS>;
6
+ embeddingModel: EmbeddingModel<VALUE, EmbeddingModelSettings>;
7
7
  generateId?: () => string;
8
8
  objects: OBJECT[];
9
9
  getValueToEmbed: (object: OBJECT, index: number) => VALUE;
10
10
  getId?: (object: OBJECT, index: number) => string | undefined;
11
- }, options?: ModelFunctionOptions<SETTINGS>): Promise<void>;
11
+ }, options?: FunctionOptions): Promise<void>;
@@ -1,7 +0,0 @@
1
- export type DeltaEvent<FULL_DELTA> = {
2
- type: "delta";
3
- fullDelta: FULL_DELTA;
4
- } | {
5
- type: "error";
6
- error: unknown;
7
- };
@@ -1,4 +0,0 @@
1
- import { FunctionOptions } from "../core/FunctionOptions.js";
2
- export interface ModelFunctionOptions<SETTINGS> extends FunctionOptions {
3
- settings?: Partial<SETTINGS>;
4
- }
File without changes
File without changes