@jupyterlite/ai 0.6.2 → 0.8.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.
Files changed (87) hide show
  1. package/README.md +1 -1
  2. package/lib/base-completer.d.ts +22 -5
  3. package/lib/base-completer.js +14 -1
  4. package/lib/chat-handler.d.ts +23 -11
  5. package/lib/chat-handler.js +66 -45
  6. package/lib/completion-provider.d.ts +2 -2
  7. package/lib/completion-provider.js +5 -4
  8. package/lib/components/stop-button.d.ts +0 -1
  9. package/lib/default-prompts.d.ts +2 -0
  10. package/lib/default-prompts.js +31 -0
  11. package/lib/default-providers/Anthropic/completer.d.ts +4 -11
  12. package/lib/default-providers/Anthropic/completer.js +5 -16
  13. package/lib/default-providers/ChromeAI/completer.d.ts +4 -11
  14. package/lib/default-providers/ChromeAI/completer.js +5 -16
  15. package/lib/default-providers/ChromeAI/instructions.d.ts +4 -0
  16. package/lib/default-providers/ChromeAI/instructions.js +18 -0
  17. package/lib/default-providers/ChromeAI/settings-schema.json +0 -3
  18. package/lib/default-providers/Gemini/completer.d.ts +12 -0
  19. package/lib/default-providers/Gemini/completer.js +48 -0
  20. package/lib/default-providers/Gemini/instructions.d.ts +2 -0
  21. package/lib/default-providers/Gemini/instructions.js +9 -0
  22. package/lib/default-providers/Gemini/settings-schema.json +64 -0
  23. package/lib/default-providers/MistralAI/completer.d.ts +10 -13
  24. package/lib/default-providers/MistralAI/completer.js +42 -52
  25. package/lib/default-providers/MistralAI/instructions.d.ts +1 -1
  26. package/lib/default-providers/MistralAI/instructions.js +2 -0
  27. package/lib/default-providers/Ollama/completer.d.ts +12 -0
  28. package/lib/default-providers/Ollama/completer.js +43 -0
  29. package/lib/default-providers/Ollama/instructions.d.ts +2 -0
  30. package/lib/default-providers/Ollama/instructions.js +70 -0
  31. package/lib/default-providers/Ollama/settings-schema.json +143 -0
  32. package/lib/default-providers/OpenAI/completer.d.ts +4 -11
  33. package/lib/default-providers/OpenAI/completer.js +8 -16
  34. package/lib/default-providers/OpenAI/settings-schema.json +88 -128
  35. package/lib/default-providers/WebLLM/completer.d.ts +21 -0
  36. package/lib/default-providers/WebLLM/completer.js +127 -0
  37. package/lib/default-providers/WebLLM/instructions.d.ts +6 -0
  38. package/lib/default-providers/WebLLM/instructions.js +32 -0
  39. package/lib/default-providers/WebLLM/settings-schema.json +19 -0
  40. package/lib/default-providers/index.js +127 -8
  41. package/lib/index.d.ts +3 -2
  42. package/lib/index.js +80 -36
  43. package/lib/provider.d.ts +48 -22
  44. package/lib/provider.js +254 -101
  45. package/lib/settings/index.d.ts +1 -1
  46. package/lib/settings/index.js +1 -1
  47. package/lib/settings/panel.d.ts +151 -14
  48. package/lib/settings/panel.js +334 -145
  49. package/lib/settings/textarea.d.ts +2 -0
  50. package/lib/settings/textarea.js +18 -0
  51. package/lib/tokens.d.ts +45 -22
  52. package/lib/tokens.js +2 -1
  53. package/lib/types/ai-model.d.ts +24 -0
  54. package/lib/types/ai-model.js +5 -0
  55. package/package.json +19 -15
  56. package/schema/chat.json +1 -1
  57. package/schema/provider-registry.json +8 -8
  58. package/schema/system-prompts.json +22 -0
  59. package/src/base-completer.ts +38 -6
  60. package/src/chat-handler.ts +62 -31
  61. package/src/completion-provider.ts +3 -3
  62. package/src/default-prompts.ts +33 -0
  63. package/src/default-providers/Anthropic/completer.ts +5 -21
  64. package/src/default-providers/ChromeAI/completer.ts +5 -21
  65. package/src/default-providers/ChromeAI/instructions.ts +21 -0
  66. package/src/default-providers/Gemini/completer.ts +61 -0
  67. package/src/default-providers/Gemini/instructions.ts +9 -0
  68. package/src/default-providers/MistralAI/completer.ts +47 -65
  69. package/src/default-providers/MistralAI/instructions.ts +2 -0
  70. package/src/default-providers/Ollama/completer.ts +54 -0
  71. package/src/default-providers/Ollama/instructions.ts +70 -0
  72. package/src/default-providers/OpenAI/completer.ts +8 -21
  73. package/src/default-providers/WebLLM/completer.ts +151 -0
  74. package/src/default-providers/WebLLM/instructions.ts +33 -0
  75. package/src/default-providers/index.ts +158 -18
  76. package/src/index.ts +108 -40
  77. package/src/provider.ts +300 -109
  78. package/src/settings/index.ts +1 -1
  79. package/src/settings/panel.tsx +463 -101
  80. package/src/settings/textarea.tsx +33 -0
  81. package/src/tokens.ts +49 -24
  82. package/src/types/ai-model.ts +37 -0
  83. package/src/types/service-worker.d.ts +6 -0
  84. package/style/base.css +34 -0
  85. package/lib/settings/settings-connector.d.ts +0 -31
  86. package/lib/settings/settings-connector.js +0 -61
  87. package/src/settings/settings-connector.ts +0 -88
