@jupyterlite/ai 0.8.0 → 0.9.0-a0

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 (162) hide show
  1. package/lib/agent.d.ts +233 -0
  2. package/lib/agent.js +604 -0
  3. package/lib/chat-model.d.ts +195 -0
  4. package/lib/chat-model.js +590 -0
  5. package/lib/completion/completion-provider.d.ts +83 -0
  6. package/lib/completion/completion-provider.js +209 -0
  7. package/lib/completion/index.d.ts +1 -0
  8. package/lib/completion/index.js +1 -0
  9. package/lib/components/clear-button.d.ts +18 -0
  10. package/lib/components/clear-button.js +31 -0
  11. package/lib/components/index.d.ts +3 -0
  12. package/lib/components/index.js +3 -0
  13. package/lib/components/model-select.d.ts +19 -0
  14. package/lib/components/model-select.js +154 -0
  15. package/lib/components/stop-button.d.ts +3 -3
  16. package/lib/components/stop-button.js +8 -9
  17. package/lib/components/token-usage-display.d.ts +45 -0
  18. package/lib/components/token-usage-display.js +74 -0
  19. package/lib/components/tool-select.d.ts +27 -0
  20. package/lib/components/tool-select.js +130 -0
  21. package/lib/icons.d.ts +3 -1
  22. package/lib/icons.js +10 -13
  23. package/lib/index.d.ts +4 -5
  24. package/lib/index.js +322 -167
  25. package/lib/mcp/browser.d.ts +68 -0
  26. package/lib/mcp/browser.js +132 -0
  27. package/lib/models/settings-model.d.ts +69 -0
  28. package/lib/models/settings-model.js +295 -0
  29. package/lib/providers/built-in-providers.d.ts +9 -0
  30. package/lib/providers/built-in-providers.js +192 -0
  31. package/lib/providers/models.d.ts +37 -0
  32. package/lib/providers/models.js +28 -0
  33. package/lib/providers/provider-registry.d.ts +94 -0
  34. package/lib/providers/provider-registry.js +155 -0
  35. package/lib/tokens.d.ts +157 -86
  36. package/lib/tokens.js +16 -12
  37. package/lib/tools/commands.d.ts +11 -0
  38. package/lib/tools/commands.js +126 -0
  39. package/lib/tools/file.d.ts +27 -0
  40. package/lib/tools/file.js +262 -0
  41. package/lib/tools/notebook.d.ts +40 -0
  42. package/lib/tools/notebook.js +762 -0
  43. package/lib/tools/tool-registry.d.ts +35 -0
  44. package/lib/tools/tool-registry.js +55 -0
  45. package/lib/widgets/ai-settings.d.ts +39 -0
  46. package/lib/widgets/ai-settings.js +506 -0
  47. package/lib/widgets/chat-wrapper.d.ts +144 -0
  48. package/lib/widgets/chat-wrapper.js +390 -0
  49. package/lib/widgets/provider-config-dialog.d.ts +13 -0
  50. package/lib/widgets/provider-config-dialog.js +104 -0
  51. package/package.json +150 -41
  52. package/schema/settings-model.json +153 -0
  53. package/src/agent.ts +800 -0
  54. package/src/chat-model.ts +770 -0
  55. package/src/completion/completion-provider.ts +308 -0
  56. package/src/completion/index.ts +1 -0
  57. package/src/components/clear-button.tsx +56 -0
  58. package/src/components/index.ts +3 -0
  59. package/src/components/model-select.tsx +245 -0
  60. package/src/components/stop-button.tsx +11 -11
  61. package/src/components/token-usage-display.tsx +130 -0
  62. package/src/components/tool-select.tsx +218 -0
  63. package/src/icons.ts +12 -14
  64. package/src/index.ts +468 -238
  65. package/src/mcp/browser.ts +213 -0
  66. package/src/models/settings-model.ts +409 -0
  67. package/src/providers/built-in-providers.ts +216 -0
  68. package/src/providers/models.ts +79 -0
  69. package/src/providers/provider-registry.ts +189 -0
  70. package/src/tokens.ts +203 -90
  71. package/src/tools/commands.ts +151 -0
  72. package/src/tools/file.ts +307 -0
  73. package/src/tools/notebook.ts +964 -0
  74. package/src/tools/tool-registry.ts +63 -0
  75. package/src/types.d.ts +4 -0
  76. package/src/widgets/ai-settings.tsx +1100 -0
  77. package/src/widgets/chat-wrapper.tsx +543 -0
  78. package/src/widgets/provider-config-dialog.tsx +256 -0
  79. package/style/base.css +335 -14
  80. package/style/icons/jupyternaut-lite.svg +1 -1
  81. package/lib/base-completer.d.ts +0 -49
  82. package/lib/base-completer.js +0 -14
  83. package/lib/chat-handler.d.ts +0 -56
  84. package/lib/chat-handler.js +0 -201
  85. package/lib/completion-provider.d.ts +0 -34
  86. package/lib/completion-provider.js +0 -32
  87. package/lib/default-prompts.d.ts +0 -2
  88. package/lib/default-prompts.js +0 -31
  89. package/lib/default-providers/Anthropic/completer.d.ts +0 -12
  90. package/lib/default-providers/Anthropic/completer.js +0 -46
  91. package/lib/default-providers/Anthropic/settings-schema.json +0 -70
  92. package/lib/default-providers/ChromeAI/completer.d.ts +0 -12
  93. package/lib/default-providers/ChromeAI/completer.js +0 -56
  94. package/lib/default-providers/ChromeAI/instructions.d.ts +0 -6
  95. package/lib/default-providers/ChromeAI/instructions.js +0 -42
  96. package/lib/default-providers/ChromeAI/settings-schema.json +0 -18
  97. package/lib/default-providers/Gemini/completer.d.ts +0 -12
  98. package/lib/default-providers/Gemini/completer.js +0 -48
  99. package/lib/default-providers/Gemini/instructions.d.ts +0 -2
  100. package/lib/default-providers/Gemini/instructions.js +0 -9
  101. package/lib/default-providers/Gemini/settings-schema.json +0 -64
  102. package/lib/default-providers/MistralAI/completer.d.ts +0 -13
  103. package/lib/default-providers/MistralAI/completer.js +0 -52
  104. package/lib/default-providers/MistralAI/instructions.d.ts +0 -2
  105. package/lib/default-providers/MistralAI/instructions.js +0 -18
  106. package/lib/default-providers/MistralAI/settings-schema.json +0 -75
  107. package/lib/default-providers/Ollama/completer.d.ts +0 -12
  108. package/lib/default-providers/Ollama/completer.js +0 -43
  109. package/lib/default-providers/Ollama/instructions.d.ts +0 -2
  110. package/lib/default-providers/Ollama/instructions.js +0 -70
  111. package/lib/default-providers/Ollama/settings-schema.json +0 -143
  112. package/lib/default-providers/OpenAI/completer.d.ts +0 -12
  113. package/lib/default-providers/OpenAI/completer.js +0 -43
  114. package/lib/default-providers/OpenAI/settings-schema.json +0 -628
  115. package/lib/default-providers/WebLLM/completer.d.ts +0 -21
  116. package/lib/default-providers/WebLLM/completer.js +0 -127
  117. package/lib/default-providers/WebLLM/instructions.d.ts +0 -6
  118. package/lib/default-providers/WebLLM/instructions.js +0 -32
  119. package/lib/default-providers/WebLLM/settings-schema.json +0 -19
  120. package/lib/default-providers/index.d.ts +0 -2
  121. package/lib/default-providers/index.js +0 -179
  122. package/lib/provider.d.ts +0 -144
  123. package/lib/provider.js +0 -412
  124. package/lib/settings/base.json +0 -7
  125. package/lib/settings/index.d.ts +0 -3
  126. package/lib/settings/index.js +0 -3
  127. package/lib/settings/panel.d.ts +0 -226
  128. package/lib/settings/panel.js +0 -510
  129. package/lib/settings/textarea.d.ts +0 -2
  130. package/lib/settings/textarea.js +0 -18
  131. package/lib/settings/utils.d.ts +0 -2
  132. package/lib/settings/utils.js +0 -4
  133. package/lib/types/ai-model.d.ts +0 -24
  134. package/lib/types/ai-model.js +0 -5
  135. package/schema/chat.json +0 -28
  136. package/schema/provider-registry.json +0 -29
  137. package/schema/system-prompts.json +0 -22
  138. package/src/base-completer.ts +0 -75
  139. package/src/chat-handler.ts +0 -262
  140. package/src/completion-provider.ts +0 -64
  141. package/src/default-prompts.ts +0 -33
  142. package/src/default-providers/Anthropic/completer.ts +0 -59
  143. package/src/default-providers/ChromeAI/completer.ts +0 -73
  144. package/src/default-providers/ChromeAI/instructions.ts +0 -45
  145. package/src/default-providers/Gemini/completer.ts +0 -61
  146. package/src/default-providers/Gemini/instructions.ts +0 -9
  147. package/src/default-providers/MistralAI/completer.ts +0 -69
  148. package/src/default-providers/MistralAI/instructions.ts +0 -18
  149. package/src/default-providers/Ollama/completer.ts +0 -54
  150. package/src/default-providers/Ollama/instructions.ts +0 -70
  151. package/src/default-providers/OpenAI/completer.ts +0 -54
  152. package/src/default-providers/WebLLM/completer.ts +0 -151
  153. package/src/default-providers/WebLLM/instructions.ts +0 -33
  154. package/src/default-providers/index.ts +0 -211
  155. package/src/global.d.ts +0 -9
  156. package/src/provider.ts +0 -514
  157. package/src/settings/index.ts +0 -3
  158. package/src/settings/panel.tsx +0 -773
  159. package/src/settings/textarea.tsx +0 -33
  160. package/src/settings/utils.ts +0 -5
  161. package/src/types/ai-model.ts +0 -37
  162. package/src/types/service-worker.d.ts +0 -6
