webslm-react 0.9.0 → 0.10.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.
- package/README.md +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/use-transcription.d.ts +24 -0
- package/dist/use-transcription.js +25 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -95,6 +95,7 @@ export function Chat() {
|
|
|
95
95
|
- `useModel(source, options)` returns `{ model, status, progress, error }` with `status` one of `"idle" | "loading" | "ready" | "error"`. It loads when the source (a hub repo id or a `ModelSource`) or a load option changes, and unloads the previous model and on unmount. Pass `null` to load nothing.
|
|
96
96
|
- `useChat(model, options)` returns `{ messages, send, stop, clear, setMessages, isGenerating, streamingText, lastResult, error }`. `send(text, media?)` sends images and videos (`[{ type: "image", image: file }]`) to vision-language models; each message's `content` is its text and `media` its images and videos. Options are webslm's generation options plus `system`, `initialMessages`, `onFinish` and `onError`.
|
|
97
97
|
- `useEmbeddings(source, options)` loads an encoder (an embedding model: `sentence-transformers/all-MiniLM-L6-v2`, `minishlab/potion-base-2M`...) and returns `{ model, embed, status, progress, error }`; `embed(texts, { pooling, normalize })` is the model's `embed`, callable while it loads (it waits): `const { vectors } = await embed(["A cat sleeps.", "A kitten naps."])`.
|
|
98
|
+
- `useTranscription(source, options)` loads a speech recognition model (Whisper: `openai/whisper-tiny`...) and returns `{ model, transcribe, status, progress, error }`; `transcribe(audio, { language, task, onToken, signal })` is the model's `transcribe`, callable while it loads (it waits): `const { text } = await transcribe(recordedBlob)`.
|
|
98
99
|
- `useModelSearch(query, options)` returns `{ results, status, error }`, searching the Hub as the query changes (debounced, stale requests cancelled). Each result says whether webslm can run it, whether it is gated, and its size.
|
|
99
100
|
- `useCapabilities()` reports WebGPU, SIMD, threads and cross-origin isolation.
|
|
100
101
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React bindings for webslm: load a model, ask it, chat with it, embed texts
|
|
3
|
-
* with an encoder and search the Hugging
|
|
3
|
+
* with an encoder, transcribe speech with Whisper and search the Hugging
|
|
4
|
+
* Face Hub from components.
|
|
4
5
|
*
|
|
5
6
|
* ```tsx
|
|
6
7
|
* const { ask, status } = useLLM();
|
|
@@ -10,8 +11,9 @@
|
|
|
10
11
|
*/
|
|
11
12
|
export { useCapabilities } from "./use-capabilities.js";
|
|
12
13
|
export { useEmbeddings, type UseEmbeddingsResult } from "./use-embeddings.js";
|
|
14
|
+
export { useTranscription, type UseTranscriptionResult } from "./use-transcription.js";
|
|
13
15
|
export { useChat, type UseChatOptions, type UseChatResult } from "./use-chat.js";
|
|
14
16
|
export { useLLM, type UseLLMAsk, type UseLLMResult } from "./use-llm.js";
|
|
15
17
|
export { useModel, type ModelStatus, type UseModelOptions, type UseModelResult, } from "./use-model.js";
|
|
16
18
|
export { useModelSearch, type UseModelSearchOptions, type UseModelSearchResult, } from "./use-model-search.js";
|
|
17
|
-
export type { Answer, AskOptions, Capabilities, Chat, ChatOptions, ChatMessage, MediaPart, EmbedOptions, Embeddings, GenerationResult, HubModel, LLM, LoadProgress, Model, ModelInfo, ModelSource, PromptOptions, TextStream, WebslmError, } from "webslm";
|
|
19
|
+
export type { Answer, AskOptions, AudioInput, Capabilities, Chat, ChatOptions, ChatMessage, MediaPart, EmbedOptions, Embeddings, GenerationResult, HubModel, LLM, LoadProgress, Model, ModelInfo, ModelSource, PromptOptions, TextStream, TranscribeOptions, Transcription, WebslmError, } from "webslm";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React bindings for webslm: load a model, ask it, chat with it, embed texts
|
|
3
|
-
* with an encoder and search the Hugging
|
|
3
|
+
* with an encoder, transcribe speech with Whisper and search the Hugging
|
|
4
|
+
* Face Hub from components.
|
|
4
5
|
*
|
|
5
6
|
* ```tsx
|
|
6
7
|
* const { ask, status } = useLLM();
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
*/
|
|
11
12
|
export { useCapabilities } from "./use-capabilities.js";
|
|
12
13
|
export { useEmbeddings } from "./use-embeddings.js";
|
|
14
|
+
export { useTranscription } from "./use-transcription.js";
|
|
13
15
|
export { useChat } from "./use-chat.js";
|
|
14
16
|
export { useLLM } from "./use-llm.js";
|
|
15
17
|
export { useModel, } from "./use-model.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WebslmError, type AudioInput, type LoadProgress, type Model, type ModelSource, type TranscribeOptions, type Transcription } from "webslm";
|
|
2
|
+
import { type ModelStatus, type UseModelOptions } from "./use-load.js";
|
|
3
|
+
export interface UseTranscriptionResult {
|
|
4
|
+
/** The loaded speech recognition model, once `status` is `"ready"`. */
|
|
5
|
+
readonly model: Model | undefined;
|
|
6
|
+
readonly status: ModelStatus;
|
|
7
|
+
/** Latest progress event of the current load. */
|
|
8
|
+
readonly progress: LoadProgress | undefined;
|
|
9
|
+
readonly error: WebslmError | undefined;
|
|
10
|
+
/** Transcribes audio (see `Model.transcribe`). Callable during the load: it waits for the model. */
|
|
11
|
+
readonly transcribe: (audio: AudioInput, options?: TranscribeOptions) => Promise<Transcription>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Loads a speech recognition model (Whisper) and gives a `transcribe`
|
|
15
|
+
* function that can be called right away: it waits for the load. Pass
|
|
16
|
+
* `null` to load nothing. The model is unloaded when the source or a load
|
|
17
|
+
* option changes and on unmount.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { transcribe, status } = useTranscription("openai/whisper-tiny");
|
|
21
|
+
* const { text } = await transcribe(recordedBlob, { onToken: (t) => setDraft((d) => d + t) });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useTranscription(source: string | ModelSource | null | undefined, options?: UseModelOptions): UseTranscriptionResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { loadModel, WebslmError, } from "webslm";
|
|
3
|
+
import { useLoad } from "./use-load.js";
|
|
4
|
+
/**
|
|
5
|
+
* Loads a speech recognition model (Whisper) and gives a `transcribe`
|
|
6
|
+
* function that can be called right away: it waits for the load. Pass
|
|
7
|
+
* `null` to load nothing. The model is unloaded when the source or a load
|
|
8
|
+
* option changes and on unmount.
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const { transcribe, status } = useTranscription("openai/whisper-tiny");
|
|
12
|
+
* const { text } = await transcribe(recordedBlob, { onToken: (t) => setDraft((d) => d + t) });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function useTranscription(source, options = {}) {
|
|
16
|
+
const { value, status, progress, error, pending } = useLoad(source, options, loadModel);
|
|
17
|
+
const transcribe = useCallback((audio, transcribeOptions) => {
|
|
18
|
+
const current = pending.current;
|
|
19
|
+
if (current === undefined) {
|
|
20
|
+
return Promise.reject(new WebslmError("INVALID_STATE", "no model is loaded or loading"));
|
|
21
|
+
}
|
|
22
|
+
return current.then((model) => model.transcribe(audio, transcribeOptions));
|
|
23
|
+
}, [pending]);
|
|
24
|
+
return { model: value, status, progress, error, transcribe };
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webslm-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "React hooks for webslm: load small language models in the browser, chat with them and search the Hugging Face Hub.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Maxime Golfier",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": ">=18",
|
|
41
|
-
"webslm": "^0.
|
|
41
|
+
"webslm": "^0.10.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@testing-library/dom": "^10.4.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"react-dom": "^19.3.1",
|
|
52
52
|
"typescript": "^7.0.2",
|
|
53
53
|
"vitest": "^5.1.2",
|
|
54
|
-
"webslm": "^0.
|
|
54
|
+
"webslm": "^0.10.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|