@blank-utils/llm 0.1.0 → 0.2.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.
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Local LLM - Browser-based LLM inference library
3
+ * Shared TypeScript types and interfaces
4
+ */
5
+ /**
6
+ * Supported backend engines
7
+ */
8
+ export type Backend = 'webllm' | 'transformers' | 'auto';
9
+ /**
10
+ * Device to run inference on
11
+ */
12
+ export type Device = 'webgpu' | 'wasm' | 'auto';
13
+ /**
14
+ * Quantization options for model loading
15
+ */
16
+ export type Quantization = 'q4' | 'q8' | 'fp16' | 'fp32';
17
+ /**
18
+ * Configuration for creating an LLM instance
19
+ */
20
+ export interface LLMConfig {
21
+ /**
22
+ * Model identifier. For WebLLM, use MLC model IDs.
23
+ * For Transformers.js, use HuggingFace model IDs.
24
+ * @default 'Phi-3-mini-4k-instruct-q4f16_1-MLC' for WebLLM
25
+ */
26
+ model?: string;
27
+ /**
28
+ * Which backend to use
29
+ * @default 'auto' - Will prefer WebLLM if WebGPU available
30
+ */
31
+ backend?: Backend;
32
+ /**
33
+ * Device to run on
34
+ * @default 'auto' - Prefers WebGPU, falls back to WASM
35
+ */
36
+ device?: Device;
37
+ /**
38
+ * Quantization level (transformers.js only)
39
+ * @default 'q4'
40
+ */
41
+ quantization?: Quantization;
42
+ /**
43
+ * System prompt to use for all conversations
44
+ */
45
+ systemPrompt?: string;
46
+ /**
47
+ * Callback for model loading progress
48
+ */
49
+ onLoadProgress?: LoadProgressCallback;
50
+ }
51
+ /**
52
+ * Role in a chat conversation
53
+ */
54
+ export type MessageRole = 'system' | 'user' | 'assistant';
55
+ /**
56
+ * A single message in a chat conversation
57
+ */
58
+ export interface ChatMessage {
59
+ role: MessageRole;
60
+ content: string;
61
+ }
62
+ /**
63
+ * Callback for streaming token output
64
+ */
65
+ export type StreamCallback = (token: string, fullText: string) => void;
66
+ /**
67
+ * Loading progress information
68
+ */
69
+ export interface LoadProgress {
70
+ /** Progress percentage (0-100) */
71
+ progress: number;
72
+ /** Current status text */
73
+ status: string;
74
+ /** Bytes loaded (if available) */
75
+ loaded?: number;
76
+ /** Total bytes (if available) */
77
+ total?: number;
78
+ }
79
+ /**
80
+ * Callback for model loading progress
81
+ */
82
+ export type LoadProgressCallback = (progress: LoadProgress) => void;
83
+ /**
84
+ * Options for text generation
85
+ */
86
+ export interface GenerateOptions {
87
+ /**
88
+ * Temperature for sampling (0-2)
89
+ * @default 0.7
90
+ */
91
+ temperature?: number;
92
+ /**
93
+ * Maximum tokens to generate
94
+ * @default 512
95
+ */
96
+ maxTokens?: number;
97
+ /**
98
+ * Top-p sampling
99
+ * @default 0.95
100
+ */
101
+ topP?: number;
102
+ /**
103
+ * Stop sequences
104
+ */
105
+ stopSequences?: string[];
106
+ }
107
+ /**
108
+ * Unified interface for LLM backends
109
+ */
110
+ export interface LLMProvider {
111
+ /**
112
+ * Backend identifier
113
+ */
114
+ readonly backend: Backend;
115
+ /**
116
+ * Whether the model is loaded and ready
117
+ */
118
+ readonly isReady: boolean;
119
+ /**
120
+ * Current model ID
121
+ */
122
+ readonly modelId: string | null;
123
+ /**
124
+ * Load a model
125
+ */
126
+ load(modelId: string, onProgress?: LoadProgressCallback): Promise<void>;
127
+ /**
128
+ * Generate a response (non-streaming)
129
+ */
130
+ chat(messages: ChatMessage[], options?: GenerateOptions): Promise<string>;
131
+ /**
132
+ * Generate a response with streaming
133
+ */
134
+ stream(messages: ChatMessage[], onToken: StreamCallback, options?: GenerateOptions): Promise<string>;
135
+ /**
136
+ * Unload the model and free resources
137
+ */
138
+ unload(): Promise<void>;
139
+ }
140
+ /**
141
+ * Options for attaching to an input element
142
+ */
143
+ export interface AttachOptions {
144
+ /**
145
+ * Trigger generation on Enter key
146
+ * @default true
147
+ */
148
+ triggerOnEnter?: boolean;
149
+ /**
150
+ * Clear input after sending
151
+ * @default true
152
+ */
153
+ clearOnSend?: boolean;
154
+ /**
155
+ * Show loading indicator
156
+ * @default true
157
+ */
158
+ showLoading?: boolean;
159
+ /**
160
+ * Custom loading text
161
+ * @default 'Thinking...'
162
+ */
163
+ loadingText?: string;
164
+ }
165
+ /**
166
+ * Browser capability information
167
+ */
168
+ export interface BrowserCapabilities {
169
+ /** WebGPU is available */
170
+ webgpu: boolean;
171
+ /** WebAssembly is available */
172
+ wasm: boolean;
173
+ /** Recommended backend based on capabilities */
174
+ recommendedBackend: Backend;
175
+ /** Recommended device based on capabilities */
176
+ recommendedDevice: Device;
177
+ }
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,cAAc,GAAG,MAAM,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC;AAMD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AA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C,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAMD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,MAAM,EAAE,OAAO,CAAC;IAChB,+BAA+B;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,gDAAgD;IAChD,kBAAkB,EAAE,OAAO,CAAC;IAC5B,+CAA+C;IAC/C,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
package/package.json CHANGED
@@ -1,32 +1,46 @@
1
1
  {
2
2
  "name": "@blank-utils/llm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Run LLMs directly in your browser with WebGPU acceleration. Supports React hooks and eager background loading.",
5
- "module": "./dist/index.js",
5
+ "type": "module",
6
6
  "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",
8
- "type": "module",
9
+ "sideEffects": false,
9
10
  "exports": {
10
11
  ".": {
12
+ "types": "./dist/index.d.ts",
11
13
  "import": "./dist/index.js",
12
- "types": "./dist/index.d.ts"
14
+ "default": "./dist/index.js"
13
15
  },
14
16
  "./react": {
17
+ "types": "./dist/react/index.d.ts",
15
18
  "import": "./dist/react/index.js",
16
- "types": "./dist/react/index.d.ts"
19
+ "default": "./dist/react/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ ".": ["./dist/index.d.ts"],
26
+ "react": ["./dist/react/index.d.ts"]
17
27
  }
18
28
  },
19
29
  "files": [
20
30
  "dist",
21
- "README.md"
31
+ "README.md",
32
+ "LICENSE"
22
33
  ],
23
34
  "scripts": {
24
35
  "dev": "bun --watch ./src/index.ts",
25
- "build": "bun build ./src/index.ts ./src/react/index.tsx --outdir ./dist --format esm --sourcemap --splitting --external react",
26
- "build:types": "tsc --declaration --emitDeclarationOnly --outDir dist",
27
- "prepublishOnly": "pnpm build",
36
+ "clean": "rm -rf dist",
37
+ "build:js": "bun build ./src/index.ts ./src/react/index.tsx --outdir ./dist --format esm --sourcemap --splitting --external react --external react-dom",
38
+ "build:types": "tsc -p tsconfig.build.json",
39
+ "build": "bun run clean && bun run build:js && bun run build:types",
40
+ "prepublishOnly": "bun run build",
28
41
  "demo": "bunx serve . -p 3000",
29
- "typecheck": "tsc --noEmit"
42
+ "typecheck": "tsc --noEmit",
43
+ "test": "bun test"
30
44
  },
31
45
  "keywords": [
32
46
  "llm",
@@ -40,30 +54,34 @@
40
54
  "react",
41
55
  "hooks",
42
56
  "streaming",
43
- "chat"
57
+ "chat",
58
+ "gpt",
59
+ "huggingface"
44
60
  ],
45
61
  "author": "blank",
46
62
  "license": "MIT",
47
63
  "repository": {
48
64
  "type": "git",
49
- "url": "https://github.com/blank-utils/llm"
65
+ "url": "git+https://github.com/kiritocode1/local-llm.git"
50
66
  },
51
- "homepage": "https://github.com/blank-utils/llm#readme",
67
+ "homepage": "https://github.com/kiritocode1/local-llm#readme",
52
68
  "bugs": {
53
- "url": "https://github.com/blank-utils/llm/issues"
69
+ "url": "https://github.com/kiritocode1/local-llm/issues"
54
70
  },
55
71
  "publishConfig": {
56
72
  "access": "public"
57
73
  },
74
+ "engines": {
75
+ "node": ">=18"
76
+ },
58
77
  "devDependencies": {
59
78
  "@types/bun": "latest",
60
- "@types/react": "^18.3.28",
61
- "@types/react-dom": "^19.2.3",
62
- "@webgpu/types": "^0.1.69"
79
+ "@types/react": "^18.3.0 || ^19.0.0",
80
+ "@webgpu/types": "^0.1.69",
81
+ "typescript": "^5.0.0"
63
82
  },
64
83
  "peerDependencies": {
65
- "react": "^18 || ^19",
66
- "typescript": "^5"
84
+ "react": ">=18.0.0"
67
85
  },
68
86
  "peerDependenciesMeta": {
69
87
  "react": {
@@ -75,4 +93,3 @@
75
93
  "@mlc-ai/web-llm": "^0.2.80"
76
94
  }
77
95
  }
78
-