@@ -42,10 +42,7 @@
42
42
  "description": "The type of the content part."
43
43
  }
44
44
  },
45
- "required": [
46
- "text",
47
- "type"
48
- ],
45
+ "required": ["text", "type"],
49
46
  "additionalProperties": false,
50
47
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
51
48
  }
@@ -63,10 +60,7 @@
63
60
  "description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
64
61
  }
65
62
  },
66
- "required": [
67
- "content",
68
- "role"
69
- ],
63
+ "required": ["content", "role"],
70
64
  "additionalProperties": false,
71
65
  "description": "Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, `developer` messages replace the previous `system` messages."
72
66
  },
@@ -93,10 +87,7 @@
93
87
  "description": "The type of the content part."
94
88
  }
95
89
  },
96
- "required": [
97
- "text",
98
- "type"
99
- ],
90
+ "required": ["text", "type"],
100
91
  "additionalProperties": false,
101
92
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
102
93
  }
@@ -114,10 +105,7 @@
114
105
  "description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
115
106
  }
116
107
  },
117
- "required": [
118
- "content",
119
- "role"
120
- ],
108
+ "required": ["content", "role"],
121
109
  "additionalProperties": false,
122
110
  "description": "Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use `developer` messages for this purpose instead."
123
111
  },
@@ -146,10 +134,7 @@
146
134
  "description": "The type of the content part."
147
135
  }
148
136
  },
149
- "required": [
150
- "text",
151
- "type"
152
- ],
137
+ "required": ["text", "type"],
153
138
  "additionalProperties": false,
154
139
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
155
140
  },
@@ -165,17 +150,11 @@
165
150
  },
166
151
  "detail": {
167
152
  "type": "string",
168
- "enum": [
169
- "auto",
170
- "low",
171
- "high"
172
- ],
153
+ "enum": ["auto", "low", "high"],
173
154
  "description": "Specifies the detail level of the image. Learn more in the [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding)."
174
155
  }
175
156
  },
176
- "required": [
177
- "url"
178
- ],
157
+ "required": ["url"],
179
158
  "additionalProperties": false
180
159
  },
