webslm-react 0.5.0 → 0.6.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 CHANGED
@@ -93,7 +93,7 @@ export function Chat() {
93
93
 
94
94
  - `useLLM(model, options)` returns `{ llm, ask, stream, chat, status, progress, error }` (see above).
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
- - `useChat(model, options)` returns `{ messages, send, stop, clear, setMessages, isGenerating, streamingText, lastResult, error }`. Options are webslm's generation options plus `system`, `initialMessages`, `onFinish` and `onError`.
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
  - `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.
98
98
  - `useCapabilities()` reports WebGPU, SIMD, threads and cross-origin isolation.
99
99
 
package/dist/index.d.ts CHANGED
@@ -13,4 +13,4 @@ export { useChat, type UseChatOptions, type UseChatResult } from "./use-chat.js"
13
13
  export { useLLM, type UseLLMAsk, type UseLLMResult } from "./use-llm.js";
14
14
  export { useModel, type ModelStatus, type UseModelOptions, type UseModelResult, } from "./use-model.js";
15
15
  export { useModelSearch, type UseModelSearchOptions, type UseModelSearchResult, } from "./use-model-search.js";
16
- export type { Answer, AskOptions, Capabilities, Chat, ChatOptions, ChatMessage, GenerationResult, HubModel, LLM, LoadProgress, Model, ModelInfo, ModelSource, PromptOptions, TextStream, WebslmError, } from "webslm";
16
+ export type { Answer, AskOptions, Capabilities, Chat, ChatOptions, ChatMessage, MediaPart, GenerationResult, HubModel, LLM, LoadProgress, Model, ModelInfo, ModelSource, PromptOptions, TextStream, WebslmError, } from "webslm";
@@ -1,4 +1,4 @@
1
- import { WebslmError, type ChatMessage, type GenerateOptions, type GenerationResult, type Model } from "webslm";
1
+ import { WebslmError, type ChatMessage, type GenerateOptions, type GenerationResult, type MediaPart, type Model } from "webslm";
2
2
  export interface UseChatOptions extends Omit<GenerateOptions, "signal"> {
3
3
  /** System prompt prepended to every request (not shown in `messages`). */
4
4
  readonly system?: string;
@@ -11,8 +11,12 @@ export interface UseChatOptions extends Omit<GenerateOptions, "signal"> {
11
11
  export interface UseChatResult {
12
12
  /** The conversation so far, without the answer being streamed. */
13
13
  readonly messages: readonly ChatMessage[];
14
- /** Sends a user message and streams the answer. Ignored while generating. */
15
- send(content: string): void;
14
+ /**
15
+ * Sends a user message and streams the answer. Ignored while generating.
16
+ * `media` sends images and videos with it to vision-language models (kept
17
+ * in the message's `media`).
18
+ */
19
+ send(content: string, media?: readonly MediaPart[]): void;
16
20
  /** Stops the current answer; the text so far is kept as the assistant message. */
17
21
  stop(): void;
18
22
  /** Starts a new conversation. */
package/dist/use-chat.js CHANGED
@@ -33,12 +33,12 @@ export function useChat(model, options = {}) {
33
33
  setStreamingText("");
34
34
  };
35
35
  }, [model]);
36
- const send = useCallback((content) => {
36
+ const send = useCallback((content, media) => {
37
37
  if (model === undefined || streamRef.current !== undefined)
38
38
  return;
39
39
  const { system, initialMessages, onFinish, onError, ...generate } = optionsRef.current;
40
40
  void initialMessages;
41
- const user = { role: "user", content };
41
+ const user = media === undefined || media.length === 0 ? { role: "user", content } : { role: "user", content, media };
42
42
  const history = [...messagesRef.current, user];
43
43
  messagesRef.current = history;
44
44
  setMessagesState(history);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webslm-react",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.5.0"
41
+ "webslm": "^0.6.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.5.0"
54
+ "webslm": "^0.6.0"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",