modelfusion 0.128.0 → 0.129.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.129.0 - 2024-01-20
4
+
5
+ ### Changed
6
+
7
+ - **breaking change**: Usage of Node `async_hooks` has been renamed from `node:async_hooks` to `async_hooks` for easier Webpack configuration. To exclude the `async_hooks` from client-side bundling, you can use the following config for Next.js (`next.config.mjs` or `next.config.js`):
8
+
9
+ ```js
10
+ /**
11
+ * @type {import('next').NextConfig}
12
+ */
13
+ const nextConfig = {
14
+ webpack: (config, { isServer }) => {
15
+ if (isServer) {
16
+ return config;
17
+ }
18
+
19
+ config.resolve = config.resolve ?? {};
20
+ config.resolve.fallback = config.resolve.fallback ?? {};
21
+
22
+ // async hooks is not available in the browser:
23
+ config.resolve.fallback.async_hooks = false;
24
+
25
+ return config;
26
+ },
27
+ };
28
+ ```
29
+
3
30
  ## v0.128.0 - 2024-01-20
4
31
 
5
32
  ### Changed
@@ -8,9 +35,7 @@
8
35
  - **breaking change**: Image content in multi-modal instruction and chat inputs (e.g. for GPT Vision) is passed in the `image` property (instead of `base64Image`) and supports both base64 strings and `Uint8Array` inputs:
9
36
 
10
37
  ```ts
11
- const image = fs.readFileSync(path.join("data", "example-image.png"), {
12
- encoding: "base64",
13
- });
38
+ const image = fs.readFileSync(path.join("data", "example-image.png"));
14
39
 
15
40
  const textStream = await streamText({
16
41
  model: openai.ChatTextGenerator({
package/README.md CHANGED
@@ -86,7 +86,7 @@ Multi-modal vision models such as GPT 4 Vision can process images as part of the
86
86
  import { streamText, openai } from "modelfusion";
87
87
  import { readFileSync } from "fs";
88
88
 
89
- const image = readFileSync("./image.png").toString("base64");
89
+ const image = readFileSync("./image.png");
90
90
 
91
91
  const textStream = await streamText({
92
92
  model: openai.ChatTextGenerator({ model: "gpt-4-vision-preview" }),
@@ -219,7 +219,7 @@ Synthesize speech (audio) from text. Also called TTS (text-to-speech).
219
219
  ```ts
220
220
  import { generateSpeech, lmnt } from "modelfusion";
221
221
 