@@ -1,69 +0,0 @@
1
- import {
2
- CompletionHandler,
3
- IInlineCompletionContext
4
- } from '@jupyterlab/completer';
5
- import { MistralAI } from '@langchain/mistralai';
6
-
7
- import { BaseCompleter } from '../../base-completer';
8
-
9
- const CODE_BLOCK_START_REGEX = /^```(?:[a-zA-Z]+)?\n?/;
10
- const CODE_BLOCK_END_REGEX = /```$/;
11
-
12
- export class CodestralCompleter extends BaseCompleter {
13
- constructor(options: BaseCompleter.IOptions) {
14
- super(options);
15
- this._completer = new MistralAI({ ...options.settings });
16
- }
17
-
18
- async fetch(
19
- request: CompletionHandler.IRequest,
20
- context: IInlineCompletionContext
21
- ) {
22
- try {
23
- const { text, offset: cursorOffset } = request;
24
- const prompt = this.systemPrompt.concat(text.slice(0, cursorOffset));
25
- const suffix = text.slice(cursorOffset);
26
- this._controller.abort();
27
- this._controller = new AbortController();
28
-
29
- const response = await this._completer.completionWithRetry(
30
- {
31
- prompt,
32
- model: this._completer.model,
33
- suffix
34
- },
35
- { signal: this._controller.signal },
36
- false
37
- );
38
- const items = response.choices.map(choice => {
39
- const messageContent = choice.message.content;
40
- let content = '';
41
-
42
- if (typeof messageContent === 'string') {
43
- content = messageContent
44
- .replace(CODE_BLOCK_START_REGEX, '')
45
- .replace(CODE_BLOCK_END_REGEX, '');
46
- } else if (Array.isArray(messageContent)) {
47
- // Handle ContentChunk[] case - extract text content
48
- content = messageContent
49
- .filter(chunk => chunk.type === 'text')
50
- .map(chunk => chunk.text || '')
51
- .join('')
52
- .replace(CODE_BLOCK_START_REGEX, '')
53
- .replace(CODE_BLOCK_END_REGEX, '');
54
- }
55
-
56
- return {
57
- insertText: content
58
- };
59
- });
60
- return { items };
61
- } catch (error) {
62
- // the request may be aborted
63
- return { items: [] };
64
- }
65
- }
66
-
67
- private _controller = new AbortController();
68
- protected _completer: MistralAI;
69
- }
@@ -1,18 +0,0 @@
1
- export default `
2
- <i class="fas fa-exclamation-triangle"></i> This extension is still very much experimental. It is not an official MistralAI extension.
3
-
4
- 1. Go to <https://console.mistral.ai/api-keys/> and create an API key.
5
-
6
- <img src="https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/1-api-key.png" alt="Screenshot showing how to create an API key" width="500px">
7
-
8
- 2. Open the JupyterLab settings and go to the **Ai providers** section to select the \`MistralAI\`
9
- provider and the API key (required).
10
-
11
- <img src="https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/2-jupyterlab-settings.png" alt="Screenshot showing how to add the API key to the settings" width="500px">
12
-
13
- **Note:** When using MistralAI for completions, only a subset of models are available. Please check [this resource](https://docs.mistral.ai/api/#tag/fim) to see the list of supported models for completions.
14
-
15
- 3. Open the chat, or use the inline completer
16
-
17
- <img src="https://raw.githubusercontent.com/jupyterlite/ai/refs/heads/main/img/3-usage.png" alt="Screenshot showing how to use the chat" width="500px">
18
- `;
@@ -1,54 +0,0 @@
1
- import {
2
- CompletionHandler,
3
- IInlineCompletionContext
4
- } from '@jupyterlab/completer';
5
- import { AIMessage, SystemMessage } from '@langchain/core/messages';
6
- import { ChatOllama } from '@langchain/ollama';
7
-
8
- import { BaseCompleter } from '../../base-completer';
9
-
10
- export class OllamaCompleter extends BaseCompleter {
11
- constructor(options: BaseCompleter.IOptions) {
12
- super(options);
13
- this._completer = new ChatOllama({ ...options.settings });
14
- }
15
-
16
- async fetch(
17
- request: CompletionHandler.IRequest,
18
- context: IInlineCompletionContext
19
- ) {
20
- const { text, offset: cursorOffset } = request;
21
- const prompt = text.slice(0, cursorOffset);
22
-
23
- const messages = [
24
- new SystemMessage(this.systemPrompt),
25
- new AIMessage(prompt)
26
- ];
27
-
28
- try {
29
- const response = await this._completer.invoke(messages);
30
- const items = [];
31
- if (typeof response.content === 'string') {
32
- items.push({
33
- insertText: response.content
34
- });
35
- } else {
36
- response.content.forEach(content => {
37
- if (content.type !== 'text') {
38
- return;
39
- }
40
- items.push({
41
- insertText: content.text,
42
- filterText: prompt.substring(prompt.length)
43
- });
44
- });
45
- }
46
- return { items };
47
- } catch (error) {
48
- console.error('Error fetching completions', error);
49
- return { items: [] };
50
- }
51
- }
52
-
53
- protected _completer: ChatOllama;
54
- }
@@ -1,70 +0,0 @@
1
- export default `
2
- Ollama allows to run large language models locally on your machine.
3
- To use it you need to install the Ollama CLI and pull the model you want to use.
4
-
5
- 1. Install the Ollama CLI by following the instructions at <https://ollama.com/download>
6
-
7
- 2. Pull the model you want to use by running the following command in your terminal:
8
-
9
- \`\`\`bash
10
- ollama pull <model-name>
11
- \`\`\`
12
-
13
- For example, to pull the Llama 2 model, run:
14
-
15
- \`\`\`bash
16
- ollama pull llama2
17
- \`\`\`
18
-
19
- 3. Once the model is pulled, you can use it in your application by running the following command:
20
-
21
- \`\`\`bash
22
- ollama serve
23
- \`\`\`
24
-
25
- 4. This model will be available in the extension, using the model name you used in the command above.
26
-
27
- <details>
28
- <summary>Deploying Lite/Lab on external server</summary>
29
-
30
- See https://objectgraph.com/blog/ollama-cors/ for more details.
31
-
32
- On Linux, you can run the following commands:
33
-
34
- 1. Check if CORS is enabled on the server. You can do this by running the following command in your terminal:
35
-
36
- \`\`\`bash
37
- curl -X OPTIONS http://localhost:11434 -H "Origin: http://example.com" -H "Access-Control-Request-Method: GET" -I
38
- \`\`\`
39
-
40
- If CORS is disabled, you will see a response like this:
41
-
42
- \`\`\`bash
43
- HTTP/1.1 403 Forbidden
44
- Date: Wed, 09 Oct 2024 10:12:15 GMT
45
- Content-Length: 0
46
- \`\`\`
47
-
48
- 2. If CORS is not enabled, update _/etc/systemd/system/ollama.service_ with:
49
-
50
- \`\`\`bash
51
- [Service]
52
- Environment="OLLAMA_HOST=0.0.0.0"
53
- Environment="OLLAMA_ORIGINS=*"
54
- \`\`\`
55
-
56
- 3. Restart the service:
57
-
58
- \`\`\`bash
59
- sudo systemctl daemon-reload
60
- sudo systemctl restart ollama
61
- \`\`\`
62
-
63
- 4. Check if CORS is enabled on the server again by running the following command in your terminal:
64
-
65
- \`\`\`bash
66
- curl -X OPTIONS http://localhost:11434 -H "Origin: http://example.com" -H "Access-Control-Request-Method: GET" -I
67
- \`\`\`
68
-
69
- </details>
70
- `;
@@ -1,54 +0,0 @@
1
- import {
2
- CompletionHandler,
3
- IInlineCompletionContext
4
- } from '@jupyterlab/completer';
5
- import { AIMessage, SystemMessage } from '@langchain/core/messages';
6
- import { ChatOpenAI } from '@langchain/openai';
7
-
8
- import { BaseCompleter } from '../../base-completer';
9
-
10
- export class OpenAICompleter extends BaseCompleter {
11
- constructor(options: BaseCompleter.IOptions) {
12
- super(options);
13
- this._completer = new ChatOpenAI({ ...options.settings });
14
- }
15
-
16
- async fetch(
17
- request: CompletionHandler.IRequest,
18
- context: IInlineCompletionContext
19
- ) {
20
- const { text, offset: cursorOffset } = request;
21
- const prompt = text.slice(0, cursorOffset);
22
-
23
- const messages = [
24
- new SystemMessage(this.systemPrompt),
25
- new AIMessage(prompt)
26
- ];
27
-
28
- try {
29
- const response = await this._completer.invoke(messages);
30
- const items = [];
31
- if (typeof response.content === 'string') {
32
- items.push({
33
- insertText: response.content
34
- });
35
- } else {
36
- response.content.forEach(content => {
37
- if (content.type !== 'text') {
38
- return;
39
- }
40
- items.push({
41
- insertText: content.text,
42
- filterText: prompt.substring(prompt.length)
43
- });
44
- });
45
- }
46
- return { items };
47
- } catch (error) {
48
- console.error('Error fetching completions', error);
49
- return { items: [] };
50
- }
51
- }
52
-
53
- protected _completer: ChatOpenAI;
54
- }
@@ -1,151 +0,0 @@
1
- import {
2
- CompletionHandler,
3
- IInlineCompletionContext
4
- } from '@jupyterlab/completer';
5
- import { HumanMessage, SystemMessage } from '@langchain/core/messages';
6
- import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
7
-
8
- import { BaseCompleter } from '../../base-completer';
9
-
10
- /**
11
- * Regular expression to match the '```' string at the start of a string.
12
- * So the completions returned by the LLM can still be kept after removing the code block formatting.
13
- *
14
- * For example, if the response contains the following content after typing `import pandas`:
15
- *
16
- * ```python
17
- * as pd
18
- * ```
19
- *
20
- * The formatting string after removing the code block delimiters will be:
21
- *
22
- * as pd
23
- */
24
- const CODE_BLOCK_START_REGEX = /^```(?:[a-zA-Z]+)?\n?/;
25
-
26
- /**
27
- * Regular expression to match the '```' string at the end of a string.
28
- */
29
- const CODE_BLOCK_END_REGEX = /```$/;
30
-
31
- export class WebLLMCompleter extends BaseCompleter {
32
- constructor(options: BaseCompleter.IOptions) {
33
- super(options);
34
- const model = options.settings.model as string;
35
- // provide model separately since ChatWebLLM expects it
36
- this._completer = new ChatWebLLM({
37
- ...options.settings,
38
- model
39
- });
40
-
41
- // Initialize the model and track its status
42
- this._isInitialized = false;
43
- this._isInitializing = false;
44
- this._initError = null;
45
- void this._initializeModel();
46
- }
47
-
48
- /**
49
- * Initialize the WebLLM model
50
- */
51
- private async _initializeModel(): Promise<void> {
52
- if (this._isInitialized || this._isInitializing) {
53
- return;
54
- }
55
-
56
- this._isInitializing = true;
57
- try {
58
- await this._completer.initialize((progress: any) => {
59
- console.log('WebLLM initialization progress:', progress);
60
- });
61
- this._isInitialized = true;
62
- this._isInitializing = false;
63
- console.log('WebLLM model successfully initialized');
64
- } catch (error) {
65
- this._initError =
66
- error instanceof Error ? error : new Error(String(error));
67
- this._isInitializing = false;
68
- console.error('Failed to initialize WebLLM model:', error);
69
- }
70
- }
71
-
72
- get provider(): ChatWebLLM {
73
- return this._completer;
74
- }
75
-
76
- async fetch(
77
- request: CompletionHandler.IRequest,
78
- context: IInlineCompletionContext
79
- ) {
80
- // Abort any pending request
81
- if (this._abortController) {
82
- this._abortController.abort();
83
- }
84
-
85
- // Create a new abort controller for this request
86
- this._abortController = new AbortController();
87
- const signal = this._abortController.signal;
88
-
89
- if (!this._isInitialized) {
90
- if (this._initError) {
91
- console.error('WebLLM model failed to initialize:', this._initError);
92
- return { items: [] };
93
- }
94
-
95
- if (!this._isInitializing) {
96
- // Try to initialize again if it's not currently initializing
97
- await this._initializeModel();
98
- } else {
99
- console.log(
100
- 'WebLLM model is still initializing, please try again later'
101
- );
102
- return { items: [] };
103
- }
104
-
105
- // Return empty if still not initialized
106
- if (!this._isInitialized) {
107
- return { items: [] };
108
- }
109
- }
110
-
111
- const { text, offset: cursorOffset } = request;
112
- const prompt = text.slice(0, cursorOffset);
113
- const trimmedPrompt = prompt.trim();
114
-
115
- const messages = [
116
- new SystemMessage(this.systemPrompt),
117
- new HumanMessage(trimmedPrompt)
118
- ];
119
-
120
- try {
121
- console.log('Trigger invoke');
122
- const response = await this._completer.invoke(messages, { signal });
123
- let content = response.content as string;
124
- console.log('Response content:', content);
125
-
126
- if (CODE_BLOCK_START_REGEX.test(content)) {
127
- content = content
128
- .replace(CODE_BLOCK_START_REGEX, '')
129
- .replace(CODE_BLOCK_END_REGEX, '');
130
- }
131
-
132
- const items = [{ insertText: content }];
133
- return {
134
- items
135
- };
136
- } catch (error) {
137
- if (error instanceof Error) {
138
- console.error('Error fetching completion from WebLLM:', error.message);
139
- } else {
140
- console.error('Unknown error fetching completion from WebLLM:', error);
141
- }
142
- return { items: [] };
143
- }
144
- }
145
-
146
- protected _completer: ChatWebLLM;
147
- private _isInitialized: boolean = false;
148
- private _isInitializing: boolean = false;
149
- private _initError: Error | null = null;
150
- private _abortController: AbortController | null = null;
151
- }
@@ -1,33 +0,0 @@
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
- /**
21
- * Check if the browser supports WebLLM.
22
- */
23
- export async function compatibilityCheck(): Promise<string | null> {
24
- // Check if the browser supports the ChromeAI model
25
- if (typeof navigator === 'undefined' || !('gpu' in navigator)) {
26
- return 'Your browser does not support WebLLM, it does not support required WebGPU.';
27
- }
28
- if ((await navigator.gpu.requestAdapter()) === null) {
29
- return 'You may need to enable WebGPU, `await navigator.gpu.requestAdapter()` is null.';
30
- }
31
- // If the model is available, return null to indicate compatibility
32
- return null;
33
- }
@@ -1,211 +0,0 @@
1
- import {
2
- JupyterFrontEnd,
3
- JupyterFrontEndPlugin
4
- } from '@jupyterlab/application';
5
- import { Notification } from '@jupyterlab/apputils';
6
-
7
- import { ChatAnthropic } from '@langchain/anthropic';
8
- import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
9
- import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
10
- import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
11
- import { ChatMistralAI } from '@langchain/mistralai';
12
- import { ChatOllama } from '@langchain/ollama';
13
- import { ChatOpenAI } from '@langchain/openai';
14
-
15
- // Import completers
16
- import { AnthropicCompleter } from './Anthropic/completer';
17
- import { ChromeCompleter } from './ChromeAI/completer';
18
- import { GeminiCompleter } from './Gemini/completer';
19
- import { CodestralCompleter } from './MistralAI/completer';
20
- import { OllamaCompleter } from './Ollama/completer';
21
- import { OpenAICompleter } from './OpenAI/completer';
22
- import { WebLLMCompleter } from './WebLLM/completer';
23
-
24
- // Import Settings
25
- import AnthropicSettings from './Anthropic/settings-schema.json';
26
- import ChromeAISettings from './ChromeAI/settings-schema.json';
27
- import GeminiSettings from './Gemini/settings-schema.json';
28
- import MistralAISettings from './MistralAI/settings-schema.json';
29
- import OllamaAISettings from './Ollama/settings-schema.json';
30
- import OpenAISettings from './OpenAI/settings-schema.json';
31
- import WebLLMSettings from './WebLLM/settings-schema.json';
32
-
33
- // Import instructions
34
- import ChromeAIInstructions, {
35
- compatibilityCheck as chromeAICompatibilityCheck
36
- } from './ChromeAI/instructions';
37
- import GeminiInstructions from './Gemini/instructions';
38
- import MistralAIInstructions from './MistralAI/instructions';
39
- import OllamaInstructions from './Ollama/instructions';
40
- import WebLLMInstructions, {
41
- compatibilityCheck as webLLMCompatibilityCheck
42
- } from './WebLLM/instructions';
43
-
44
- import { prebuiltAppConfig } from '@mlc-ai/web-llm';
45
-
46
- import { IAIProvider, IAIProviderRegistry } from '../tokens';
47
-
48
- // Build the AIProvider list
49
- const AIProviders: IAIProvider[] = [
50
- {
51
- name: 'Anthropic',
52
- chat: ChatAnthropic,
53
- completer: AnthropicCompleter,
54
- settingsSchema: AnthropicSettings,
55
- errorMessage: (error: any) => error.error.error.message
56
- },
57
- {
58
- name: 'ChromeAI',
59
- // TODO: fix
60
- // @ts-expect-error: missing properties
61
- chat: ChromeAI,
62
- completer: ChromeCompleter,
63
- instructions: ChromeAIInstructions,
64
- settingsSchema: ChromeAISettings,
65
- compatibilityCheck: chromeAICompatibilityCheck
66
- },
67
- {
68
- name: 'MistralAI',
69
- chat: ChatMistralAI,
70
- completer: CodestralCompleter,
71
- instructions: MistralAIInstructions,
72
- settingsSchema: MistralAISettings
73
- },
74
- {
75
- name: 'Ollama',
76
- chat: ChatOllama,
77
- completer: OllamaCompleter,
78
- instructions: OllamaInstructions,
79
- settingsSchema: OllamaAISettings
80
- },
81
- {
82
- name: 'Gemini',
83
- chat: ChatGoogleGenerativeAI,
84
- completer: GeminiCompleter,
85
- instructions: GeminiInstructions,
86
- settingsSchema: GeminiSettings
87
- },
88
- {
89
- name: 'OpenAI',
90
- chat: ChatOpenAI,
91
- completer: OpenAICompleter,
92
- settingsSchema: OpenAISettings
93
- }
94
- ];
95
-
96
- /**
97
- * Register the WebLLM provider in a separate plugin since it creates notifications
98
- * when the model is changed in the settings.
99
- */
100
- const webLLMProviderPlugin: JupyterFrontEndPlugin<void> = {
101
- id: '@jupyterlite/ai:webllm',
102
- description: 'Register the WebLLM provider',
103
- autoStart: true,
104
- requires: [IAIProviderRegistry],
105
- activate: (app: JupyterFrontEnd, registry: IAIProviderRegistry) => {
106
- registry.add({
107
- name: 'WebLLM',
108
- chat: ChatWebLLM,
109
- completer: WebLLMCompleter,
110
- settingsSchema: WebLLMSettings,
111
- instructions: WebLLMInstructions,
112
- compatibilityCheck: webLLMCompatibilityCheck,
113
- exposeChatModel: true
114
- });
115
-
116
- registry.providerChanged.connect(async (sender, role) => {
117
- const { currentChatModel } = registry;
118
-
119
- // TODO: implement a proper way to handle models that may need to be initialized before being used.
120
- // Mostly applies to WebLLM and ChromeAI as they may need to download the model in the browser first.
121
- if (registry.currentName(role) === 'WebLLM') {
122
- // Leaving this check here, but it should never happen, this check is done in
123
- // the provider registry, and the current name is set to 'None' if there is a
124
- // compatibility error.
125
- const compatibilityError = await webLLMCompatibilityCheck();
126
- if (compatibilityError) {
127
- return;
128
- }
129
-
130
- const model = currentChatModel as ChatWebLLM;
131
- if (model === null || !model.model) {
132
- return;
133
- }
134
-
135
- // Find if the model is part of the prebuiltAppConfig
136
- const modelRecord = prebuiltAppConfig.model_list.find(
137
- modelRecord => modelRecord.model_id === model.model
138
- );
139
- if (!modelRecord) {
140
- Notification.dismiss();
141
- Notification.emit(
142
- `Model ${model.model} not found in the prebuiltAppConfig`,
143
- 'error',
144
- {
145
- autoClose: 2000
146
- }
147
- );
148
- return;
149
- }
150
-
151
- // create a notification
152
- const notification = Notification.emit(
153
- 'Loading model...',
154
- 'in-progress',
155
- {
156
- autoClose: false,
157
- progress: 0
158
- }
159
- );
160
- try {
161
- void model.initialize(report => {
162
- const { progress, text } = report;
163
- if (progress === 1) {
164
- Notification.update({
165
- id: notification,
166
- progress: 1,
167
- message: `Model ${model.model} loaded successfully`,
168
- type: 'success',
169
- autoClose: 2000
170
- });
171
- return;
172
- }
173
- Notification.update({
174
- id: notification,
175
- progress: progress / 1,
176
- message: text,
177
- type: 'in-progress'
178
- });
179
- });
180
- } catch (err) {
181
- Notification.update({
182
- id: notification,
183
- progress: 1,
184
- message: `Error loading model ${model.model}`,
185
- type: 'error',
186
- autoClose: 2000
187
- });
188
- }
189
- }
190
- });
191
- }
192
- };
193
-
194
- /**
195
- * Register all default AI providers.
196
- */
197
- const aiProviderPlugins = AIProviders.map(provider => {
198
- return {
199
- id: `@jupyterlite/ai:${provider.name}`,
200
- autoStart: true,
201
- requires: [IAIProviderRegistry],
202
- activate: (app: JupyterFrontEnd, registry: IAIProviderRegistry) => {
203
- registry.add(provider);
204
- }
205
- };
206
- });
207
-
208
- export const defaultProviderPlugins: JupyterFrontEndPlugin<void>[] = [
209
- webLLMProviderPlugin,
210
- ...aiProviderPlugins
211
- ];
package/src/global.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /*
2
- * Copyright (c) Jupyter Development Team.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
-
6
- declare module '*.svg' {
7
- const value: string;
8
- export default value;
9
- }