@blank-utils/llm 0.2.2 → 0.2.6
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/README.md +487 -89
- package/dist/index.js +1245 -65
- package/dist/react/index.js +1267 -66
- package/package.json +6 -3
- package/dist/backends/transformers.d.ts +0 -62
- package/dist/backends/transformers.d.ts.map +0 -1
- package/dist/backends/webllm.d.ts +0 -70
- package/dist/backends/webllm.d.ts.map +0 -1
- package/dist/core.d.ts +0 -71
- package/dist/core.d.ts.map +0 -1
- package/dist/detect.d.ts +0 -21
- package/dist/detect.d.ts.map +0 -1
- package/dist/helpers.d.ts +0 -35
- package/dist/helpers.d.ts.map +0 -1
- package/dist/index.d.ts +0 -27
- package/dist/index.d.ts.map +0 -1
- package/dist/react/index.d.ts +0 -309
- package/dist/react/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -178
- package/dist/types.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blank-utils/llm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Run LLMs directly in your browser with WebGPU acceleration. Supports React hooks and eager background loading.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"dev": "bun --watch ./src/index.ts",
|
|
36
36
|
"clean": "rm -rf dist",
|
|
37
|
-
"build:js": "bun build ./src/index.ts --outfile ./dist/index.js --format esm --external react --external react-dom && bun build ./src/react/index.tsx --outfile ./dist/react/index.js --format esm --external react --external react-dom",
|
|
37
|
+
"build:js": "bun build ./src/index.ts --outfile ./dist/index.js --format esm --external react --external react-dom --external streamdown --external @streamdown/code --external @streamdown/mermaid && bun build ./src/react/index.tsx --outfile ./dist/react/index.js --format esm --external react --external react-dom --external streamdown --external @streamdown/code --external @streamdown/mermaid",
|
|
38
38
|
"postbuild": "mkdir -p dist/react && cp node_modules/@huggingface/transformers/dist/*.wasm dist/ && cp node_modules/onnxruntime-web/dist/*.mjs dist/ && cp node_modules/onnxruntime-web/dist/*.wasm dist/ && cp dist/*.wasm dist/react/ 2>/dev/null || true && cp dist/*.mjs dist/react/ 2>/dev/null || true",
|
|
39
39
|
"build:types": "tsc -p tsconfig.build.json",
|
|
40
40
|
"build": "bun run clean && bun run build:js && bun run postbuild && bun run build:types",
|
|
@@ -91,6 +91,9 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@huggingface/transformers": "^3.8.1",
|
|
94
|
-
"@mlc-ai/web-llm": "^0.2.80"
|
|
94
|
+
"@mlc-ai/web-llm": "^0.2.80",
|
|
95
|
+
"@streamdown/code": "^1.0.2",
|
|
96
|
+
"@streamdown/mermaid": "^1.0.2",
|
|
97
|
+
"streamdown": "^2.2.0"
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transformers.js Backend Implementation
|
|
3
|
-
* Fallback backend using HuggingFace Transformers.js with ONNX runtime
|
|
4
|
-
*/
|
|
5
|
-
import type { LLMProvider, ChatMessage, GenerateOptions, StreamCallback, LoadProgressCallback, Backend, Device, Quantization } from '../types';
|
|
6
|
-
/**
|
|
7
|
-
* Default model for Transformers.js backend
|
|
8
|
-
* Using Qwen2.5 0.5B as it's well-tested with ONNX
|
|
9
|
-
*/
|
|
10
|
-
export declare const DEFAULT_TRANSFORMERS_MODEL = "onnx-community/Qwen2.5-0.5B-Instruct";
|
|
11
|
-
/**
|
|
12
|
-
* Transformers.js compatible models (must have ONNX weights)
|
|
13
|
-
* These are specifically converted for browser use via transformers.js
|
|
14
|
-
*
|
|
15
|
-
* @see https://huggingface.co/onnx-community for more models
|
|
16
|
-
*/
|
|
17
|
-
export declare const TRANSFORMERS_MODELS: {
|
|
18
|
-
readonly 'qwen-2.5-0.5b': "onnx-community/Qwen2.5-0.5B-Instruct";
|
|
19
|
-
readonly 'qwen-2.5-1.5b': "onnx-community/Qwen2.5-1.5B-Instruct";
|
|
20
|
-
readonly 'qwen-2.5-coder-0.5b': "onnx-community/Qwen2.5-Coder-0.5B-Instruct";
|
|
21
|
-
readonly 'qwen-2.5-coder-1.5b': "onnx-community/Qwen2.5-Coder-1.5B-Instruct";
|
|
22
|
-
readonly 'qwen-3-0.6b': "onnx-community/Qwen3-0.6B-ONNX";
|
|
23
|
-
readonly 'smollm2-135m': "HuggingFaceTB/SmolLM2-135M-Instruct";
|
|
24
|
-
readonly 'smollm2-360m': "HuggingFaceTB/SmolLM2-360M-Instruct";
|
|
25
|
-
readonly 'smollm2-1.7b': "HuggingFaceTB/SmolLM2-1.7B-Instruct";
|
|
26
|
-
readonly 'phi-3-mini': "Xenova/Phi-3-mini-4k-instruct";
|
|
27
|
-
readonly tinyllama: "Xenova/TinyLlama-1.1B-Chat-v1.0";
|
|
28
|
-
};
|
|
29
|
-
export type TransformersModelAlias = keyof typeof TRANSFORMERS_MODELS;
|
|
30
|
-
/**
|
|
31
|
-
* Model size estimates for UI display
|
|
32
|
-
*/
|
|
33
|
-
export declare const TRANSFORMERS_MODEL_SIZES: Record<TransformersModelAlias, string>;
|
|
34
|
-
/**
|
|
35
|
-
* Configuration for TransformersProvider
|
|
36
|
-
*/
|
|
37
|
-
export interface TransformersProviderConfig {
|
|
38
|
-
device?: Device;
|
|
39
|
-
quantization?: Quantization;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Transformers.js provider implementation
|
|
43
|
-
*/
|
|
44
|
-
export declare class TransformersProvider implements LLMProvider {
|
|
45
|
-
readonly backend: Backend;
|
|
46
|
-
private pipeline;
|
|
47
|
-
private currentModel;
|
|
48
|
-
private device;
|
|
49
|
-
private quantization;
|
|
50
|
-
constructor(config?: TransformersProviderConfig);
|
|
51
|
-
get isReady(): boolean;
|
|
52
|
-
get modelId(): string | null;
|
|
53
|
-
load(modelId: string, onProgress?: LoadProgressCallback): Promise<void>;
|
|
54
|
-
chat(messages: ChatMessage[], options?: GenerateOptions): Promise<string>;
|
|
55
|
-
stream(messages: ChatMessage[], onToken: StreamCallback, options?: GenerateOptions): Promise<string>;
|
|
56
|
-
unload(): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Create a Transformers.js provider instance
|
|
60
|
-
*/
|
|
61
|
-
export declare function createTransformersProvider(config?: TransformersProviderConfig): TransformersProvider;
|
|
62
|
-
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../src/backends/transformers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,cAAc,EACd,oBAAoB,EAEpB,OAAO,EACP,MAAM,EACN,YAAY,EACb,MAAM,UAAU,CAAC;AAKlB;;;GAGG;AACH,eAAO,MAAM,0BAA0B,yCAAyC,CAAC;AAEjF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;CAoBtB,CAAC;AAEX,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAW3E,CAAC;AAkGF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,WAAW;IACtD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAkB;IAE3C,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAe;gBAEvB,MAAM,GAAE,0BAA+B;IAKnD,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAEK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDvE,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBzE,MAAM,CACV,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;IAgCZ,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAI9B;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,CAAC,EAAE,0BAA0B,GAAG,oBAAoB,CAEpG"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WebLLM Backend Implementation
|
|
3
|
-
* Primary backend using MLC's WebLLM for high-performance inference
|
|
4
|
-
*/
|
|
5
|
-
import type { LLMProvider, ChatMessage, GenerateOptions, StreamCallback, LoadProgressCallback, Backend } from '../types';
|
|
6
|
-
/**
|
|
7
|
-
* Default model for WebLLM backend
|
|
8
|
-
* Using Phi 3.5 Mini as it's well-tested and reasonably sized
|
|
9
|
-
*/
|
|
10
|
-
export declare const DEFAULT_WEBLLM_MODEL = "Phi-3.5-mini-instruct-q4f16_1-MLC";
|
|
11
|
-
/**
|
|
12
|
-
* Popular WebLLM model options with correct MLC model IDs
|
|
13
|
-
* These IDs must match exactly what's in web-llm's prebuiltAppConfig
|
|
14
|
-
*
|
|
15
|
-
* @see https://github.com/mlc-ai/web-llm/blob/main/src/config.ts
|
|
16
|
-
*/
|
|
17
|
-
export declare const WEBLLM_MODELS: {
|
|
18
|
-
readonly 'llama-3.2-1b': "Llama-3.2-1B-Instruct-q4f16_1-MLC";
|
|
19
|
-
readonly 'llama-3.2-3b': "Llama-3.2-3B-Instruct-q4f16_1-MLC";
|
|
20
|
-
readonly 'llama-3.1-8b': "Llama-3.1-8B-Instruct-q4f16_1-MLC";
|
|
21
|
-
readonly 'llama-3.1-8b-1k': "Llama-3.1-8B-Instruct-q4f16_1-MLC-1k";
|
|
22
|
-
readonly 'phi-3.5-mini': "Phi-3.5-mini-instruct-q4f16_1-MLC";
|
|
23
|
-
readonly 'phi-3.5-mini-1k': "Phi-3.5-mini-instruct-q4f16_1-MLC-1k";
|
|
24
|
-
readonly 'phi-3.5-vision': "Phi-3.5-vision-instruct-q4f16_1-MLC";
|
|
25
|
-
readonly 'qwen-2.5-0.5b': "Qwen2.5-0.5B-Instruct-q4f16_1-MLC";
|
|
26
|
-
readonly 'qwen-2.5-1.5b': "Qwen2.5-1.5B-Instruct-q4f16_1-MLC";
|
|
27
|
-
readonly 'qwen-2.5-3b': "Qwen2.5-3B-Instruct-q4f16_1-MLC";
|
|
28
|
-
readonly 'qwen-2.5-7b': "Qwen2.5-7B-Instruct-q4f16_1-MLC";
|
|
29
|
-
readonly 'qwen-2.5-coder-0.5b': "Qwen2.5-Coder-0.5B-Instruct-q4f16_1-MLC";
|
|
30
|
-
readonly 'qwen-2.5-coder-1.5b': "Qwen2.5-Coder-1.5B-Instruct-q4f16_1-MLC";
|
|
31
|
-
readonly 'qwen-3-0.6b': "Qwen3-0.6B-q4f16_1-MLC";
|
|
32
|
-
readonly 'qwen-3-1.7b': "Qwen3-1.7B-q4f16_1-MLC";
|
|
33
|
-
readonly 'qwen-3-4b': "Qwen3-4B-q4f16_1-MLC";
|
|
34
|
-
readonly 'qwen-3-8b': "Qwen3-8B-q4f16_1-MLC";
|
|
35
|
-
readonly 'gemma-2-2b': "gemma-2-2b-it-q4f16_1-MLC";
|
|
36
|
-
readonly 'gemma-2-2b-1k': "gemma-2-2b-it-q4f16_1-MLC-1k";
|
|
37
|
-
readonly 'gemma-2-9b': "gemma-2-9b-it-q4f16_1-MLC";
|
|
38
|
-
readonly 'smollm2-135m': "SmolLM2-135M-Instruct-q0f16-MLC";
|
|
39
|
-
readonly 'smollm2-360m': "SmolLM2-360M-Instruct-q4f16_1-MLC";
|
|
40
|
-
readonly 'smollm2-1.7b': "SmolLM2-1.7B-Instruct-q4f16_1-MLC";
|
|
41
|
-
readonly 'mistral-7b': "Mistral-7B-Instruct-v0.3-q4f16_1-MLC";
|
|
42
|
-
readonly 'deepseek-r1-qwen-7b': "DeepSeek-R1-Distill-Qwen-7B-q4f16_1-MLC";
|
|
43
|
-
readonly 'deepseek-r1-llama-8b': "DeepSeek-R1-Distill-Llama-8B-q4f16_1-MLC";
|
|
44
|
-
readonly 'hermes-3-llama-3.2-3b': "Hermes-3-Llama-3.2-3B-q4f16_1-MLC";
|
|
45
|
-
readonly 'hermes-3-llama-3.1-8b': "Hermes-3-Llama-3.1-8B-q4f16_1-MLC";
|
|
46
|
-
};
|
|
47
|
-
export type WebLLMModelAlias = keyof typeof WEBLLM_MODELS;
|
|
48
|
-
/**
|
|
49
|
-
* Model size estimates for UI display
|
|
50
|
-
*/
|
|
51
|
-
export declare const WEBLLM_MODEL_SIZES: Record<WebLLMModelAlias, string>;
|
|
52
|
-
/**
|
|
53
|
-
* WebLLM provider implementation
|
|
54
|
-
*/
|
|
55
|
-
export declare class WebLLMProvider implements LLMProvider {
|
|
56
|
-
readonly backend: Backend;
|
|
57
|
-
private engine;
|
|
58
|
-
private currentModel;
|
|
59
|
-
get isReady(): boolean;
|
|
60
|
-
get modelId(): string | null;
|
|
61
|
-
load(modelId: string, onProgress?: LoadProgressCallback): Promise<void>;
|
|
62
|
-
chat(messages: ChatMessage[], options?: GenerateOptions): Promise<string>;
|
|
63
|
-
stream(messages: ChatMessage[], onToken: StreamCallback, options?: GenerateOptions): Promise<string>;
|
|
64
|
-
unload(): Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Create a WebLLM provider instance
|
|
68
|
-
*/
|
|
69
|
-
export declare function createWebLLMProvider(): WebLLMProvider;
|
|
70
|
-
//# sourceMappingURL=webllm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webllm.d.ts","sourceRoot":"","sources":["../../src/backends/webllm.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,cAAc,EACd,oBAAoB,EAEpB,OAAO,EACR,MAAM,UAAU,CAAC;AAMlB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,sCAAsC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDhB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,aAAa,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CA6B/D,CAAC;AAYF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAY;IAErC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,YAAY,CAAuB;IAE3C,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAEK,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBvE,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBzE,MAAM,CACV,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;IA8BZ,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAErD"}
|
package/dist/core.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core LLM functionality - Separated from index.ts to avoid circular dependencies
|
|
3
|
-
* with React integration.
|
|
4
|
-
*
|
|
5
|
-
* @module local-llm/core
|
|
6
|
-
*/
|
|
7
|
-
export type { Backend, Device, Quantization, LLMConfig, MessageRole, ChatMessage, StreamCallback, LoadProgress, LoadProgressCallback, GenerateOptions, LLMProvider as LLMProviderInterface, AttachOptions, BrowserCapabilities, } from './types';
|
|
8
|
-
export { checkWebGPU, checkWasm, detectCapabilities, logCapabilities } from './detect';
|
|
9
|
-
export { WebLLMProvider, createWebLLMProvider, DEFAULT_WEBLLM_MODEL, WEBLLM_MODELS, } from './backends/webllm';
|
|
10
|
-
export { TransformersProvider, createTransformersProvider, DEFAULT_TRANSFORMERS_MODEL, TRANSFORMERS_MODELS, } from './backends/transformers';
|
|
11
|
-
export { createOutputStreamer, attachToElements, createChatUI, createLoadingIndicator, } from './helpers';
|
|
12
|
-
import type { LLMConfig, ChatMessage, GenerateOptions, StreamCallback, AttachOptions } from './types';
|
|
13
|
-
/**
|
|
14
|
-
* Main LLM interface with simplified API
|
|
15
|
-
*/
|
|
16
|
-
export interface LocalLLM {
|
|
17
|
-
/**
|
|
18
|
-
* Whether the model is loaded and ready
|
|
19
|
-
*/
|
|
20
|
-
readonly isReady: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* The current model ID
|
|
23
|
-
*/
|
|
24
|
-
readonly modelId: string | null;
|
|
25
|
-
/**
|
|
26
|
-
* The backend being used
|
|
27
|
-
*/
|
|
28
|
-
readonly backend: 'webllm' | 'transformers';
|
|
29
|
-
/**
|
|
30
|
-
* Generate a chat response
|
|
31
|
-
*/
|
|
32
|
-
chat(messages: ChatMessage[] | string, options?: GenerateOptions): Promise<string>;
|
|
33
|
-
/**
|
|
34
|
-
* Generate with streaming output
|
|
35
|
-
*/
|
|
36
|
-
stream(messages: ChatMessage[] | string, onToken: StreamCallback, options?: GenerateOptions): Promise<string>;
|
|
37
|
-
/**
|
|
38
|
-
* Attach to input/output elements for automatic generation
|
|
39
|
-
*/
|
|
40
|
-
attachToInput(inputSelector: string | HTMLInputElement | HTMLTextAreaElement, outputSelector: string | HTMLElement, options?: AttachOptions): () => void;
|
|
41
|
-
/**
|
|
42
|
-
* Unload the model and free resources
|
|
43
|
-
*/
|
|
44
|
-
unload(): Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a LocalLLM instance
|
|
48
|
-
*
|
|
49
|
-
* @param config - Configuration options
|
|
50
|
-
* @returns Promise that resolves to a LocalLLM instance once the model is loaded
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* // Simple usage with defaults
|
|
55
|
-
* const llm = await createLLM();
|
|
56
|
-
*
|
|
57
|
-
* // With configuration
|
|
58
|
-
* const llm = await createLLM({
|
|
59
|
-
* model: 'phi-3-mini',
|
|
60
|
-
* backend: 'webllm',
|
|
61
|
-
* systemPrompt: 'You are a helpful assistant.',
|
|
62
|
-
* onLoadProgress: (p) => console.log(p.progress)
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare function createLLM(config?: LLMConfig): Promise<LocalLLM>;
|
|
67
|
-
/**
|
|
68
|
-
* Quick helper to test if the current browser supports WebGPU
|
|
69
|
-
*/
|
|
70
|
-
export declare function isWebGPUSupported(): Promise<boolean>;
|
|
71
|
-
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,OAAO,EACP,MAAM,EACN,YAAY,EACZ,SAAS,EACT,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAA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Aa,GACtB,MAAM,IAAI,CAAC;IAEd;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAwBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,SAAS,CAAC,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAyFzE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAG1D"}
|
package/dist/detect.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser capability detection utilities
|
|
3
|
-
*/
|
|
4
|
-
import type { BrowserCapabilities } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* Check if WebGPU is available in the current browser
|
|
7
|
-
*/
|
|
8
|
-
export declare function checkWebGPU(): Promise<boolean>;
|
|
9
|
-
/**
|
|
10
|
-
* Check if WebAssembly is available
|
|
11
|
-
*/
|
|
12
|
-
export declare function checkWasm(): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Detect browser capabilities and recommend backend/device
|
|
15
|
-
*/
|
|
16
|
-
export declare function detectCapabilities(): Promise<BrowserCapabilities>;
|
|
17
|
-
/**
|
|
18
|
-
* Log capability detection results to console
|
|
19
|
-
*/
|
|
20
|
-
export declare function logCapabilities(): Promise<BrowserCapabilities>;
|
|
21
|
-
//# sourceMappingURL=detect.d.ts.map
|
package/dist/detect.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAmB,MAAM,SAAS,CAAC;AAEpE;;GAEG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAapD;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAYnC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAuBvE;AAED;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAUpE"}
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOM Helper Utilities
|
|
3
|
-
* Easy integration with HTML input/output elements
|
|
4
|
-
*/
|
|
5
|
-
import type { StreamCallback, AttachOptions } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Creates a streaming callback that updates an output element
|
|
8
|
-
*/
|
|
9
|
-
export declare function createOutputStreamer(outputSelector: string | HTMLElement, options?: {
|
|
10
|
-
append?: boolean;
|
|
11
|
-
scrollToBottom?: boolean;
|
|
12
|
-
}): StreamCallback;
|
|
13
|
-
/**
|
|
14
|
-
* Attach LLM to input/output elements with automatic handling
|
|
15
|
-
*/
|
|
16
|
-
export declare function attachToElements(inputSelector: string | HTMLInputElement | HTMLTextAreaElement, outputSelector: string | HTMLElement, generateFn: (input: string, onToken: StreamCallback) => Promise<string>, options?: AttachOptions): () => void;
|
|
17
|
-
/**
|
|
18
|
-
* Create a simple chat UI in a container
|
|
19
|
-
*/
|
|
20
|
-
export declare function createChatUI(containerSelector: string | HTMLElement): {
|
|
21
|
-
input: HTMLTextAreaElement;
|
|
22
|
-
output: HTMLDivElement;
|
|
23
|
-
sendButton: HTMLButtonElement;
|
|
24
|
-
cleanup: () => void;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Create a loading indicator
|
|
28
|
-
*/
|
|
29
|
-
export declare function createLoadingIndicator(containerSelector: string | HTMLElement): {
|
|
30
|
-
show: () => void;
|
|
31
|
-
hide: () => void;
|
|
32
|
-
setProgress: (percent: number, status?: string) => void;
|
|
33
|
-
element: HTMLDivElement;
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/helpers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7D;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,MAAM,GAAG,WAAW,EACpC,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GACA,cAAc,CAoBhB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,GAAG,gBAAgB,GAAG,mBAAmB,EAC9D,cAAc,EAAE,MAAM,GAAG,WAAW,EACpC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,EACvE,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,IAAI,CA8DZ;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,iBAAiB,EAAE,MAAM,GAAG,WAAW,GAAG;IACrE,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,cAAc,CAAC;IACvB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAyBA;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,iBAAiB,EAAE,MAAM,GAAG,WAAW,GAAG;IAC/E,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,OAAO,EAAE,cAAc,CAAC;CACzB,CAwCA"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local LLM - Browser-based LLM inference library
|
|
3
|
-
*
|
|
4
|
-
* A simple, generalized library for interacting with LLMs directly in the browser.
|
|
5
|
-
* Works in any codebase with WebGPU or WASM support.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { createLLM } from '@blank-utils/llm';
|
|
10
|
-
*
|
|
11
|
-
* const llm = await createLLM({
|
|
12
|
-
* onLoadProgress: (p) => console.log(`Loading: ${p.progress}%`)
|
|
13
|
-
* });
|
|
14
|
-
*
|
|
15
|
-
* // Streaming generation
|
|
16
|
-
* await llm.stream('Tell me a joke', (token) => console.log(token));
|
|
17
|
-
*
|
|
18
|
-
* // Attach to DOM elements
|
|
19
|
-
* llm.attachToInput('#input', '#output');
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @module @blank-utils/llm
|
|
23
|
-
*/
|
|
24
|
-
export { type Backend, type Device, type Quantization, type LLMConfig, type MessageRole, type ChatMessage, type StreamCallback, type LoadProgress, type LoadProgressCallback, type GenerateOptions, type LLMProviderInterface, type AttachOptions, type BrowserCapabilities, checkWebGPU, checkWasm, detectCapabilities, logCapabilities, WebLLMProvider, createWebLLMProvider, DEFAULT_WEBLLM_MODEL, WEBLLM_MODELS, TransformersProvider, createTransformersProvider, DEFAULT_TRANSFORMERS_MODEL, TRANSFORMERS_MODELS, createOutputStreamer, attachToElements, createChatUI, createLoadingIndicator, type LocalLLM, createLLM, isWebGPUSupported, } from './core';
|
|
25
|
-
export { createLLM as default } from './core';
|
|
26
|
-
export { LLMProvider, useLLM, useChat, useStream, useCompletion, LLMLoading, LLMReady, type LLMContextValue, type LLMProviderProps, type UseChatOptions, type UseChatReturn, type UseStreamOptions, type UseStreamReturn, type UseCompletionOptions, type UseCompletionReturn, type LLMLoadingProps, type LLMReadyProps, } from './react';
|
|
27
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAGxB,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,eAAe,EAGf,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,mBAAmB,EAGnB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EAGtB,KAAK,QAAQ,EACb,SAAS,EACT,iBAAiB,GAClB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,QAAQ,CAAC;AAQ9C,OAAO,EAEL,WAAW,EACX,MAAM,EAGN,OAAO,EACP,SAAS,EACT,aAAa,EAGb,UAAU,EACV,QAAQ,EAGR,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,SAAS,CAAC"}
|
package/dist/react/index.d.ts
DELETED
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React Integration for Local LLM
|
|
3
|
-
*
|
|
4
|
-
* Provides React context, hooks, and components for easy LLM integration.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* import { LLMProvider, useChat } from 'local-llm/react';
|
|
9
|
-
*
|
|
10
|
-
* function App() {
|
|
11
|
-
* return (
|
|
12
|
-
* <LLMProvider model="qwen-2.5-0.5b">
|
|
13
|
-
* <ChatComponent />
|
|
14
|
-
* </LLMProvider>
|
|
15
|
-
* );
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* function ChatComponent() {
|
|
19
|
-
* const { messages, send, isGenerating } = useChat();
|
|
20
|
-
*
|
|
21
|
-
* return (
|
|
22
|
-
* <div>
|
|
23
|
-
* {messages.map((m, i) => <p key={i}>{m.content}</p>)}
|
|
24
|
-
* <button onClick={() => send('Hello!')}>Send</button>
|
|
25
|
-
* </div>
|
|
26
|
-
* );
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
import * as React from 'react';
|
|
31
|
-
import type { LLMConfig, ChatMessage, GenerateOptions, LoadProgress, Backend } from '../types';
|
|
32
|
-
import { type LocalLLM } from '../core';
|
|
33
|
-
export interface LLMContextValue {
|
|
34
|
-
/** The LLM instance (null while loading) */
|
|
35
|
-
llm: LocalLLM | null;
|
|
36
|
-
/** Whether the model is currently loading */
|
|
37
|
-
isLoading: boolean;
|
|
38
|
-
/** Whether the model is ready for inference */
|
|
39
|
-
isReady: boolean;
|
|
40
|
-
/** Current loading progress */
|
|
41
|
-
loadProgress: LoadProgress | null;
|
|
42
|
-
/** Error if loading failed */
|
|
43
|
-
error: Error | null;
|
|
44
|
-
/** Current model ID */
|
|
45
|
-
modelId: string | null;
|
|
46
|
-
/** Backend being used */
|
|
47
|
-
backend: Backend | null;
|
|
48
|
-
/** Manually reload the model */
|
|
49
|
-
reload: () => Promise<void>;
|
|
50
|
-
/** Unload the model */
|
|
51
|
-
unload: () => Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
export interface LLMProviderProps extends Omit<LLMConfig, 'onLoadProgress'> {
|
|
54
|
-
children: React.ReactNode;
|
|
55
|
-
/**
|
|
56
|
-
* Auto-load the model on mount
|
|
57
|
-
* @default true
|
|
58
|
-
*/
|
|
59
|
-
autoLoad?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Callback when model finishes loading
|
|
62
|
-
*/
|
|
63
|
-
onLoad?: (llm: LocalLLM) => void;
|
|
64
|
-
/**
|
|
65
|
-
* Callback on loading progress
|
|
66
|
-
*/
|
|
67
|
-
onProgress?: (progress: LoadProgress) => void;
|
|
68
|
-
/**
|
|
69
|
-
* Callback on error
|
|
70
|
-
*/
|
|
71
|
-
onError?: (error: Error) => void;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Provider component that manages LLM lifecycle
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```tsx
|
|
78
|
-
* <LLMProvider
|
|
79
|
-
* model="qwen-2.5-0.5b"
|
|
80
|
-
* backend="auto"
|
|
81
|
-
* onProgress={(p) => console.log(p.progress)}
|
|
82
|
-
* >
|
|
83
|
-
* <App />
|
|
84
|
-
* </LLMProvider>
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
declare function LLMProvider({ children, autoLoad, onLoad, onProgress, onError, ...config }: LLMProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
88
|
-
/**
|
|
89
|
-
* Access the LLM context
|
|
90
|
-
*
|
|
91
|
-
* @throws If used outside of LLMProvider
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```tsx
|
|
95
|
-
* const { llm, isReady, loadProgress } = useLLM();
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
declare function useLLM(): LLMContextValue;
|
|
99
|
-
export interface UseChatOptions {
|
|
100
|
-
/** Initial messages */
|
|
101
|
-
initialMessages?: ChatMessage[];
|
|
102
|
-
/** System prompt */
|
|
103
|
-
systemPrompt?: string;
|
|
104
|
-
/** Generation options */
|
|
105
|
-
generateOptions?: GenerateOptions;
|
|
106
|
-
/**
|
|
107
|
-
* Queue messages while model is loading
|
|
108
|
-
* When true, users can send messages before model loads - they'll be processed once ready
|
|
109
|
-
* @default true
|
|
110
|
-
*/
|
|
111
|
-
queueWhileLoading?: boolean;
|
|
112
|
-
/** Called when generation starts */
|
|
113
|
-
onStart?: () => void;
|
|
114
|
-
/** Called on each token (streaming) */
|
|
115
|
-
onToken?: (token: string, fullText: string) => void;
|
|
116
|
-
/** Called when generation completes */
|
|
117
|
-
onFinish?: (response: string) => void;
|
|
118
|
-
/** Called on error */
|
|
119
|
-
onError?: (error: Error) => void;
|
|
120
|
-
}
|
|
121
|
-
export interface UseChatReturn {
|
|
122
|
-
/** All messages in the conversation */
|
|
123
|
-
messages: ChatMessage[];
|
|
124
|
-
/** Current input value (for controlled input) */
|
|
125
|
-
input: string;
|
|
126
|
-
/** Set the input value */
|
|
127
|
-
setInput: (input: string) => void;
|
|
128
|
-
/** Whether currently generating a response */
|
|
129
|
-
isGenerating: boolean;
|
|
130
|
-
/** Whether a message is queued waiting for model to load */
|
|
131
|
-
isPending: boolean;
|
|
132
|
-
/** Current streaming text (while generating) */
|
|
133
|
-
streamingText: string;
|
|
134
|
-
/** Send a message and get a response */
|
|
135
|
-
send: (content?: string) => Promise<string>;
|
|
136
|
-
/** Stop the current generation */
|
|
137
|
-
stop: () => void;
|
|
138
|
-
/** Clear all messages */
|
|
139
|
-
clear: () => void;
|
|
140
|
-
/** Add a message without generating a response */
|
|
141
|
-
append: (message: ChatMessage) => void;
|
|
142
|
-
/** Reload/regenerate the last assistant message */
|
|
143
|
-
reload: () => Promise<string>;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Hook for managing a chat conversation with the LLM
|
|
147
|
-
*
|
|
148
|
-
* Supports **eager loading** - users can send messages while the model loads.
|
|
149
|
-
* Messages are queued and processed automatically once the model is ready.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```tsx
|
|
153
|
-
* function ChatComponent() {
|
|
154
|
-
* const { isLoading, loadProgress } = useLLM();
|
|
155
|
-
* const {
|
|
156
|
-
* messages,
|
|
157
|
-
* input,
|
|
158
|
-
* setInput,
|
|
159
|
-
* send,
|
|
160
|
-
* isGenerating,
|
|
161
|
-
* isPending, // true if message is queued waiting for model
|
|
162
|
-
* streamingText,
|
|
163
|
-
* } = useChat({
|
|
164
|
-
* systemPrompt: 'You are a helpful assistant.',
|
|
165
|
-
* queueWhileLoading: true, // default: true
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* return (
|
|
169
|
-
* <div>
|
|
170
|
-
* {isLoading && <p>Loading model... {loadProgress?.progress}%</p>}
|
|
171
|
-
*
|
|
172
|
-
* {messages.map((m, i) => (
|
|
173
|
-
* <div key={i} className={m.role}>
|
|
174
|
-
* {m.content}
|
|
175
|
-
* </div>
|
|
176
|
-
* ))}
|
|
177
|
-
*
|
|
178
|
-
* {isPending && <p className="pending">Waiting for model to load...</p>}
|
|
179
|
-
* {isGenerating && <div className="assistant">{streamingText}</div>}
|
|
180
|
-
*
|
|
181
|
-
* {/* Users can type immediately, even before model loads *\/}
|
|
182
|
-
* <input
|
|
183
|
-
* value={input}
|
|
184
|
-
* onChange={(e) => setInput(e.target.value)}
|
|
185
|
-
* onKeyDown={(e) => e.key === 'Enter' && send()}
|
|
186
|
-
* placeholder={isLoading ? 'Type now, send when ready...' : 'Type a message...'}
|
|
187
|
-
* />
|
|
188
|
-
* <button onClick={() => send()} disabled={isGenerating}>
|
|
189
|
-
* {isPending ? 'Queued...' : 'Send'}
|
|
190
|
-
* </button>
|
|
191
|
-
* </div>
|
|
192
|
-
* );
|
|
193
|
-
* }
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
declare function useChat(options?: UseChatOptions): UseChatReturn;
|
|
197
|
-
export interface UseStreamOptions {
|
|
198
|
-
/** Generation options */
|
|
199
|
-
generateOptions?: GenerateOptions;
|
|
200
|
-
/** Called on each token */
|
|
201
|
-
onToken?: (token: string, fullText: string) => void;
|
|
202
|
-
/** Called when complete */
|
|
203
|
-
onFinish?: (response: string) => void;
|
|
204
|
-
/** Called on error */
|
|
205
|
-
onError?: (error: Error) => void;
|
|
206
|
-
}
|
|
207
|
-
export interface UseStreamReturn {
|
|
208
|
-
/** Current streamed text */
|
|
209
|
-
text: string;
|
|
210
|
-
/** Whether currently streaming */
|
|
211
|
-
isStreaming: boolean;
|
|
212
|
-
/** Start streaming a response */
|
|
213
|
-
stream: (messages: ChatMessage[] | string) => Promise<string>;
|
|
214
|
-
/** Stop streaming */
|
|
215
|
-
stop: () => void;
|
|
216
|
-
/** Clear the text */
|
|
217
|
-
clear: () => void;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Hook for simple streaming generation
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```tsx
|
|
224
|
-
* function StreamComponent() {
|
|
225
|
-
* const { text, isStreaming, stream, clear } = useStream();
|
|
226
|
-
*
|
|
227
|
-
* return (
|
|
228
|
-
* <div>
|
|
229
|
-
* <pre>{text}</pre>
|
|
230
|
-
* <button onClick={() => stream('Tell me a story')} disabled={isStreaming}>
|
|
231
|
-
* Generate
|
|
232
|
-
* </button>
|
|
233
|
-
* <button onClick={clear}>Clear</button>
|
|
234
|
-
* </div>
|
|
235
|
-
* );
|
|
236
|
-
* }
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
declare function useStream(options?: UseStreamOptions): UseStreamReturn;
|
|
240
|
-
export interface UseCompletionOptions {
|
|
241
|
-
/** Generation options */
|
|
242
|
-
generateOptions?: GenerateOptions;
|
|
243
|
-
}
|
|
244
|
-
export interface UseCompletionReturn {
|
|
245
|
-
/** Current completion text */
|
|
246
|
-
completion: string;
|
|
247
|
-
/** Whether currently generating */
|
|
248
|
-
isLoading: boolean;
|
|
249
|
-
/** Generate a completion (non-streaming) */
|
|
250
|
-
complete: (prompt: string) => Promise<string>;
|
|
251
|
-
/** Clear the completion */
|
|
252
|
-
clear: () => void;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Hook for simple non-streaming completion
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```tsx
|
|
259
|
-
* function CompletionComponent() {
|
|
260
|
-
* const { completion, isLoading, complete } = useCompletion();
|
|
261
|
-
*
|
|
262
|
-
* return (
|
|
263
|
-
* <div>
|
|
264
|
-
* <p>{completion}</p>
|
|
265
|
-
* <button onClick={() => complete('Summarize this')} disabled={isLoading}>
|
|
266
|
-
* Complete
|
|
267
|
-
* </button>
|
|
268
|
-
* </div>
|
|
269
|
-
* );
|
|
270
|
-
* }
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
declare function useCompletion(options?: UseCompletionOptions): UseCompletionReturn;
|
|
274
|
-
export interface LLMLoadingProps {
|
|
275
|
-
/** Custom loading UI */
|
|
276
|
-
children?: React.ReactNode;
|
|
277
|
-
/** Class name for the wrapper */
|
|
278
|
-
className?: string;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Component that shows loading state while LLM is loading
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```tsx
|
|
285
|
-
* <LLMLoading>
|
|
286
|
-
* <p>Loading model...</p>
|
|
287
|
-
* </LLMLoading>
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
declare function LLMLoading({ children, className }: LLMLoadingProps): import("react/jsx-runtime").JSX.Element | null;
|
|
291
|
-
export interface LLMReadyProps {
|
|
292
|
-
/** Content to show when ready */
|
|
293
|
-
children: React.ReactNode;
|
|
294
|
-
/** Content to show while loading */
|
|
295
|
-
fallback?: React.ReactNode;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Component that only renders children when LLM is ready
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```tsx
|
|
302
|
-
* <LLMReady fallback={<Loading />}>
|
|
303
|
-
* <ChatInterface />
|
|
304
|
-
* </LLMReady>
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
declare function LLMReady({ children, fallback }: LLMReadyProps): import("react/jsx-runtime").JSX.Element;
|
|
308
|
-
export { LLMProvider, useLLM, useChat, useStream, useCompletion, LLMLoading, LLMReady, };
|
|
309
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAW/B,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,eAAe,EACf,YAAY,EACZ,OAAO,EACR,MAAM,UAAU,CAAC;AAElB,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQnD,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAC;IAErB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAC;IAEnB,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IAEjB,+BAA+B;IAC/B,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAElC,8BAA8B;IAC9B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,uBAAuB;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,yBAAyB;IACzB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAExB,gCAAgC;IAChC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,uBAAuB;IACvB,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAQD,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACzE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,CAAC;IAEjC;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