181
160
  "type": {
@@ -184,10 +163,7 @@
184
163
  "description": "The type of the content part."
185
164
  }
186
165
  },
187
- "required": [
188
- "image_url",
189
- "type"
190
- ],
166
+ "required": ["image_url", "type"],
191
167
  "additionalProperties": false,
192
168
  "description": "Learn about [image inputs](https://platform.openai.com/docs/guides/vision)."
193
169
  },
@@ -203,17 +179,11 @@
203
179
  },
204
180
  "format": {
205
181
  "type": "string",
206
- "enum": [
207
- "wav",
208
- "mp3"
209
- ],
182
+ "enum": ["wav", "mp3"],
210
183
  "description": "The format of the encoded audio data. Currently supports \"wav\" and \"mp3\"."
211
184
  }
212
185
  },
213
- "required": [
214
- "data",
215
- "format"
216
- ],
186
+ "required": ["data", "format"],
217
187
  "additionalProperties": false
218
188
  },
219
189
  "type": {
@@ -222,12 +192,40 @@
222
192
  "description": "The type of the content part. Always `input_audio`."
223
193
  }
224
194
  },
225
- "required": [
226
- "input_audio",
227
- "type"
228
- ],
195
+ "required": ["input_audio", "type"],
229
196
  "additionalProperties": false,
230
197
  "description": "Learn about [audio inputs](https://platform.openai.com/docs/guides/audio)."
198
+ },
199
+ {
200
+ "type": "object",
201
+ "properties": {
202
+ "file": {
203
+ "type": "object",
204
+ "properties": {
205
+ "file_data": {
206
+ "type": "string",
207
+ "description": "The base64 encoded file data, used when passing the file to the model as a string."
208
+ },
209
+ "file_id": {
210
+ "type": "string",
211
+ "description": "The ID of an uploaded file to use as input."
212
+ },
213
+ "filename": {
214
+ "type": "string",
215
+ "description": "The name of the file, used when passing the file to the model as a string."
216
+ }
217
+ },
218
+ "additionalProperties": false
219
+ },
220
+ "type": {
221
+ "type": "string",
222
+ "const": "file",
223
+ "description": "The type of the content part. Always `file`."
224
+ }
225
+ },
226
+ "required": ["file", "type"],
227
+ "additionalProperties": false,
228
+ "description": "Learn about [file inputs](https://platform.openai.com/docs/guides/text) for text generation."
231
229
  }
232
230
  ],
233
231
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
@@ -246,10 +244,7 @@
246
244
  "description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
247
245
  }
248
246
  },
249
- "required": [
250
- "content",
251
- "role"
252
- ],
247
+ "required": ["content", "role"],
253
248
  "additionalProperties": false,
254
249
  "description": "Messages sent by an end user, containing prompts or additional context information."
255
250
  },
@@ -271,9 +266,7 @@
271
266
  "description": "Unique identifier for a previous audio response from the model."
272
267
  }
273
268
  },
274
- "required": [
275
- "id"
276
- ],
269
+ "required": ["id"],
277
270
  "additionalProperties": false,
278
271
  "description": "Data about a previous audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio)."
279
272
  },
@@ -305,10 +298,7 @@
305
298
  "description": "The type of the content part."
306
299
  }
307
300
  },
308
- "required": [
309
- "text",
310
- "type"
311
- ],
301
+ "required": ["text", "type"],
312
302
  "additionalProperties": false,
313
303
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
314
304
  },
@@ -325,10 +315,7 @@
325
315
  "description": "The type of the content part."
326
316
  }
327
317
  },
328
- "required": [
329
- "refusal",
330
- "type"
331
- ],
318
+ "required": ["refusal", "type"],
332
319
  "additionalProperties": false
333
320
  }
334
321
  ]
@@ -354,10 +341,7 @@
354
341
  "description": "The name of the function to call."
355
342
  }
356
343
  },
357
- "required": [
358
- "arguments",
359
- "name"
360
- ],
344
+ "required": ["arguments", "name"],
361
345
  "additionalProperties": false,
