@wayfield/ember 0.1.1 → 0.1.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/engine.d.ts +10 -11
- package/dist/engine.js +40 -2
- package/dist/index.d.ts +1 -0
- package/dist/models.json +5 -5
- package/dist/types.d.ts +9 -3
- package/package.json +1 -1
package/dist/engine.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ChatMessage, EmberModelId } from "./types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
2
|
+
|
|
3
|
+
export interface EmberInstance {
|
|
4
|
+
init(): Promise<any>;
|
|
5
|
+
chat(m: ChatMessage[]): Promise<string>;
|
|
6
|
+
rewrite(t: string, tone?: string): Promise<string>;
|
|
7
|
+
summarize(t: string): Promise<string>;
|
|
8
|
+
models: { name: string; id: string }[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare function createEmber(modelId?: EmberModelId): EmberInstance;
|
package/dist/engine.js
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
import { CreateWebWorkerMLCEngine } from "@mlc-ai/web-llm";
|
|
2
2
|
import MODELS from "./models.json";
|
|
3
3
|
import { prompts } from "./prompts";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
export function createEmber(modelId = "ember-balance") {
|
|
6
|
+
const cfg = MODELS[modelId];
|
|
7
|
+
if (!cfg) throw new Error(`Unknown model: ${modelId}`);
|
|
8
|
+
|
|
9
|
+
let engine = null;
|
|
10
|
+
let initPromise = null;
|
|
11
|
+
|
|
12
|
+
async function init() {
|
|
13
|
+
if (engine) return engine;
|
|
14
|
+
if (initPromise) return initPromise;
|
|
15
|
+
initPromise = (async () => {
|
|
16
|
+
const w = new Worker(new URL("./worker.js", import.meta.url), { type: "module" });
|
|
17
|
+
engine = await CreateWebWorkerMLCEngine(w, cfg.id);
|
|
18
|
+
return engine;
|
|
19
|
+
})().catch(e => {
|
|
20
|
+
initPromise = null; // allow retry on failure
|
|
21
|
+
throw e;
|
|
22
|
+
});
|
|
23
|
+
return initPromise;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
async init() {
|
|
28
|
+
return init();
|
|
29
|
+
},
|
|
30
|
+
async chat(m) {
|
|
31
|
+
const e = await init();
|
|
32
|
+
const r = await e.chat.completions.create({ messages: m });
|
|
33
|
+
return r.choices[0].message.content;
|
|
34
|
+
},
|
|
35
|
+
async rewrite(t, tone = "friendly") {
|
|
36
|
+
return this.chat([{ role: "user", content: prompts.rewrite(t, tone) }]);
|
|
37
|
+
},
|
|
38
|
+
async summarize(t) {
|
|
39
|
+
return this.chat([{ role: "user", content: prompts.summarize(t) }]);
|
|
40
|
+
},
|
|
41
|
+
models: MODELS
|
|
42
|
+
};
|
|
43
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/models.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[
|
|
2
|
-
{ "name": "lightning", "id": "Llama-3.2-1B-Instruct-q4f16_1-MLC" },
|
|
3
|
-
{ "name": "nano", "id": "
|
|
4
|
-
{ "name": "standard", "id": "gemma-2-2b-it-q4f16_1-MLC" },
|
|
5
|
-
{ "name": "balance", "id": "
|
|
6
|
-
{ "name": "titan", "id": "Llama-3.2-3B-Instruct-q4f16_1-MLC" }
|
|
2
|
+
{ "name": "ember-lightning", "id": "Llama-3.2-1B-Instruct-q4f16_1-MLC" },
|
|
3
|
+
{ "name": "ember-nano", "id": "Qwen2.5-Coder-1.5B-Instruct-q4f16_1-MLC" },
|
|
4
|
+
{ "name": "ember-standard", "id": "gemma-2-2b-it-q4f16_1-MLC" },
|
|
5
|
+
{ "name": "ember-balance", "id": "Phi-3.5-mini-instruct-q4f16_1-MLC" },
|
|
6
|
+
{ "name": "ember-titan", "id": "Llama-3.2-3B-Instruct-q4f16_1-MLC" }
|
|
7
7
|
]
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
export type EmberModelId =
|
|
1
|
+
export type EmberModelId =
|
|
2
|
+
| "ember-lightning"
|
|
3
|
+
| "ember-nano"
|
|
4
|
+
| "ember-standard"
|
|
5
|
+
| "ember-balance"
|
|
6
|
+
| "ember-titan";
|
|
7
|
+
|
|
2
8
|
export interface ChatMessage {
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
role: "system" | "user" | "assistant";
|
|
10
|
+
content: string;
|
|
5
11
|
}
|