modelfusion 0.128.0 → 0.129.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.
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,11 @@ 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_
641
641
 
642
- Create an 19th century painting image for your input.
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.
642
+ Various examples of using ModelFusion with Next.js: Image generation, voice recording & transcription.
649
643
 
650
644
  ### [Duplex Speech Streaming (using Vite/React & ModelFusion Server/Fastify)](https://github.com/lgrammel/modelfusion/tree/main/examples/speech-streaming-vite-react-fastify)
651
645
 
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();
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.0",
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
  }