@jupyterlite/ai 0.8.1 → 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.
- package/lib/agent.d.ts +233 -0
- package/lib/agent.js +604 -0
- package/lib/chat-model.d.ts +195 -0
- package/lib/chat-model.js +590 -0
- package/lib/completion/completion-provider.d.ts +83 -0
- package/lib/completion/completion-provider.js +209 -0
- package/lib/completion/index.d.ts +1 -0
- package/lib/completion/index.js +1 -0
- package/lib/components/clear-button.d.ts +18 -0
- package/lib/components/clear-button.js +31 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +3 -0
- package/lib/components/model-select.d.ts +19 -0
- package/lib/components/model-select.js +154 -0
- package/lib/components/stop-button.d.ts +3 -3
- package/lib/components/stop-button.js +8 -9
- package/lib/components/token-usage-display.d.ts +45 -0
- package/lib/components/token-usage-display.js +74 -0
- package/lib/components/tool-select.d.ts +27 -0
- package/lib/components/tool-select.js +130 -0
- package/lib/icons.d.ts +3 -1
- package/lib/icons.js +10 -13
- package/lib/index.d.ts +4 -5
- package/lib/index.js +322 -167
- package/lib/mcp/browser.d.ts +68 -0
- package/lib/mcp/browser.js +132 -0
- package/lib/models/settings-model.d.ts +69 -0
- package/lib/models/settings-model.js +295 -0
- package/lib/providers/built-in-providers.d.ts +9 -0
- package/lib/providers/built-in-providers.js +192 -0
- package/lib/providers/models.d.ts +37 -0
- package/lib/providers/models.js +28 -0
- package/lib/providers/provider-registry.d.ts +94 -0
- package/lib/providers/provider-registry.js +155 -0
- package/lib/tokens.d.ts +157 -86
- package/lib/tokens.js +16 -12
- package/lib/tools/commands.d.ts +11 -0
- package/lib/tools/commands.js +126 -0
- package/lib/tools/file.d.ts +27 -0
- package/lib/tools/file.js +262 -0
- package/lib/tools/notebook.d.ts +40 -0
- package/lib/tools/notebook.js +762 -0
- package/lib/tools/tool-registry.d.ts +35 -0
- package/lib/tools/tool-registry.js +55 -0
- package/lib/widgets/ai-settings.d.ts +39 -0
- package/lib/widgets/ai-settings.js +506 -0
- package/lib/widgets/chat-wrapper.d.ts +144 -0
- package/lib/widgets/chat-wrapper.js +390 -0
- package/lib/widgets/provider-config-dialog.d.ts +13 -0
- package/lib/widgets/provider-config-dialog.js +104 -0
- package/package.json +150 -41
- package/schema/settings-model.json +153 -0
- package/src/agent.ts +800 -0
- package/src/chat-model.ts +770 -0
- package/src/completion/completion-provider.ts +308 -0
- package/src/completion/index.ts +1 -0
- package/src/components/clear-button.tsx +56 -0
- package/src/components/index.ts +3 -0
- package/src/components/model-select.tsx +245 -0
- package/src/components/stop-button.tsx +11 -11
- package/src/components/token-usage-display.tsx +130 -0
- package/src/components/tool-select.tsx +218 -0
- package/src/icons.ts +12 -14
- package/src/index.ts +468 -238
- package/src/mcp/browser.ts +213 -0
- package/src/models/settings-model.ts +409 -0
- package/src/providers/built-in-providers.ts +216 -0
- package/src/providers/models.ts +79 -0
- package/src/providers/provider-registry.ts +189 -0
- package/src/tokens.ts +203 -90
- package/src/tools/commands.ts +151 -0
- package/src/tools/file.ts +307 -0
- package/src/tools/notebook.ts +964 -0
- package/src/tools/tool-registry.ts +63 -0
- package/src/types.d.ts +4 -0
- package/src/widgets/ai-settings.tsx +1100 -0
- package/src/widgets/chat-wrapper.tsx +543 -0
- package/src/widgets/provider-config-dialog.tsx +256 -0
- package/style/base.css +335 -14
- package/style/icons/jupyternaut-lite.svg +1 -1
- package/lib/base-completer.d.ts +0 -49
- package/lib/base-completer.js +0 -14
- package/lib/chat-handler.d.ts +0 -56
- package/lib/chat-handler.js +0 -201
- package/lib/completion-provider.d.ts +0 -34
- package/lib/completion-provider.js +0 -32
- package/lib/default-prompts.d.ts +0 -2
- package/lib/default-prompts.js +0 -31
- package/lib/default-providers/Anthropic/completer.d.ts +0 -12
- package/lib/default-providers/Anthropic/completer.js +0 -46
- package/lib/default-providers/Anthropic/settings-schema.json +0 -70
- package/lib/default-providers/ChromeAI/completer.d.ts +0 -12
- package/lib/default-providers/ChromeAI/completer.js +0 -56
- package/lib/default-providers/ChromeAI/instructions.d.ts +0 -6
- package/lib/default-providers/ChromeAI/instructions.js +0 -42
- package/lib/default-providers/ChromeAI/settings-schema.json +0 -18
- package/lib/default-providers/Gemini/completer.d.ts +0 -12
- package/lib/default-providers/Gemini/completer.js +0 -48
- package/lib/default-providers/Gemini/instructions.d.ts +0 -2
- package/lib/default-providers/Gemini/instructions.js +0 -9
- package/lib/default-providers/Gemini/settings-schema.json +0 -64
- package/lib/default-providers/MistralAI/completer.d.ts +0 -13
- package/lib/default-providers/MistralAI/completer.js +0 -52
- package/lib/default-providers/MistralAI/instructions.d.ts +0 -2
- package/lib/default-providers/MistralAI/instructions.js +0 -18
- package/lib/default-providers/MistralAI/settings-schema.json +0 -75
- package/lib/default-providers/Ollama/completer.d.ts +0 -12
- package/lib/default-providers/Ollama/completer.js +0 -43
- package/lib/default-providers/Ollama/instructions.d.ts +0 -2
- package/lib/default-providers/Ollama/instructions.js +0 -70
- package/lib/default-providers/Ollama/settings-schema.json +0 -143
- package/lib/default-providers/OpenAI/completer.d.ts +0 -12
- package/lib/default-providers/OpenAI/completer.js +0 -43
- package/lib/default-providers/OpenAI/settings-schema.json +0 -628
- package/lib/default-providers/WebLLM/completer.d.ts +0 -21
- package/lib/default-providers/WebLLM/completer.js +0 -127
- package/lib/default-providers/WebLLM/instructions.d.ts +0 -6
- package/lib/default-providers/WebLLM/instructions.js +0 -32
- package/lib/default-providers/WebLLM/settings-schema.json +0 -19
- package/lib/default-providers/index.d.ts +0 -2
- package/lib/default-providers/index.js +0 -179
- package/lib/provider.d.ts +0 -144
- package/lib/provider.js +0 -412
- package/lib/settings/base.json +0 -7
- package/lib/settings/index.d.ts +0 -3
- package/lib/settings/index.js +0 -3
- package/lib/settings/panel.d.ts +0 -226
- package/lib/settings/panel.js +0 -510
- package/lib/settings/textarea.d.ts +0 -2
- package/lib/settings/textarea.js +0 -18
- package/lib/settings/utils.d.ts +0 -2
- package/lib/settings/utils.js +0 -4
- package/lib/types/ai-model.d.ts +0 -24
- package/lib/types/ai-model.js +0 -5
- package/schema/chat.json +0 -28
- package/schema/provider-registry.json +0 -29
- package/schema/system-prompts.json +0 -22
- package/src/base-completer.ts +0 -75
- package/src/chat-handler.ts +0 -262
- package/src/completion-provider.ts +0 -64
- package/src/default-prompts.ts +0 -33
- package/src/default-providers/Anthropic/completer.ts +0 -59
- package/src/default-providers/ChromeAI/completer.ts +0 -73
- package/src/default-providers/ChromeAI/instructions.ts +0 -45
- package/src/default-providers/Gemini/completer.ts +0 -61
- package/src/default-providers/Gemini/instructions.ts +0 -9
- package/src/default-providers/MistralAI/completer.ts +0 -69
- package/src/default-providers/MistralAI/instructions.ts +0 -18
- package/src/default-providers/Ollama/completer.ts +0 -54
- package/src/default-providers/Ollama/instructions.ts +0 -70
- package/src/default-providers/OpenAI/completer.ts +0 -54
- package/src/default-providers/WebLLM/completer.ts +0 -151
- package/src/default-providers/WebLLM/instructions.ts +0 -33
- package/src/default-providers/index.ts +0 -211
- package/src/global.d.ts +0 -9
- package/src/provider.ts +0 -514
- package/src/settings/index.ts +0 -3
- package/src/settings/panel.tsx +0 -773
- package/src/settings/textarea.tsx +0 -33
- package/src/settings/utils.ts +0 -5
- package/src/types/ai-model.ts +0 -37
- package/src/types/service-worker.d.ts +0 -6
|
@@ -1,127 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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>;
|
|
@@ -1,32 +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
|
-
* 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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Notification } from '@jupyterlab/apputils';
|
|
2
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
3
|
-
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
|
|
4
|
-
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
|
|
5
|
-
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
6
|
-
import { ChatMistralAI } from '@langchain/mistralai';
|
|
7
|
-
import { ChatOllama } from '@langchain/ollama';
|
|
8
|
-
import { ChatOpenAI } from '@langchain/openai';
|
|
9
|
-
// Import completers
|
|
10
|
-
import { AnthropicCompleter } from './Anthropic/completer';
|
|
11
|
-
import { ChromeCompleter } from './ChromeAI/completer';
|
|
12
|
-
import { GeminiCompleter } from './Gemini/completer';
|
|
13
|
-
import { CodestralCompleter } from './MistralAI/completer';
|
|
14
|
-
import { OllamaCompleter } from './Ollama/completer';
|
|
15
|
-
import { OpenAICompleter } from './OpenAI/completer';
|
|
16
|
-
import { WebLLMCompleter } from './WebLLM/completer';
|
|
17
|
-
// Import Settings
|
|
18
|
-
import AnthropicSettings from './Anthropic/settings-schema.json';
|
|
19
|
-
import ChromeAISettings from './ChromeAI/settings-schema.json';
|
|
20
|
-
import GeminiSettings from './Gemini/settings-schema.json';
|
|
21
|
-
import MistralAISettings from './MistralAI/settings-schema.json';
|
|
22
|
-
import OllamaAISettings from './Ollama/settings-schema.json';
|
|
23
|
-
import OpenAISettings from './OpenAI/settings-schema.json';
|
|
24
|
-
import WebLLMSettings from './WebLLM/settings-schema.json';
|
|
25
|
-
// Import instructions
|
|
26
|
-
import ChromeAIInstructions, { compatibilityCheck as chromeAICompatibilityCheck } from './ChromeAI/instructions';
|
|
27
|
-
import GeminiInstructions from './Gemini/instructions';
|
|
28
|
-
import MistralAIInstructions from './MistralAI/instructions';
|
|
29
|
-
import OllamaInstructions from './Ollama/instructions';
|
|
30
|
-
import WebLLMInstructions, { compatibilityCheck as webLLMCompatibilityCheck } from './WebLLM/instructions';
|
|
31
|
-
import { prebuiltAppConfig } from '@mlc-ai/web-llm';
|
|
32
|
-
import { IAIProviderRegistry } from '../tokens';
|
|
33
|
-
// Build the AIProvider list
|
|
34
|
-
const AIProviders = [
|
|
35
|
-
{
|
|
36
|
-
name: 'Anthropic',
|
|
37
|
-
chat: ChatAnthropic,
|
|
38
|
-
completer: AnthropicCompleter,
|
|
39
|
-
settingsSchema: AnthropicSettings,
|
|
40
|
-
errorMessage: (error) => error.error.error.message
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'ChromeAI',
|
|
44
|
-
// TODO: fix
|
|
45
|
-
// @ts-expect-error: missing properties
|
|
46
|
-
chat: ChromeAI,
|
|
47
|
-
completer: ChromeCompleter,
|
|
48
|
-
instructions: ChromeAIInstructions,
|
|
49
|
-
settingsSchema: ChromeAISettings,
|
|
50
|
-
compatibilityCheck: chromeAICompatibilityCheck
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'MistralAI',
|
|
54
|
-
chat: ChatMistralAI,
|
|
55
|
-
completer: CodestralCompleter,
|
|
56
|
-
instructions: MistralAIInstructions,
|
|
57
|
-
settingsSchema: MistralAISettings
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'Ollama',
|
|
61
|
-
chat: ChatOllama,
|
|
62
|
-
completer: OllamaCompleter,
|
|
63
|
-
instructions: OllamaInstructions,
|
|
64
|
-
settingsSchema: OllamaAISettings
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'Gemini',
|
|
68
|
-
chat: ChatGoogleGenerativeAI,
|
|
69
|
-
completer: GeminiCompleter,
|
|
70
|
-
instructions: GeminiInstructions,
|
|
71
|
-
settingsSchema: GeminiSettings
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
name: 'OpenAI',
|
|
75
|
-
chat: ChatOpenAI,
|
|
76
|
-
completer: OpenAICompleter,
|
|
77
|
-
settingsSchema: OpenAISettings
|
|
78
|
-
}
|
|
79
|
-
];
|
|
80
|
-
/**
|
|
81
|
-
* Register the WebLLM provider in a separate plugin since it creates notifications
|
|
82
|
-
* when the model is changed in the settings.
|
|
83
|
-
*/
|
|
84
|
-
const webLLMProviderPlugin = {
|
|
85
|
-
id: '@jupyterlite/ai:webllm',
|
|
86
|
-
description: 'Register the WebLLM provider',
|
|
87
|
-
autoStart: true,
|
|
88
|
-
requires: [IAIProviderRegistry],
|
|
89
|
-
activate: (app, registry) => {
|
|
90
|
-
registry.add({
|
|
91
|
-
name: 'WebLLM',
|
|
92
|
-
chat: ChatWebLLM,
|
|
93
|
-
completer: WebLLMCompleter,
|
|
94
|
-
settingsSchema: WebLLMSettings,
|
|
95
|
-
instructions: WebLLMInstructions,
|
|
96
|
-
compatibilityCheck: webLLMCompatibilityCheck,
|
|
97
|
-
exposeChatModel: true
|
|
98
|
-
});
|
|
99
|
-
registry.providerChanged.connect(async (sender, role) => {
|
|
100
|
-
const { currentChatModel } = registry;
|
|
101
|
-
// TODO: implement a proper way to handle models that may need to be initialized before being used.
|
|
102
|
-
// Mostly applies to WebLLM and ChromeAI as they may need to download the model in the browser first.
|
|
103
|
-
if (registry.currentName(role) === 'WebLLM') {
|
|
104
|
-
// Leaving this check here, but it should never happen, this check is done in
|
|
105
|
-
// the provider registry, and the current name is set to 'None' if there is a
|
|
106
|
-
// compatibility error.
|
|
107
|
-
const compatibilityError = await webLLMCompatibilityCheck();
|
|
108
|
-
if (compatibilityError) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const model = currentChatModel;
|
|
112
|
-
if (model === null || !model.model) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
// Find if the model is part of the prebuiltAppConfig
|
|
116
|
-
const modelRecord = prebuiltAppConfig.model_list.find(modelRecord => modelRecord.model_id === model.model);
|
|
117
|
-
if (!modelRecord) {
|
|
118
|
-
Notification.dismiss();
|
|
119
|
-
Notification.emit(`Model ${model.model} not found in the prebuiltAppConfig`, 'error', {
|
|
120
|
-
autoClose: 2000
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// create a notification
|
|
125
|
-
const notification = Notification.emit('Loading model...', 'in-progress', {
|
|
126
|
-
autoClose: false,
|
|
127
|
-
progress: 0
|
|
128
|
-
});
|
|
129
|
-
try {
|
|
130
|
-
void model.initialize(report => {
|
|
131
|
-
const { progress, text } = report;
|
|
132
|
-
if (progress === 1) {
|
|
133
|
-
Notification.update({
|
|
134
|
-
id: notification,
|
|
135
|
-
progress: 1,
|
|
136
|
-
message: `Model ${model.model} loaded successfully`,
|
|
137
|
-
type: 'success',
|
|
138
|
-
autoClose: 2000
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
Notification.update({
|
|
143
|
-
id: notification,
|
|
144
|
-
progress: progress / 1,
|
|
145
|
-
message: text,
|
|
146
|
-
type: 'in-progress'
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
catch (err) {
|
|
151
|
-
Notification.update({
|
|
152
|
-
id: notification,
|
|
153
|
-
progress: 1,
|
|
154
|
-
message: `Error loading model ${model.model}`,
|
|
155
|
-
type: 'error',
|
|
156
|
-
autoClose: 2000
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Register all default AI providers.
|
|
165
|
-
*/
|
|
166
|
-
const aiProviderPlugins = AIProviders.map(provider => {
|
|
167
|
-
return {
|
|
168
|
-
id: `@jupyterlite/ai:${provider.name}`,
|
|
169
|
-
autoStart: true,
|
|
170
|
-
requires: [IAIProviderRegistry],
|
|
171
|
-
activate: (app, registry) => {
|
|
172
|
-
registry.add(provider);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
export const defaultProviderPlugins = [
|
|
177
|
-
webLLMProviderPlugin,
|
|
178
|
-
...aiProviderPlugins
|
|
179
|
-
];
|
package/lib/provider.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
2
|
-
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
3
|
-
import { ISignal } from '@lumino/signaling';
|
|
4
|
-
import { JSONSchema7 } from 'json-schema';
|
|
5
|
-
import { ISecretsManager } from 'jupyter-secrets-manager';
|
|
6
|
-
import { IAIProvider, IAIProviderRegistry, ModelRole } from './tokens';
|
|
7
|
-
import { AIChatModel, AICompleter } from './types/ai-model';
|
|
8
|
-
export declare class AIProviderRegistry implements IAIProviderRegistry {
|
|
9
|
-
/**
|
|
10
|
-
* The constructor of the provider registry.
|
|
11
|
-
*/
|
|
12
|
-
constructor(options: AIProviderRegistry.IOptions);
|
|
13
|
-
/**
|
|
14
|
-
* Get the list of provider names.
|
|
15
|
-
*/
|
|
16
|
-
get providers(): string[];
|
|
17
|
-
/**
|
|
18
|
-
* Add a new provider.
|
|
19
|
-
*/
|
|
20
|
-
add(provider: IAIProvider): void;
|
|
21
|
-
/**
|
|
22
|
-
* Get the current provider name.
|
|
23
|
-
*/
|
|
24
|
-
currentName(role: ModelRole): string;
|
|
25
|
-
/**
|
|
26
|
-
* Get the current AICompleter.
|
|
27
|
-
*/
|
|
28
|
-
get currentCompleter(): AICompleter | null;
|
|
29
|
-
/**
|
|
30
|
-
* Getter/setter for the completer system prompt.
|
|
31
|
-
*/
|
|
32
|
-
get completerSystemPrompt(): string;
|
|
33
|
-
set completerSystemPrompt(value: string);
|
|
34
|
-
/**
|
|
35
|
-
* Get the current AIChatModel.
|
|
36
|
-
*/
|
|
37
|
-
get currentChatModel(): AIChatModel | null;
|
|
38
|
-
/**
|
|
39
|
-
* Getter/setter for the chat system prompt.
|
|
40
|
-
*/
|
|
41
|
-
get chatSystemPrompt(): string;
|
|
42
|
-
set chatSystemPrompt(value: string);
|
|
43
|
-
/**
|
|
44
|
-
* Get the settings schema of a given provider.
|
|
45
|
-
*/
|
|
46
|
-
getSettingsSchema(provider: string): JSONSchema7;
|
|
47
|
-
/**
|
|
48
|
-
* Get the instructions of a given provider.
|
|
49
|
-
*/
|
|
50
|
-
getInstructions(provider: string): string | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Get the compatibility check function of a given provider.
|
|
53
|
-
*/
|
|
54
|
-
getCompatibilityCheck(provider: string): (() => Promise<string | null>) | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Format an error message from the current provider.
|
|
57
|
-
*/
|
|
58
|
-
formatErrorMessage(error: any): string;
|
|
59
|
-
/**
|
|
60
|
-
* Get/set the current chat error;
|
|
61
|
-
*/
|
|
62
|
-
get chatError(): string;
|
|
63
|
-
private set chatError(value);
|
|
64
|
-
/**
|
|
65
|
-
* Get/set the current completer error.
|
|
66
|
-
*/
|
|
67
|
-
get completerError(): string;
|
|
68
|
-
private set completerError(value);
|
|
69
|
-
/**
|
|
70
|
-
* A function to emit a notification error.
|
|
71
|
-
*/
|
|
72
|
-
private _emitErrorNotification;
|
|
73
|
-
/**
|
|
74
|
-
* Set the completer provider.
|
|
75
|
-
* Creates the provider if the name has changed, otherwise only updates its config.
|
|
76
|
-
*
|
|
77
|
-
* @param options - An object with the name and the settings of the provider to use.
|
|
78
|
-
*/
|
|
79
|
-
setCompleterProvider(settings: ReadonlyPartialJSONObject): Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* Set the chat provider.
|
|
82
|
-
* Creates the provider if the name has changed, otherwise only updates its config.
|
|
83
|
-
*
|
|
84
|
-
* @param options - An object with the name and the settings of the provider to use.
|
|
85
|
-
*/
|
|
86
|
-
setChatProvider(settings: ReadonlyPartialJSONObject): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* A signal emitting when the provider or its settings has changed.
|
|
89
|
-
*/
|
|
90
|
-
get providerChanged(): ISignal<IAIProviderRegistry, ModelRole>;
|
|
91
|
-
/**
|
|
92
|
-
* Build a new settings object containing the secrets.
|
|
93
|
-
*/
|
|
94
|
-
private _buildFullSettings;
|
|
95
|
-
private _secretsManager;
|
|
96
|
-
private _providerChanged;
|
|
97
|
-
private _chatError;
|
|
98
|
-
private _completerError;
|
|
99
|
-
private _notifications;
|
|
100
|
-
private _deferredProvider;
|
|
101
|
-
private _chatPrompt;
|
|
102
|
-
private _completerPrompt;
|
|
103
|
-
}
|
|
104
|
-
export declare namespace AIProviderRegistry {
|
|
105
|
-
/**
|
|
106
|
-
* The options for the LLM provider.
|
|
107
|
-
*/
|
|
108
|
-
interface IOptions {
|
|
109
|
-
/**
|
|
110
|
-
* The secrets manager used in the application.
|
|
111
|
-
*/
|
|
112
|
-
secretsManager?: ISecretsManager;
|
|
113
|
-
/**
|
|
114
|
-
* The token used to request the secrets manager.
|
|
115
|
-
*/
|
|
116
|
-
token: symbol;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* The options for the Chat system prompt.
|
|
120
|
-
*/
|
|
121
|
-
interface IPromptOptions {
|
|
122
|
-
/**
|
|
123
|
-
* The provider name.
|
|
124
|
-
*/
|
|
125
|
-
provider_name: string;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* This function indicates whether a key is writable in an object.
|
|
129
|
-
* https://stackoverflow.com/questions/54724875/can-we-check-whether-property-is-readonly-in-typescript
|
|
130
|
-
*
|
|
131
|
-
* @param obj - An object extending the BaseLanguageModel interface.
|
|
132
|
-
* @param key - A string as a key of the object.
|
|
133
|
-
* @returns a boolean whether the key is writable or not.
|
|
134
|
-
*/
|
|
135
|
-
function isWritable<T extends BaseLanguageModel>(obj: T, key: keyof T): boolean;
|
|
136
|
-
/**
|
|
137
|
-
* Update the config of a language model.
|
|
138
|
-
* It only updates the writable attributes of the model.
|
|
139
|
-
*
|
|
140
|
-
* @param model - the model to update.
|
|
141
|
-
* @param settings - the configuration s a JSON object.
|
|
142
|
-
*/
|
|
143
|
-
function updateConfig<T extends BaseLanguageModel>(model: T, settings: ReadonlyPartialJSONObject): void;
|
|
144
|
-
}
|