@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 CHANGED
@@ -1,12 +1,11 @@
1
1
  import type { ChatMessage, EmberModelId } from "./types";
2
- export declare function createEmber(opts?: {
3
- model?: EmberModelId;
4
- }): {
5
- chat(m: ChatMessage[]): Promise<any>;
6
- rewrite(t: string, tone?: string): Promise<any>;
7
- summarize(t: string): Promise<any>;
8
- models: {
9
- name: string;
10
- id: string;
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
- export function createEmber(opts = {}) { const model = opts.model ?? "lightning"; const cfg = MODELS[model]; let engine = null; async function get() { if (engine)
5
- return engine; const w = new Worker(new URL("./worker.js", import.meta.url), { type: "module" }); engine = await CreateWebWorkerMLCEngine(w, cfg.id); return engine; } return { async chat(m) { const e = await get(); const r = await e.chat.completions.create({ messages: m }); return r.choices[0].message.content; }, async rewrite(t, tone = "friendly") { return this.chat([{ role: "user", content: prompts.rewrite(t, tone) }]); }, async summarize(t) { return this.chat([{ role: "user", content: prompts.summarize(t) }]); }, models: MODELS }; }
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
@@ -1,3 +1,4 @@
1
1
  export { createEmber } from "./engine";
2
+ export type { EmberInstance } from "./engine";
2
3
  export { prompts } from "./prompts";
3
4
  export type { EmberModelId } from "./types";
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": "Phi-3.5-mini-instruct-q4f16_1-MLC" },
4
- { "name": "standard", "id": "gemma-2-2b-it-q4f16_1-MLC" },
5
- { "name": "balance", "id": "Qwen2.5-Coder-1.5B-Instruct-q4f16_1-MLC" },
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 = "lightning" | "nano" | "balanced" | "standard" | "large";
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
- role: "system" | "user" | "assistant";
4
- content: string;
9
+ role: "system" | "user" | "assistant";
10
+ content: string;
5
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wayfield/ember",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Local-first AI engine for the web. Runs entirely in browser via WebGPU. No API keys.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",