362
346
  "deprecated": "Deprecated and replaced by `tool_calls`. The name and arguments of a\nfunction that should be called, as generated by the model."
363
347
  },
@@ -372,10 +356,7 @@
372
356
  "description": "An optional name for the participant. Provides the model information to differentiate between participants of the same role."
373
357
  },
374
358
  "refusal": {
375
- "type": [
376
- "string",
377
- "null"
378
- ],
359
+ "type": ["string", "null"],
379
360
  "description": "The refusal message by the assistant."
380
361
  },
381
362
  "tool_calls": {
@@ -399,10 +380,7 @@
399
380
  "description": "The name of the function to call."
400
381
  }
401
382
  },
402
- "required": [
403
- "arguments",
404
- "name"
405
- ],
383
+ "required": ["arguments", "name"],
406
384
  "additionalProperties": false,
407
385
  "description": "The function that the model called."
408
386
  },
@@ -412,19 +390,13 @@
412
390
  "description": "The type of the tool. Currently, only `function` is supported."
413
391
  }
414
392
  },
415
- "required": [
416
- "id",
417
- "function",
418
- "type"
419
- ],
393
+ "required": ["id", "function", "type"],
420
394
  "additionalProperties": false
421
395
  },
422
396
  "description": "The tool calls generated by the model, such as function calls."
423
397
  }
424
398
  },
425
- "required": [
426
- "role"
427
- ],
399
+ "required": ["role"],
428
400
  "additionalProperties": false,
429
401
  "description": "Messages sent by the model in response to user messages."
430
402
  },
@@ -451,10 +423,7 @@
451
423
  "description": "The type of the content part."
452
424
  }
453
425
  },
454
- "required": [
455
- "text",
456
- "type"
457
- ],
426
+ "required": ["text", "type"],
458
427
  "additionalProperties": false,
459
428
  "description": "Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation)."
460
429
  }
@@ -472,21 +441,14 @@
472
441
  "description": "Tool call that this message is responding to."
473
442
  }
474
443
  },
475
- "required": [
476
- "content",
477
- "role",
478
- "tool_call_id"
479
- ],
444
+ "required": ["content", "role", "tool_call_id"],
480
445
  "additionalProperties": false
481
446
  },
482
447
  {
483
448
  "type": "object",
484
449
  "properties": {
485
450
  "content": {
486
- "type": [
487
- "string",
488
- "null"
489
- ],
451
+ "type": ["string", "null"],
490
452
  "description": "The contents of the function message."
491
453
  },
492
454
  "name": {
@@ -499,11 +461,7 @@
499
461
  "description": "The role of the messages author, in this case `function`."
500
462
  }
501
463
  },
502
- "required": [
503
- "content",
504
- "name",
505
- "role"
506
- ],
464
+ "required": ["content", "name", "role"],
507
465
  "additionalProperties": false,
508
466
  "deprecated": true
509
467
  }
@@ -524,10 +482,7 @@
524
482
  "type": "array",
525
483
  "items": {
526
484
  "type": "string",
527
- "enum": [
528
- "text",
529
- "audio"
530
- ]
485
+ "enum": ["text", "audio"]
531
486
  },
532
487
  "description": "Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default:\n\n`[\"text\"]`\n\nThe `gpt-4o-audio-preview` model can also be used to [generate audio](https://platform.openai.com/docs/guides/audio). To request that this model generate both text and audio responses, you can use:\n\n`[\"text\", \"audio\"]`"
533
488
  },
