@forbocai/browser 0.5.0 → 0.5.2
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +25 -6
- package/dist/index.mjs +14 -5
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CortexConfig, ICortex, MemoryType, MemoryItem, MemoryConfig } from '@forbocai/core';
|
|
2
2
|
|
|
3
|
-
declare const createBrowserCortex: (config
|
|
4
|
-
declare const createCortex: (config
|
|
3
|
+
declare const createBrowserCortex: (config?: CortexConfig) => ICortex;
|
|
4
|
+
declare const createCortex: (config?: CortexConfig) => ICortex;
|
|
5
5
|
|
|
6
6
|
interface IBrowserMemory {
|
|
7
7
|
store(text: string, type?: MemoryType, importance?: number): Promise<MemoryItem>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CortexConfig, ICortex, MemoryType, MemoryItem, MemoryConfig } from '@forbocai/core';
|
|
2
2
|
|
|
3
|
-
declare const createBrowserCortex: (config
|
|
4
|
-
declare const createCortex: (config
|
|
3
|
+
declare const createBrowserCortex: (config?: CortexConfig) => ICortex;
|
|
4
|
+
declare const createCortex: (config?: CortexConfig) => ICortex;
|
|
5
5
|
|
|
6
6
|
interface IBrowserMemory {
|
|
7
7
|
store(text: string, type?: MemoryType, importance?: number): Promise<MemoryItem>;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -32,11 +42,20 @@ module.exports = __toCommonJS(index_exports);
|
|
|
32
42
|
// src/cortex.ts
|
|
33
43
|
var import_web_llm = require("@mlc-ai/web-llm");
|
|
34
44
|
var import_meta = {};
|
|
35
|
-
var
|
|
45
|
+
var DEFAULT_MODEL = "smollm2-135m";
|
|
46
|
+
var MODEL_ALIASES = {
|
|
47
|
+
"smollm2-135m": "SmolLM2-135M-Instruct-q4f16_1-MLC",
|
|
48
|
+
"smollm2-360m": "SmolLM2-360M-Instruct-q4f16_1-MLC",
|
|
49
|
+
"smollm2-1.7b": "SmolLM2-1.7B-Instruct-q4f16_1-MLC",
|
|
50
|
+
"llama3-8b": "Llama-3.1-8B-Instruct-q4f16_1-MLC"
|
|
51
|
+
};
|
|
52
|
+
var resolveModelId = (alias) => MODEL_ALIASES[alias] ?? alias;
|
|
53
|
+
var createBrowserCortex = (config = {}) => {
|
|
54
|
+
const friendlyModel = config.model || DEFAULT_MODEL;
|
|
36
55
|
let engine = null;
|
|
37
56
|
let status = {
|
|
38
57
|
id: "browser-init",
|
|
39
|
-
model:
|
|
58
|
+
model: friendlyModel,
|
|
40
59
|
ready: false,
|
|
41
60
|
engine: "web-llm"
|
|
42
61
|
};
|
|
@@ -47,7 +66,7 @@ var createBrowserCortex = (config) => {
|
|
|
47
66
|
if (onProgress) {
|
|
48
67
|
}
|
|
49
68
|
};
|
|
50
|
-
const modelId =
|
|
69
|
+
const modelId = resolveModelId(friendlyModel);
|
|
51
70
|
engine = await (0, import_web_llm.CreateWebWorkerMLCEngine)(
|
|
52
71
|
new Worker(new URL("./worker.js", import_meta.url), { type: "module" }),
|
|
53
72
|
modelId,
|
|
@@ -89,18 +108,18 @@ var createBrowserCortex = (config) => {
|
|
|
89
108
|
completeStream
|
|
90
109
|
};
|
|
91
110
|
};
|
|
92
|
-
var createCortex = (config) => createBrowserCortex(config);
|
|
111
|
+
var createCortex = (config = {}) => createBrowserCortex(config);
|
|
93
112
|
|
|
94
113
|
// src/memory.ts
|
|
95
114
|
var import_orama = require("@orama/orama");
|
|
96
115
|
|
|
97
116
|
// src/vector.ts
|
|
98
|
-
var import_transformers = require("@xenova/transformers");
|
|
99
117
|
var embedder = null;
|
|
100
118
|
var initVectorEngine = async () => {
|
|
101
119
|
if (embedder) return;
|
|
102
120
|
console.log("> Initializing Browser Vector Engine...");
|
|
103
|
-
|
|
121
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
122
|
+
embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
|
104
123
|
};
|
|
105
124
|
var generateEmbedding = async (text) => {
|
|
106
125
|
if (!embedder) await initVectorEngine();
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
// src/cortex.ts
|
|
2
2
|
import { CreateWebWorkerMLCEngine } from "@mlc-ai/web-llm";
|
|
3
|
-
var
|
|
3
|
+
var DEFAULT_MODEL = "smollm2-135m";
|
|
4
|
+
var MODEL_ALIASES = {
|
|
5
|
+
"smollm2-135m": "SmolLM2-135M-Instruct-q4f16_1-MLC",
|
|
6
|
+
"smollm2-360m": "SmolLM2-360M-Instruct-q4f16_1-MLC",
|
|
7
|
+
"smollm2-1.7b": "SmolLM2-1.7B-Instruct-q4f16_1-MLC",
|
|
8
|
+
"llama3-8b": "Llama-3.1-8B-Instruct-q4f16_1-MLC"
|
|
9
|
+
};
|
|
10
|
+
var resolveModelId = (alias) => MODEL_ALIASES[alias] ?? alias;
|
|
11
|
+
var createBrowserCortex = (config = {}) => {
|
|
12
|
+
const friendlyModel = config.model || DEFAULT_MODEL;
|
|
4
13
|
let engine = null;
|
|
5
14
|
let status = {
|
|
6
15
|
id: "browser-init",
|
|
7
|
-
model:
|
|
16
|
+
model: friendlyModel,
|
|
8
17
|
ready: false,
|
|
9
18
|
engine: "web-llm"
|
|
10
19
|
};
|
|
@@ -15,7 +24,7 @@ var createBrowserCortex = (config) => {
|
|
|
15
24
|
if (onProgress) {
|
|
16
25
|
}
|
|
17
26
|
};
|
|
18
|
-
const modelId =
|
|
27
|
+
const modelId = resolveModelId(friendlyModel);
|
|
19
28
|
engine = await CreateWebWorkerMLCEngine(
|
|
20
29
|
new Worker(new URL("./worker.js", import.meta.url), { type: "module" }),
|
|
21
30
|
modelId,
|
|
@@ -57,17 +66,17 @@ var createBrowserCortex = (config) => {
|
|
|
57
66
|
completeStream
|
|
58
67
|
};
|
|
59
68
|
};
|
|
60
|
-
var createCortex = (config) => createBrowserCortex(config);
|
|
69
|
+
var createCortex = (config = {}) => createBrowserCortex(config);
|
|
61
70
|
|
|
62
71
|
// src/memory.ts
|
|
63
72
|
import { create, insert, search } from "@orama/orama";
|
|
64
73
|
|
|
65
74
|
// src/vector.ts
|
|
66
|
-
import { pipeline } from "@xenova/transformers";
|
|
67
75
|
var embedder = null;
|
|
68
76
|
var initVectorEngine = async () => {
|
|
69
77
|
if (embedder) return;
|
|
70
78
|
console.log("> Initializing Browser Vector Engine...");
|
|
79
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
71
80
|
embedder = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
|
72
81
|
};
|
|
73
82
|
var generateEmbedding = async (text) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forbocai/browser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Web Browser implementation for ForbocAI SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"test": "vitest"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@forbocai/core": "^0.5.
|
|
15
|
+
"@forbocai/core": "^0.5.2",
|
|
16
16
|
"@mlc-ai/web-llm": "^0.2.46",
|
|
17
17
|
"@orama/orama": "^2.0.26",
|
|
18
|
-
"@
|
|
18
|
+
"@huggingface/transformers": "^3.0.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"tsup": "^8.5.1",
|