modelfusion 0.5.0 → 0.7.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 (70) hide show
  1. package/README.md +22 -21
  2. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +3 -3
  3. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +4 -4
  4. package/composed-function/use-tool/useTool.cjs +4 -1
  5. package/composed-function/use-tool/useTool.js +4 -1
  6. package/model-function/embed-text/embedText.cjs +16 -30
  7. package/model-function/embed-text/embedText.d.ts +14 -4
  8. package/model-function/embed-text/embedText.js +16 -30
  9. package/model-function/generate-image/generateImage.cjs +7 -20
  10. package/model-function/generate-image/generateImage.d.ts +7 -2
  11. package/model-function/generate-image/generateImage.js +7 -20
  12. package/model-function/generate-json/generateJson.cjs +7 -5
  13. package/model-function/generate-json/generateJson.d.ts +6 -1
  14. package/model-function/generate-json/generateJson.js +7 -5
  15. package/model-function/generate-json/generateJsonOrText.cjs +7 -5
  16. package/model-function/generate-json/generateJsonOrText.d.ts +10 -1
  17. package/model-function/generate-json/generateJsonOrText.js +7 -5
  18. package/model-function/generate-text/generateText.cjs +7 -17
  19. package/model-function/generate-text/generateText.d.ts +7 -2
  20. package/model-function/generate-text/generateText.js +7 -17
  21. package/model-function/generate-text/streamText.cjs +6 -4
  22. package/model-function/generate-text/streamText.d.ts +9 -1
  23. package/model-function/generate-text/streamText.js +6 -4
  24. package/model-function/transcribe-audio/transcribe.cjs +7 -19
  25. package/model-function/transcribe-audio/transcribe.d.ts +7 -2
  26. package/model-function/transcribe-audio/transcribe.js +7 -19
  27. package/model-provider/cohere/CohereTextEmbeddingModel.cjs +1 -1
  28. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +1 -1
  29. package/model-provider/cohere/CohereTextEmbeddingModel.js +1 -1
  30. package/model-provider/cohere/CohereTextGenerationModel.cjs +1 -1
  31. package/model-provider/cohere/CohereTextGenerationModel.d.ts +1 -1
  32. package/model-provider/cohere/CohereTextGenerationModel.js +1 -1
  33. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +1 -1
  34. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.d.ts +1 -1
  35. package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +1 -1
  36. package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +1 -1
  37. package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +1 -1
  38. package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +1 -1
  39. package/model-provider/openai/OpenAIImageGenerationModel.cjs +1 -1
  40. package/model-provider/openai/OpenAIImageGenerationModel.d.ts +1 -1
  41. package/model-provider/openai/OpenAIImageGenerationModel.js +1 -1
  42. package/model-provider/openai/OpenAITextEmbeddingModel.cjs +1 -1
  43. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +1 -1
  44. package/model-provider/openai/OpenAITextEmbeddingModel.js +1 -1
  45. package/model-provider/openai/OpenAITextGenerationModel.cjs +1 -1
  46. package/model-provider/openai/OpenAITextGenerationModel.d.ts +1 -1
  47. package/model-provider/openai/OpenAITextGenerationModel.js +1 -1
  48. package/model-provider/openai/OpenAITranscriptionModel.cjs +1 -1
  49. package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -1
  50. package/model-provider/openai/OpenAITranscriptionModel.js +1 -1
  51. package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
  52. package/model-provider/openai/chat/OpenAIChatModel.d.ts +1 -1
  53. package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
  54. package/model-provider/stability/StabilityImageGenerationModel.cjs +1 -1
  55. package/model-provider/stability/StabilityImageGenerationModel.d.ts +1 -1
  56. package/model-provider/stability/StabilityImageGenerationModel.js +1 -1
  57. package/package.json +2 -2
  58. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.cjs +1 -1
  59. package/text-chunk/SimilarTextChunksFromVectorIndexRetriever.js +1 -1
  60. package/text-chunk/split/splitOnSeparator.cjs +7 -9
  61. package/text-chunk/split/splitOnSeparator.d.ts +5 -6
  62. package/text-chunk/split/splitOnSeparator.js +6 -7
  63. package/text-chunk/split/splitRecursively.cjs +16 -7
  64. package/text-chunk/split/splitRecursively.d.ts +13 -4
  65. package/text-chunk/split/splitRecursively.js +13 -4
  66. package/text-chunk/split/splitTextChunks.cjs +10 -8
  67. package/text-chunk/split/splitTextChunks.d.ts +1 -0
  68. package/text-chunk/split/splitTextChunks.js +8 -7
  69. package/text-chunk/upsertTextChunks.cjs +1 -1
  70. package/text-chunk/upsertTextChunks.js +1 -1
@@ -1,9 +1,18 @@
1
1
  import { FullTokenizer } from "../../model-function/tokenize-text/Tokenizer.js";
2
2
  import { SplitFunction } from "./SplitFunction.js";