@@ -536,43 +491,48 @@
536
491
  "properties": {
537
492
  "format": {
538
493
  "type": "string",
539
- "enum": [
540
- "wav",
541
- "mp3",
542
- "flac",
543
- "opus",
544
- "pcm16"
545
- ],
494
+ "enum": ["wav", "aac", "mp3", "flac", "opus", "pcm16"],
546
495
  "description": "Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`, or `pcm16`."
547
496
  },
548
497
  "voice": {
549
- "type": "string",
550
- "enum": [
551
- "alloy",
552
- "ash",
553
- "ballad",
554
- "coral",
555
- "echo",
556
- "sage",
557
- "shimmer",
558
- "verse"
498
+ "anyOf": [
499
+ {
500
+ "type": "string"
501
+ },
502
+ {
503
+ "type": "string",
504
+ "enum": [
505
+ "alloy",
506
+ "ash",
507
+ "ballad",
508
+ "coral",
509
+ "echo",
510
+ "fable",
511
+ "onyx",
512
+ "nova",
513
+ "sage",
514
+ "shimmer",
515
+ "verse"
516
+ ]
517
+ }
559
518
  ],
560
- "description": "The voice the model uses to respond. Supported voices are `ash`, `ballad`, `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`, `echo`, and `shimmer`; these voices are less expressive)."
519
+ "description": "The voice the model uses to respond. Supported voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, and `shimmer`."
561
520
  }
562
521
  },
563
- "required": [
564
- "format",
565
- "voice"
566
- ],
522
+ "required": ["format", "voice"],
567
523
  "additionalProperties": false,
568
524
  "description": "Parameters for audio output. Required when audio output is requested with `modalities: [\"audio\"]`. [Learn more](https://platform.openai.com/docs/guides/audio)."
569
525
  },
