modelfusion 0.130.0 → 0.130.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 +6 -0
- package/README.md +9 -6
- package/package.json +1 -1
- package/util/SimpleWebSocket.cjs +15 -8
- package/util/SimpleWebSocket.js +15 -8
- package/util/detectRuntime.cjs +21 -0
- package/util/detectRuntime.d.ts +1 -0
- package/util/detectRuntime.js +17 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -89,13 +89,16 @@ import { readFileSync } from "fs";
|
|
89
89
|
const image = readFileSync("./image.png");
|
90
90
|
|
91
91
|
const textStream = await streamText({
|
92
|
-
model: openai
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
model: openai
|
93
|
+
.ChatTextGenerator({ model: "gpt-4-vision-preview" })
|
94
|
+
.withInstructionPrompt(),
|
95
|
+
|
96
|
+
prompt: {
|
97
|
+
instruction: [
|
98
|
+
{ type: "text", text: "Describe the image in detail." },
|
96
99
|
{ type: "image", image, mimeType: "image/png" },
|
97
|
-
]
|
98
|
-
|
100
|
+
],
|
101
|
+
},
|
99
102
|
});
|
100
103
|
|
101
104
|
for await (const textPart of textStream) {
|
package/package.json
CHANGED
package/util/SimpleWebSocket.cjs
CHANGED
@@ -24,18 +24,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
26
|
exports.createSimpleWebSocket = void 0;
|
27
|
+
const Runtime = __importStar(require("./detectRuntime.cjs"));
|
27
28
|
/**
|
28
29
|
* Creates a simplified websocket connection. This function works in both Node.js and browser.
|
29
30
|
*/
|
30
31
|
async function createSimpleWebSocket(url) {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
switch (Runtime.detectRuntime()) {
|
33
|
+
case "vercel-edge":
|
34
|
+
case "cloudflare-workers":
|
35
|
+
case "browser": {
|
36
|
+
return new WebSocket(url);
|
37
|
+
}
|
38
|
+
case "node": {
|
39
|
+
// Use ws library (for Node.js):
|
40
|
+
const { default: WebSocket } = await Promise.resolve().then(() => __importStar(require("ws")));
|
41
|
+
return new WebSocket(url);
|
42
|
+
}
|
43
|
+
default: {
|
44
|
+
throw new Error("Unknown runtime");
|
45
|
+
}
|
39
46
|
}
|
40
47
|
}
|
41
48
|
exports.createSimpleWebSocket = createSimpleWebSocket;
|
package/util/SimpleWebSocket.js
CHANGED
@@ -1,14 +1,21 @@
|
|
1
|
+
import * as Runtime from "./detectRuntime.js";
|
1
2
|
/**
|
2
3
|
* Creates a simplified websocket connection. This function works in both Node.js and browser.
|
3
4
|
*/
|
4
5
|
export async function createSimpleWebSocket(url) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
switch (Runtime.detectRuntime()) {
|
7
|
+
case "vercel-edge":
|
8
|
+
case "cloudflare-workers":
|
9
|
+
case "browser": {
|
10
|
+
return new WebSocket(url);
|
11
|
+
}
|
12
|
+
case "node": {
|
13
|
+
// Use ws library (for Node.js):
|
14
|
+
const { default: WebSocket } = await import("ws");
|
15
|
+
return new WebSocket(url);
|
16
|
+
}
|
17
|
+
default: {
|
18
|
+
throw new Error("Unknown runtime");
|
19
|
+
}
|
13
20
|
}
|
14
21
|
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.detectRuntime = void 0;
|
4
|
+
function detectRuntime() {
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
|
+
const globalThisAny = globalThis;
|
7
|
+
if (globalThisAny.EdgeRuntime) {
|
8
|
+
return "vercel-edge";
|
9
|
+
}
|
10
|
+
if (globalThis.navigator?.userAgent === "Cloudflare-Workers") {
|
11
|
+
return "cloudflare-workers";
|
12
|
+
}
|
13
|
+
if (globalThis.process?.release?.name === "node") {
|
14
|
+
return "node";
|
15
|
+
}
|
16
|
+
if (globalThis.window) {
|
17
|
+
return "browser";
|
18
|
+
}
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
exports.detectRuntime = detectRuntime;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function detectRuntime(): "vercel-edge" | "cloudflare-workers" | "node" | "browser" | null;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export function detectRuntime() {
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
3
|
+
const globalThisAny = globalThis;
|
4
|
+
if (globalThisAny.EdgeRuntime) {
|
5
|
+
return "vercel-edge";
|
6
|
+
}
|
7
|
+
if (globalThis.navigator?.userAgent === "Cloudflare-Workers") {
|
8
|
+
return "cloudflare-workers";
|
9
|
+
}
|
10
|
+
if (globalThis.process?.release?.name === "node") {
|
11
|
+
return "node";
|
12
|
+
}
|
13
|
+
if (globalThis.window) {
|
14
|
+
return "browser";
|
15
|
+
}
|
16
|
+
return null;
|
17
|
+
}
|