222
- // `speech` is a Buffer with MP3 audio data
222
+ // `speech` is a Uint8Array with MP3 audio data
223
223
  const speech = await generateSpeech({
224
224
  model: lmnt.SpeechGenerator({
225
225
  voice: "034b632b-df71-46c8-b440-86a42ffc3cf3", // Henry
@@ -257,7 +257,7 @@ const speechStream = await streamSpeech({
257
257
  });
258
258
 
259
259
  for await (const part of speechStream) {
260
- // each part is a Buffer with MP3 audio data
260
+ // each part is a Uint8Array with MP3 audio data
261
261
  }
262
262
  ```
263
263
 
@@ -635,17 +635,14 @@ A web chat with an AI assistant, implemented as a Next.js app.
635
635
 
636
636
  Ask questions about a PDF document and get answers from the document.
637
637
 
638
- ### [Image generator (Next.js)](https://github.com/lgrammel/modelfusion/tree/main/examples/image-generator-next-js)
638
+ ### [Next.js / ModelFusion Demos](https://github.com/lgrammel/modelfusion/tree/main/examples/nextjs)
639
639
 
640
- > _Next.js app_, _Stability AI image generation_
640
+ > _Next.js app_, _image generation_, _transcription_, _OpenAI_, _Stability AI_
641
641
 
642
- Create an 19th century painting image for your input.
642
+ Examples of using ModelFusion with Next.js 14 (App Router):
643
643
 
644
- ### [Voice recording and transcription (Next.js)](https://github.com/lgrammel/modelfusion/tree/main/examples/voice-recording-next-js)
645
-
646
- > _Next.js app_, _OpenAI Whisper_
647
-
648
- Record audio with push-to-talk and transcribe it using Whisper, implemented as a Next.js app. The app shows a list of the transcriptions.
644
+ - image generation
645
+ - voice recording & transcription
649
646
 
650
647
  ### [Duplex Speech Streaming (using Vite/React & ModelFusion Server/Fastify)](https://github.com/lgrammel/modelfusion/tree/main/examples/speech-streaming-vite-react-fastify)
651
648
 
package/core/getRun.cjs CHANGED
@@ -34,7 +34,8 @@ async function ensureLoaded() {
34
34
  if (!isNode)
35
35
  return Promise.resolve();
36
36
  if (!runStorage) {
37
- const { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("node:async_hooks")));
37
+ // Note: using "async_hooks" instead of "node:async_hooks" to avoid webpack fallback problems.
38
+ const { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("async_hooks")));
38
39
  runStorage = new AsyncLocalStorage();
39
40
  }
40
41
  return Promise.resolve();
package/core/getRun.js CHANGED
@@ -8,7 +8,8 @@ async function ensureLoaded() {
8
8
  if (!isNode)
9
9
  return Promise.resolve();
10
10
  if (!runStorage) {
11
- const { AsyncLocalStorage } = await import("node:async_hooks");
11
+ // Note: using "async_hooks" instead of "node:async_hooks" to avoid webpack fallback problems.
12
+ const { AsyncLocalStorage } = await import("async_hooks");
12
13
  runStorage = new AsyncLocalStorage();
13
14
  }
14
15
  return Promise.resolve();
@@ -14,12 +14,24 @@ class ZodSchema {
14
14
  writable: true,
15
15
  value: void 0
16
16
  });
17
+ /**
18
+ * Use only for typing purposes. The value is always `undefined`.
19
+ */
17
20
  Object.defineProperty(this, "_type", {
18
21
  enumerable: true,
19
22
  configurable: true,
20
23
  writable: true,
21
24
  value: void 0
22
25
  });
26
+ /**
27
+ * Use only for typing purposes. The value is always `undefined`.
28
+ */
29
+ Object.defineProperty(this, "_partialType", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
23
35
  this.zodSchema = zodSchema;
24
36
  }
25
37
  validate(data) {
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { JsonSchemaProducer } from "./JsonSchemaProducer.js";
3
3
  import { Schema } from "./Schema.js";
4
+ import { PartialDeep } from "type-fest";
4
5
  export declare function zodSchema<STRUCTURE>(zodSchema: z.Schema<STRUCTURE>): ZodSchema<STRUCTURE>;
5
6
  export declare class ZodSchema<STRUCTURE> implements Schema<STRUCTURE>, JsonSchemaProducer {
6
7
  readonly zodSchema: z.Schema<STRUCTURE>;
@@ -13,5 +14,14 @@ export declare class ZodSchema<STRUCTURE> implements Schema<STRUCTURE>, JsonSche
13
14
  error: unknown;
14
15
  };
15
16
  getJsonSchema(): unknown;
17
+ /**
18
+ * Use only for typing purposes. The value is always `undefined`.
19
+ */
16
20
  readonly _type: STRUCTURE;
21
+ /**
22
+ * Use only for typing purposes. The value is always `undefined`.
23
+ */
24
+ readonly _partialType: PartialDeep<STRUCTURE, {
25
+ recurseIntoArrays: true;
26
+ }>;
17
27
  }
@@ -10,12 +10,24 @@ export class ZodSchema {
10
10
  writable: true,
11
11
  value: void 0
12
12
  });
13
+ /**
14
+ * Use only for typing purposes. The value is always `undefined`.
15
+ */
13
16
  Object.defineProperty(this, "_type", {
14
17
  enumerable: true,
15
18
  configurable: true,
16
19
  writable: true,
17
20
  value: void 0
18
21
  });
22
+ /**
23
+ * Use only for typing purposes. The value is always `undefined`.
24
+ */
25
+ Object.defineProperty(this, "_partialType", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
19
31
  this.zodSchema = zodSchema;
20
32
  }
21
33
  validate(data) {
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  export interface TextPart {
2
3
  type: "text";
3
4
  /**
@@ -8,9 +9,9 @@ export interface TextPart {
8
9
  export interface ImagePart {
9
10
  type: "image";
10
11
  /**
11
- * Image data. Can either be a base64-encoded string or a Uint8Array.
12
+ * Image data. Can either be a base64-encoded string, a Uint8Array, or a Buffer.
12
13
  */
13
- image: string | Uint8Array;
14
+ image: string | Uint8Array | Buffer;
14
15
  /**
15
16
  * Optional mime type of the image.
16
17
  */
@@ -27,5 +28,5 @@ export interface ToolResponsePart {
27
28
  id: string;
28
29
  response: unknown;
29
30
  }
30
- export declare function getImageAsBase64(image: string | Uint8Array): string;
31
+ export declare function getImageAsBase64(image: string | Uint8Array | Buffer): string;
31
32
  export declare function validateContentIsString(content: string | unknown, prompt: unknown): string;
@@ -69,9 +69,9 @@ export declare class StabilityImageGenerationModel extends AbstractModel<Stabili
69
69
  doGenerateImages(prompt: StabilityImageGenerationPrompt, callOptions: FunctionCallOptions): Promise<{
70
70
  rawResponse: {
71
71
  artifacts: {
72
+ base64: string;
72
73
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
73
74
  seed: number;
74
- base64: string;
75
75
  }[];
76
76
  };
77
77
  base64Images: string[];
@@ -86,25 +86,25 @@ declare const stabilityImageGenerationResponseSchema: z.ZodObject<{
86
86
  seed: z.ZodNumber;
87
87
  finishReason: z.ZodEnum<["SUCCESS", "ERROR", "CONTENT_FILTERED"]>;
88
88
  }, "strip", z.ZodTypeAny, {
89
+ base64: string;
89
90
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
90
91
  seed: number;
91
- base64: string;
92
92
  }, {
93
+ base64: string;
93
94
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
94
95
  seed: number;
95
- base64: string;
96
96
  }>, "many">;
97
97
  }, "strip", z.ZodTypeAny, {
98
98
  artifacts: {
99
+ base64: string;
99
100
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
100
101
  seed: number;
101
- base64: string;
102
102
  }[];
103
103
  }, {
104
104
  artifacts: {
105
+ base64: string;
105
106
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
106
107
  seed: number;
107
- base64: string;
108
108
  }[];
109
109
  }>;
110
110
  export type StabilityImageGenerationResponse = z.infer<typeof stabilityImageGenerationResponseSchema>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building AI applications.",
4
- "version": "0.128.0",
4
+ "version": "0.129.1",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -80,7 +80,7 @@
80
80
  "@vitest/ui": "1.1.0",
81
81
  "eslint": "^8.45.0",
82
82
  "eslint-config-prettier": "9.1.0",
83
- "msw": "2.0.11",
83
+ "msw": "2.1.2",
84
84
  "type-fest": "4.9.0"
85
85
  }
86
86
  }