3
- export declare const splitRecursivelyAtCharacter: ({ maxChunkSize }: {
4
- maxChunkSize: number;
3
+ /**
4
+ * Splits text recursively until the resulting chunks are smaller than the `maxCharactersPerChunk`.
5
+ * The text is recursively split in the middle, so that all chunks are roughtly the same size.
6
+ */
7
+ export declare const splitAtCharacter: ({ maxCharactersPerChunk, }: {
8
+ maxCharactersPerChunk: number;
5
9
  }) => SplitFunction;
6
- export declare const splitRecursivelyAtToken: ({ tokenizer, maxChunkSize, }: {
10
+ /**
11
+ * Splits text recursively until the resulting chunks are smaller than the `maxTokensPerChunk`,
12
+ * while respecting the token boundaries.
13
+ * The text is recursively split in the middle, so that all chunks are roughtly the same size.
14
+ */
15
+ export declare const splitAtToken: ({ tokenizer, maxTokensPerChunk, }: {
7
16
  tokenizer: FullTokenizer;
8
- maxChunkSize: number;
17
+ maxTokensPerChunk: number;
9
18
  }) => SplitFunction;
@@ -17,11 +17,20 @@ function splitRecursively({ maxChunkSize, segments, }) {
17
17
  }),
18
18
  ];
19
19
  }
20
- export const splitRecursivelyAtCharacter = ({ maxChunkSize }) => async ({ text }) => splitRecursively({
21
- maxChunkSize,
20
+ /**
21
+ * Splits text recursively until the resulting chunks are smaller than the `maxCharactersPerChunk`.
22
+ * The text is recursively split in the middle, so that all chunks are roughtly the same size.
23
+ */
24
+ export const splitAtCharacter = ({ maxCharactersPerChunk, }) => async ({ text }) => splitRecursively({
25
+ maxChunkSize: maxCharactersPerChunk,
22
26
  segments: text,
23
27
  });
24
- export const splitRecursivelyAtToken = ({ tokenizer, maxChunkSize, }) => async ({ text }) => splitRecursively({
25
- maxChunkSize,
28
+ /**
29
+ * Splits text recursively until the resulting chunks are smaller than the `maxTokensPerChunk`,
30
+ * while respecting the token boundaries.
31
+ * The text is recursively split in the middle, so that all chunks are roughtly the same size.
32
+ */
33
+ export const splitAtToken = ({ tokenizer, maxTokensPerChunk, }) => async ({ text }) => splitRecursively({
34
+ maxChunkSize: maxTokensPerChunk,
26
35
  segments: (await tokenizer.tokenizeWithTexts(text)).tokenTexts,
27
36
  });
@@ -1,14 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitTextChunks = void 0;
3
+ exports.splitTextChunk = exports.splitTextChunks = void 0;
4
4
  async function splitTextChunks(splitFunction, inputs) {
5
- const pageChunks = await Promise.all(inputs.map(async (input) => {
6
- const parts = await splitFunction(input);
7
- return parts.map((text) => ({
8
- ...input,
9
- text,
10
- }));
11
- }));
5
+ const pageChunks = await Promise.all(inputs.map((input) => splitTextChunk(splitFunction, input)));
12
6
  return pageChunks.flat();
13
7
  }
14
8
  exports.splitTextChunks = splitTextChunks;
9
+ async function splitTextChunk(splitFunction, input) {
10
+ const parts = await splitFunction(input);
11
+ return parts.map((text) => ({
12
+ ...input,
13
+ text,
14
+ }));
15
+ }
16
+ exports.splitTextChunk = splitTextChunk;
@@ -1,3 +1,4 @@
1
1
  import { TextChunk } from "../TextChunk.js";
2
2
  import { SplitFunction } from "./SplitFunction.js";
3
3
  export declare function splitTextChunks<CHUNK extends TextChunk>(splitFunction: SplitFunction, inputs: CHUNK[]): Promise<CHUNK[]>;
4
+ export declare function splitTextChunk<CHUNK extends TextChunk>(splitFunction: SplitFunction, input: CHUNK): Promise<CHUNK[]>;
@@ -1,10 +1,11 @@
1
1
  export async function splitTextChunks(splitFunction, inputs) {
2
- const pageChunks = await Promise.all(inputs.map(async (input) => {
3
- const parts = await splitFunction(input);
4
- return parts.map((text) => ({
5
- ...input,
6
- text,
7
- }));
8
- }));
2
+ const pageChunks = await Promise.all(inputs.map((input) => splitTextChunk(splitFunction, input)));
9
3
  return pageChunks.flat();
10
4
  }
5
+ export async function splitTextChunk(splitFunction, input) {
6
+ const parts = await splitFunction(input);
7
+ return parts.map((text) => ({
8
+ ...input,
9
+ text,
10
+ }));
11
+ }
@@ -5,7 +5,7 @@ const nanoid_1 = require("nanoid");
5
5
  const embedText_js_1 = require("../model-function/embed-text/embedText.cjs");
6
6
  async function upsertTextChunks({ vectorIndex, embeddingModel, generateId = nanoid_1.nanoid, chunks, ids, }, options) {
7
7
  // many embedding models support bulk embedding, so we first embed all texts:
8
- const { embeddings } = await (0, embedText_js_1.embedTexts)(embeddingModel, chunks.map((chunk) => chunk.text), options);
8
+ const embeddings = await (0, embedText_js_1.embedTexts)(embeddingModel, chunks.map((chunk) => chunk.text), options);
9
9
  await vectorIndex.upsertMany(chunks.map((chunk, i) => ({
10
10
  id: ids?.[i] ?? generateId(),
11
11
  vector: embeddings[i],
@@ -2,7 +2,7 @@ import { nanoid as createId } from "nanoid";
2
2
  import { embedTexts } from "../model-function/embed-text/embedText.js";
3
3
  export async function upsertTextChunks({ vectorIndex, embeddingModel, generateId = createId, chunks, ids, }, options) {
4
4
  // many embedding models support bulk embedding, so we first embed all texts:
5
- const { embeddings } = await embedTexts(embeddingModel, chunks.map((chunk) => chunk.text), options);
5
+ const embeddings = await embedTexts(embeddingModel, chunks.map((chunk) => chunk.text), options);
6
6
  await vectorIndex.upsertMany(chunks.map((chunk, i) => ({
7
7
  id: ids?.[i] ?? generateId(),
8
8
  vector: embeddings[i],