570
526
  "reasoningEffort": {
571
- "type": "string",
572
- "enum": [
573
- "low",
574
- "medium",
575
- "high"
527
+ "anyOf": [
528
+ {
529
+ "type": ["string", "null"],
530
+ "enum": ["low", "medium", "high", null],
531
+ "description": "**o-series models only**\n\nConstrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently supported values are `low`, `medium`, and `high`. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response."
532
+ },
533
+ {
534
+ "type": "null"
535
+ }
576
536
  ],
577
537
  "description": "Constrains effort on reasoning for reasoning models. Currently supported values are low, medium, and high. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response."
578
538
  },
@@ -0,0 +1,21 @@
1
+ import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
2
+ import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
3
+ import { BaseCompleter } from '../../base-completer';
4
+ export declare class WebLLMCompleter extends BaseCompleter {
5
+ constructor(options: BaseCompleter.IOptions);
6
+ /**
7
+ * Initialize the WebLLM model
8
+ */
9
+ private _initializeModel;
10
+ get provider(): ChatWebLLM;
11
+ fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
12
+ items: {
13
+ insertText: string;
14
+ }[];
15
+ }>;
16
+ protected _completer: ChatWebLLM;
17
+ private _isInitialized;
18
+ private _isInitializing;
19
+ private _initError;
20
+ private _abortController;
21
+ }
@@ -0,0 +1,127 @@
1
+ import { HumanMessage, SystemMessage } from '@langchain/core/messages';
2
+ import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
3
+ import { BaseCompleter } from '../../base-completer';
4
+ /**
5
+ * Regular expression to match the '```' string at the start of a string.
6
+ * So the completions returned by the LLM can still be kept after removing the code block formatting.
7
+ *
8
+ * For example, if the response contains the following content after typing `import pandas`:
9
+ *
10
+ * ```python
11
+ * as pd
12
+ * ```
13
+ *
14
+ * The formatting string after removing the code block delimiters will be:
15
+ *
16
+ * as pd
17
+ */
18
+ const CODE_BLOCK_START_REGEX = /^```(?:[a-zA-Z]+)?\n?/;
19
+ /**
20
+ * Regular expression to match the '```' string at the end of a string.
21
+ */
22
+ const CODE_BLOCK_END_REGEX = /```$/;
23
+ export class WebLLMCompleter extends BaseCompleter {
24
+ constructor(options) {
25
+ super(options);
26
+ const model = options.settings.model;
27
+ // provide model separately since ChatWebLLM expects it
28
+ this._completer = new ChatWebLLM({
29
+ ...options.settings,
30
+ model
31
+ });
32
+ // Initialize the model and track its status
33
+ this._isInitialized = false;
34
+ this._isInitializing = false;
35
+ this._initError = null;
36
+ void this._initializeModel();
37
+ }
38
+ /**
39
+ * Initialize the WebLLM model
40
+ */
41
+ async _initializeModel() {
42
+ if (this._isInitialized || this._isInitializing) {
43
+ return;
44
+ }
45
+ this._isInitializing = true;
46
+ try {
47
+ await this._completer.initialize((progress) => {
48
+ console.log('WebLLM initialization progress:', progress);
49
+ });
50
+ this._isInitialized = true;
51
+ this._isInitializing = false;
52
+ console.log('WebLLM model successfully initialized');
53
+ }
54
+ catch (error) {
55
+ this._initError =
56
+ error instanceof Error ? error : new Error(String(error));
57
+ this._isInitializing = false;
58
+ console.error('Failed to initialize WebLLM model:', error);
59
+ }
60
+ }
61
+ get provider() {
62
+ return this._completer;
63
+ }
64
+ async fetch(request, context) {
65
+ // Abort any pending request
66
+ if (this._abortController) {
67
+ this._abortController.abort();
68
+ }
69
+ // Create a new abort controller for this request
70
+ this._abortController = new AbortController();
71
+ const signal = this._abortController.signal;
72
+ if (!this._isInitialized) {
73
+ if (this._initError) {
74
+ console.error('WebLLM model failed to initialize:', this._initError);
75
+ return { items: [] };
76
+ }
77
+ if (!this._isInitializing) {
78
+ // Try to initialize again if it's not currently initializing
79
+ await this._initializeModel();
80
+ }
81
+ else {
82
+ console.log('WebLLM model is still initializing, please try again later');
83
+ return { items: [] };
84
+ }
85
+ // Return empty if still not initialized
86
+ if (!this._isInitialized) {
87
+ return { items: [] };
88
+ }
89
+ }
90
+ const { text, offset: cursorOffset } = request;
91
+ const prompt = text.slice(0, cursorOffset);
92
+ const trimmedPrompt = prompt.trim();
93
+ const messages = [
94
+ new SystemMessage(this.systemPrompt),
95
+ new HumanMessage(trimmedPrompt)
96
+ ];
97
+ try {
98
+ console.log('Trigger invoke');
99
+ const response = await this._completer.invoke(messages, { signal });
100
+ let content = response.content;
101
+ console.log('Response content:', content);
102
+ if (CODE_BLOCK_START_REGEX.test(content)) {
103
+ content = content
104
+ .replace(CODE_BLOCK_START_REGEX, '')
105
+ .replace(CODE_BLOCK_END_REGEX, '');
106
+ }
107
+ const items = [{ insertText: content }];
108
+ return {
109
+ items
110
+ };
111
+ }
112
+ catch (error) {
113
+ if (error instanceof Error) {
114
+ console.error('Error fetching completion from WebLLM:', error.message);
115
+ }
116
+ else {
117
+ console.error('Unknown error fetching completion from WebLLM:', error);
118
+ }
119
+ return { items: [] };
120
+ }
121
+ }
122
+ _completer;
123
+ _isInitialized = false;
124
+ _isInitializing = false;
125
+ _initError = null;
126
+ _abortController = null;
127
+ }
@@ -0,0 +1,6 @@
1
+ declare const _default: "\nWebLLM enables running LLMs directly in your browser, making it possible to use AI features without sending data to external servers.\n\n<i class=\"fas fa-info-circle\"></i> WebLLM runs models entirely in your browser, so initial model download may be large (100MB-2GB depending on the model).\n\n<i class=\"fas fa-exclamation-triangle\"></i> <strong>Requirements:</strong> WebLLM requires a browser with WebGPU support (Chrome 113+, Edge 113+, or Safari 17+). It will not work on older browsers or browsers without WebGPU enabled.\n\n1. Enter a model in the JupyterLab settings under the **Ai providers** section. Select the `WebLLM` provider and type the model you want to use.\n2. When you first use WebLLM, your browser will download the model. A progress notification will appear:\n3. Once loaded, use the chat\n4. Example of available models:\n - Llama-3.2-1B-Instruct-q4f32_1-MLC\n - Mistral-7B-Instruct-v0.3-q4f32_1-MLC\n - Qwen3-0.6B-q4f32_1-MLC\n5. See the full list of models: https://github.com/mlc-ai/web-llm/blob/632d34725629b480b5b2772379ef5c150b1286f0/src/config.ts#L303-L309\n\n<i class=\"fas fa-exclamation-triangle\"></i> Model performance depends on your device's hardware capabilities. More powerful devices will run models faster. Some larger models may not work well on devices with limited GPU memory or may experience slow response times.\n";
2
+ export default _default;
3
+ /**
4
+ * Check if the browser supports WebLLM.
5
+ */
6
+ export declare function compatibilityCheck(): Promise<string | null>;
@@ -0,0 +1,32 @@
1
+ export default `
2
+ WebLLM enables running LLMs directly in your browser, making it possible to use AI features without sending data to external servers.
3
+
4
+ <i class="fas fa-info-circle"></i> WebLLM runs models entirely in your browser, so initial model download may be large (100MB-2GB depending on the model).
5
+
6
+ <i class="fas fa-exclamation-triangle"></i> <strong>Requirements:</strong> WebLLM requires a browser with WebGPU support (Chrome 113+, Edge 113+, or Safari 17+). It will not work on older browsers or browsers without WebGPU enabled.
7
+
8
+ 1. Enter a model in the JupyterLab settings under the **Ai providers** section. Select the \`WebLLM\` provider and type the model you want to use.
9
+ 2. When you first use WebLLM, your browser will download the model. A progress notification will appear:
10
+ 3. Once loaded, use the chat
11
+ 4. Example of available models:
12
+ - Llama-3.2-1B-Instruct-q4f32_1-MLC
13
+ - Mistral-7B-Instruct-v0.3-q4f32_1-MLC
14
+ - Qwen3-0.6B-q4f32_1-MLC
15
+ 5. See the full list of models: https://github.com/mlc-ai/web-llm/blob/632d34725629b480b5b2772379ef5c150b1286f0/src/config.ts#L303-L309
16
+
17
+ <i class="fas fa-exclamation-triangle"></i> Model performance depends on your device's hardware capabilities. More powerful devices will run models faster. Some larger models may not work well on devices with limited GPU memory or may experience slow response times.
18
+ `;
19
+ /**
20
+ * Check if the browser supports WebLLM.
21
+ */
22
+ export async function compatibilityCheck() {
23
+ // Check if the browser supports the ChromeAI model
24
+ if (typeof navigator === 'undefined' || !('gpu' in navigator)) {
25
+ return 'Your browser does not support WebLLM, it does not support required WebGPU.';
26
+ }
27
+ if ((await navigator.gpu.requestAdapter()) === null) {
28
+ return 'You may need to enable WebGPU, `await navigator.gpu.requestAdapter()` is null.';
29
+ }
30
+ // If the model is available, return null to indicate compatibility
31
+ return null;
32
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "disableStreaming": {
6
+ "type": "boolean",
7
+ "description": "Whether to disable streaming.\n\nIf streaming is bypassed, then `stream()` will defer to `invoke()`.\n\n- If true, will always bypass streaming case.\n- If false (default), will always use streaming case if available."
8
+ },
9
+ "temperature": {
10
+ "type": "number"
11
+ },
12
+ "model": {
13
+ "type": "string"
14
+ }
15
+ },
16
+ "required": ["model"],
17
+ "additionalProperties": false,
18
+ "definitions": {}
19
+ }