@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.
- 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
package/lib/chat-handler.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ChatCommand, AbstractChatContext, AbstractChatModel, IChatCommandProvider, IChatContext, IChatHistory, IChatMessage, IChatModel, IInputModel, INewMessage } from '@jupyter/chat';
|
|
2
|
-
import { IAIProviderRegistry } from './tokens';
|
|
3
|
-
import { AIChatModel } from './types/ai-model';
|
|
4
|
-
export declare const welcomeMessage: (providers: string[]) => string;
|
|
5
|
-
export type ConnectionMessage = {
|
|
6
|
-
type: 'connection';
|
|
7
|
-
client_id: string;
|
|
8
|
-
};
|
|
9
|
-
export declare class ChatHandler extends AbstractChatModel {
|
|
10
|
-
constructor(options: ChatHandler.IOptions);
|
|
11
|
-
get provider(): AIChatModel | null;
|
|
12
|
-
/**
|
|
13
|
-
* Getter and setter for the persona name.
|
|
14
|
-
*/
|
|
15
|
-
get personaName(): string;
|
|
16
|
-
set personaName(value: string);
|
|
17
|
-
/**
|
|
18
|
-
* Get/set the system prompt for the chat.
|
|
19
|
-
*/
|
|
20
|
-
get systemPrompt(): string;
|
|
21
|
-
sendMessage(message: INewMessage): Promise<boolean>;
|
|
22
|
-
getHistory(): Promise<IChatHistory>;
|
|
23
|
-
dispose(): void;
|
|
24
|
-
messageAdded(message: IChatMessage): void;
|
|
25
|
-
stopStreaming(): void;
|
|
26
|
-
createChatContext(): IChatContext;
|
|
27
|
-
private _providerRegistry;
|
|
28
|
-
private _personaName;
|
|
29
|
-
private _errorMessage;
|
|
30
|
-
private _history;
|
|
31
|
-
private _defaultErrorMessage;
|
|
32
|
-
private _controller;
|
|
33
|
-
}
|
|
34
|
-
export declare namespace ChatHandler {
|
|
35
|
-
/**
|
|
36
|
-
* The options used to create a chat handler.
|
|
37
|
-
*/
|
|
38
|
-
interface IOptions extends IChatModel.IOptions {
|
|
39
|
-
providerRegistry: IAIProviderRegistry;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The minimal chat context.
|
|
43
|
-
*/
|
|
44
|
-
class ChatContext extends AbstractChatContext {
|
|
45
|
-
users: never[];
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The chat command provider for the chat.
|
|
49
|
-
*/
|
|
50
|
-
class ClearCommandProvider implements IChatCommandProvider {
|
|
51
|
-
id: string;
|
|
52
|
-
private _slash_commands;
|
|
53
|
-
listCommandCompletions(inputModel: IInputModel): Promise<ChatCommand[]>;
|
|
54
|
-
onSubmit(inputModel: IInputModel): Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
}
|
package/lib/chat-handler.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Jupyter Development Team.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
import { AbstractChatContext, AbstractChatModel } from '@jupyter/chat';
|
|
6
|
-
import { AIMessage, HumanMessage, mergeMessageRuns, SystemMessage } from '@langchain/core/messages';
|
|
7
|
-
import { UUID } from '@lumino/coreutils';
|
|
8
|
-
import { DEFAULT_CHAT_SYSTEM_PROMPT } from './default-prompts';
|
|
9
|
-
import { jupyternautLiteIcon } from './icons';
|
|
10
|
-
/**
|
|
11
|
-
* The base64 encoded SVG string of the jupyternaut lite icon.
|
|
12
|
-
* Encode so it can be passed as avatar_url to jupyter-chat.
|
|
13
|
-
*/
|
|
14
|
-
const AI_AVATAR_BASE64 = btoa(jupyternautLiteIcon.svgstr);
|
|
15
|
-
const AI_AVATAR = `data:image/svg+xml;base64,${AI_AVATAR_BASE64}`;
|
|
16
|
-
export const welcomeMessage = (providers) => `
|
|
17
|
-
#### Ask JupyterLite AI
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
The provider to use can be set in the <button data-commandLinker-command="settingeditor:open" data-commandLinker-args='{"query": "AI provider"}' href="#">settings editor</button>, by selecting it from
|
|
21
|
-
the <img src="${AI_AVATAR}" width="16" height="16"> _AI provider_ settings.
|
|
22
|
-
|
|
23
|
-
The current providers that are available are _${providers.sort().join('_, _')}_.
|
|
24
|
-
|
|
25
|
-
To clear the chat, you can use the \`/clear\` command from the chat input.
|
|
26
|
-
`;
|
|
27
|
-
export class ChatHandler extends AbstractChatModel {
|
|
28
|
-
constructor(options) {
|
|
29
|
-
super(options);
|
|
30
|
-
this._providerRegistry = options.providerRegistry;
|
|
31
|
-
this._providerRegistry.providerChanged.connect(() => {
|
|
32
|
-
this._errorMessage = this._providerRegistry.chatError;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
get provider() {
|
|
36
|
-
return this._providerRegistry.currentChatModel;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Getter and setter for the persona name.
|
|
40
|
-
*/
|
|
41
|
-
get personaName() {
|
|
42
|
-
return this._personaName;
|
|
43
|
-
}
|
|
44
|
-
set personaName(value) {
|
|
45
|
-
this.messages.forEach(message => {
|
|
46
|
-
if (message.sender.username === this._personaName) {
|
|
47
|
-
const updated = { ...message };
|
|
48
|
-
updated.sender.username = value;
|
|
49
|
-
this.messageAdded(updated);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
this._personaName = value;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get/set the system prompt for the chat.
|
|
56
|
-
*/
|
|
57
|
-
get systemPrompt() {
|
|
58
|
-
return (this._providerRegistry.chatSystemPrompt ?? DEFAULT_CHAT_SYSTEM_PROMPT);
|
|
59
|
-
}
|
|
60
|
-
async sendMessage(message) {
|
|
61
|
-
const body = message.body;
|
|
62
|
-
if (body.startsWith('/clear')) {
|
|
63
|
-
// TODO: do we need a clear method?
|
|
64
|
-
this.messagesDeleted(0, this.messages.length);
|
|
65
|
-
this._history.messages = [];
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
message.id = UUID.uuid4();
|
|
69
|
-
const msg = {
|
|
70
|
-
id: message.id,
|
|
71
|
-
body,
|
|
72
|
-
sender: { username: 'User' },
|
|
73
|
-
time: Private.getTimestampMs(),
|
|
74
|
-
type: 'msg'
|
|
75
|
-
};
|
|
76
|
-
this.messageAdded(msg);
|
|
77
|
-
if (this._providerRegistry.currentChatModel === null) {
|
|
78
|
-
const errorMsg = {
|
|
79
|
-
id: UUID.uuid4(),
|
|
80
|
-
body: `**${this._errorMessage ? this._errorMessage : this._defaultErrorMessage}**`,
|
|
81
|
-
sender: { username: 'ERROR' },
|
|
82
|
-
time: Private.getTimestampMs(),
|
|
83
|
-
type: 'msg'
|
|
84
|
-
};
|
|
85
|
-
this.messageAdded(errorMsg);
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
this._history.messages.push(msg);
|
|
89
|
-
const messages = mergeMessageRuns([new SystemMessage(this.systemPrompt)]);
|
|
90
|
-
messages.push(...this._history.messages.map(msg => {
|
|
91
|
-
if (msg.sender.username === 'User') {
|
|
92
|
-
return new HumanMessage(msg.body);
|
|
93
|
-
}
|
|
94
|
-
return new AIMessage(msg.body);
|
|
95
|
-
}));
|
|
96
|
-
const sender = { username: this._personaName, avatar_url: AI_AVATAR };
|
|
97
|
-
this.updateWriters([{ user: sender }]);
|
|
98
|
-
// create an empty message to be filled by the AI provider
|
|
99
|
-
const botMsg = {
|
|
100
|
-
id: UUID.uuid4(),
|
|
101
|
-
body: '',
|
|
102
|
-
sender,
|
|
103
|
-
time: Private.getTimestampMs(),
|
|
104
|
-
type: 'msg'
|
|
105
|
-
};
|
|
106
|
-
let content = '';
|
|
107
|
-
this._controller = new AbortController();
|
|
108
|
-
try {
|
|
109
|
-
for await (const chunk of await this._providerRegistry.currentChatModel.stream(messages, { signal: this._controller.signal })) {
|
|
110
|
-
content += chunk.content ?? chunk;
|
|
111
|
-
botMsg.body = content;
|
|
112
|
-
this.messageAdded(botMsg);
|
|
113
|
-
}
|
|
114
|
-
this._history.messages.push(botMsg);
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
catch (reason) {
|
|
118
|
-
const error = this._providerRegistry.formatErrorMessage(reason);
|
|
119
|
-
const errorMsg = {
|
|
120
|
-
id: UUID.uuid4(),
|
|
121
|
-
body: `**${error}**`,
|
|
122
|
-
sender: { username: 'ERROR' },
|
|
123
|
-
time: Private.getTimestampMs(),
|
|
124
|
-
type: 'msg'
|
|
125
|
-
};
|
|
126
|
-
this.messageAdded(errorMsg);
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
finally {
|
|
130
|
-
this.updateWriters([]);
|
|
131
|
-
this._controller = null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async getHistory() {
|
|
135
|
-
return this._history;
|
|
136
|
-
}
|
|
137
|
-
dispose() {
|
|
138
|
-
super.dispose();
|
|
139
|
-
}
|
|
140
|
-
messageAdded(message) {
|
|
141
|
-
super.messageAdded(message);
|
|
142
|
-
}
|
|
143
|
-
stopStreaming() {
|
|
144
|
-
this._controller?.abort();
|
|
145
|
-
}
|
|
146
|
-
createChatContext() {
|
|
147
|
-
return new ChatHandler.ChatContext({ model: this });
|
|
148
|
-
}
|
|
149
|
-
_providerRegistry;
|
|
150
|
-
_personaName = 'AI';
|
|
151
|
-
_errorMessage = '';
|
|
152
|
-
_history = { messages: [] };
|
|
153
|
-
_defaultErrorMessage = 'AI provider not configured';
|
|
154
|
-
_controller = null;
|
|
155
|
-
}
|
|
156
|
-
(function (ChatHandler) {
|
|
157
|
-
/**
|
|
158
|
-
* The minimal chat context.
|
|
159
|
-
*/
|
|
160
|
-
class ChatContext extends AbstractChatContext {
|
|
161
|
-
users = [];
|
|
162
|
-
}
|
|
163
|
-
ChatHandler.ChatContext = ChatContext;
|
|
164
|
-
/**
|
|
165
|
-
* The chat command provider for the chat.
|
|
166
|
-
*/
|
|
167
|
-
class ClearCommandProvider {
|
|
168
|
-
id = '@jupyterlite/ai:clear-commands';
|
|
169
|
-
_slash_commands = [
|
|
170
|
-
{
|
|
171
|
-
name: '/clear',
|
|
172
|
-
providerId: this.id,
|
|
173
|
-
replaceWith: '/clear',
|
|
174
|
-
description: 'Clear the chat'
|
|
175
|
-
}
|
|
176
|
-
];
|
|
177
|
-
async listCommandCompletions(inputModel) {
|
|
178
|
-
const match = inputModel.currentWord?.match(/^\/\w*/)?.[0];
|
|
179
|
-
if (!match) {
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
const commands = this._slash_commands.filter(cmd => cmd.name.startsWith(match));
|
|
183
|
-
return commands;
|
|
184
|
-
}
|
|
185
|
-
async onSubmit(inputModel) {
|
|
186
|
-
// no handling needed because `replaceWith` is set in each command.
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
ChatHandler.ClearCommandProvider = ClearCommandProvider;
|
|
191
|
-
})(ChatHandler || (ChatHandler = {}));
|
|
192
|
-
var Private;
|
|
193
|
-
(function (Private) {
|
|
194
|
-
/**
|
|
195
|
-
* Return the current timestamp in milliseconds.
|
|
196
|
-
*/
|
|
197
|
-
function getTimestampMs() {
|
|
198
|
-
return Date.now() / 1000;
|
|
199
|
-
}
|
|
200
|
-
Private.getTimestampMs = getTimestampMs;
|
|
201
|
-
})(Private || (Private = {}));
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CompletionHandler, IInlineCompletionContext, IInlineCompletionProvider } from '@jupyterlab/completer';
|
|
2
|
-
import { IAIProviderRegistry } from './tokens';
|
|
3
|
-
import { AICompleter } from './types/ai-model';
|
|
4
|
-
/**
|
|
5
|
-
* The generic completion provider to register to the completion provider manager.
|
|
6
|
-
*/
|
|
7
|
-
export declare class CompletionProvider implements IInlineCompletionProvider {
|
|
8
|
-
readonly identifier = "@jupyterlite/ai";
|
|
9
|
-
constructor(options: CompletionProvider.IOptions);
|
|
10
|
-
/**
|
|
11
|
-
* Get the current completer name.
|
|
12
|
-
*/
|
|
13
|
-
get name(): string;
|
|
14
|
-
/**
|
|
15
|
-
* Get the current completer.
|
|
16
|
-
*/
|
|
17
|
-
get completer(): AICompleter | null;
|
|
18
|
-
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<any>;
|
|
19
|
-
private _providerRegistry;
|
|
20
|
-
private _requestCompletion;
|
|
21
|
-
}
|
|
22
|
-
export declare namespace CompletionProvider {
|
|
23
|
-
interface IOptions {
|
|
24
|
-
/**
|
|
25
|
-
* The registry where the completion provider belongs.
|
|
26
|
-
*/
|
|
27
|
-
providerRegistry: IAIProviderRegistry;
|
|
28
|
-
/**
|
|
29
|
-
* The request completion commands, can be useful if a provider needs to request
|
|
30
|
-
* the completion by itself.
|
|
31
|
-
*/
|
|
32
|
-
requestCompletion: () => void;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The generic completion provider to register to the completion provider manager.
|
|
3
|
-
*/
|
|
4
|
-
export class CompletionProvider {
|
|
5
|
-
identifier = '@jupyterlite/ai';
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this._providerRegistry = options.providerRegistry;
|
|
8
|
-
this._requestCompletion = options.requestCompletion;
|
|
9
|
-
this._providerRegistry.providerChanged.connect(() => {
|
|
10
|
-
if (this.completer) {
|
|
11
|
-
this.completer.requestCompletion = this._requestCompletion;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Get the current completer name.
|
|
17
|
-
*/
|
|
18
|
-
get name() {
|
|
19
|
-
return this._providerRegistry.currentName('completer');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get the current completer.
|
|
23
|
-
*/
|
|
24
|
-
get completer() {
|
|
25
|
-
return this._providerRegistry.currentCompleter;
|
|
26
|
-
}
|
|
27
|
-
async fetch(request, context) {
|
|
28
|
-
return this.completer?.fetch(request, context);
|
|
29
|
-
}
|
|
30
|
-
_providerRegistry;
|
|
31
|
-
_requestCompletion;
|
|
32
|
-
}
|
package/lib/default-prompts.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_CHAT_SYSTEM_PROMPT = "\nYou are Jupyternaut, a conversational assistant living in JupyterLab to help users.\nYou are not a language model, but rather an application built on a foundation model from $provider_name$.\nYou are talkative and you provide lots of specific details from the foundation model's context.\nYou may use Markdown to format your response.\nIf your response includes code, they must be enclosed in Markdown fenced code blocks (with triple backticks before and after).\nIf your response includes mathematical notation, they must be expressed in LaTeX markup and enclosed in LaTeX delimiters.\nAll dollar quantities (of USD) must be formatted in LaTeX, with the `$` symbol escaped by a single backslash `\\`.\n- Example prompt: `If I have \\\\$100 and spend \\\\$20, how much money do I have left?`\n- **Correct** response: `You have \\(\\$80\\) remaining.`\n- **Incorrect** response: `You have $80 remaining.`\nIf you do not know the answer to a question, answer truthfully by responding that you do not know.\nThe following is a friendly conversation between you and a human.\n";
|
|
2
|
-
export declare const DEFAULT_COMPLETION_SYSTEM_PROMPT = "\nYou are an application built to provide helpful code completion suggestions.\nYou should only produce code. Keep comments to minimum, use the\nprogramming language comment syntax. Produce clean code.\nThe code is written in JupyterLab, a data analysis and code development\nenvironment which can execute code extended with additional syntax for\ninteractive features, such as magics.\nOnly give raw strings back, do not format the response using backticks.\nThe output should be a single string, and should only contain the code that will complete the\ngive code passed as input, no explanation whatsoever.\nDo not include the prompt in the output, only the string that should be appended to the current input.\nHere is the code to complete:\n";
|
package/lib/default-prompts.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Jupyter Development Team.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
export const DEFAULT_CHAT_SYSTEM_PROMPT = `
|
|
6
|
-
You are Jupyternaut, a conversational assistant living in JupyterLab to help users.
|
|
7
|
-
You are not a language model, but rather an application built on a foundation model from $provider_name$.
|
|
8
|
-
You are talkative and you provide lots of specific details from the foundation model's context.
|
|
9
|
-
You may use Markdown to format your response.
|
|
10
|
-
If your response includes code, they must be enclosed in Markdown fenced code blocks (with triple backticks before and after).
|
|
11
|
-
If your response includes mathematical notation, they must be expressed in LaTeX markup and enclosed in LaTeX delimiters.
|
|
12
|
-
All dollar quantities (of USD) must be formatted in LaTeX, with the \`$\` symbol escaped by a single backslash \`\\\`.
|
|
13
|
-
- Example prompt: \`If I have \\\\$100 and spend \\\\$20, how much money do I have left?\`
|
|
14
|
-
- **Correct** response: \`You have \\(\\$80\\) remaining.\`
|
|
15
|
-
- **Incorrect** response: \`You have $80 remaining.\`
|
|
16
|
-
If you do not know the answer to a question, answer truthfully by responding that you do not know.
|
|
17
|
-
The following is a friendly conversation between you and a human.
|
|
18
|
-
`;
|
|
19
|
-
export const DEFAULT_COMPLETION_SYSTEM_PROMPT = `
|
|
20
|
-
You are an application built to provide helpful code completion suggestions.
|
|
21
|
-
You should only produce code. Keep comments to minimum, use the
|
|
22
|
-
programming language comment syntax. Produce clean code.
|
|
23
|
-
The code is written in JupyterLab, a data analysis and code development
|
|
24
|
-
environment which can execute code extended with additional syntax for
|
|
25
|
-
interactive features, such as magics.
|
|
26
|
-
Only give raw strings back, do not format the response using backticks.
|
|
27
|
-
The output should be a single string, and should only contain the code that will complete the
|
|
28
|
-
give code passed as input, no explanation whatsoever.
|
|
29
|
-
Do not include the prompt in the output, only the string that should be appended to the current input.
|
|
30
|
-
Here is the code to complete:
|
|
31
|
-
`;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
3
|
-
import { BaseCompleter } from '../../base-completer';
|
|
4
|
-
export declare class AnthropicCompleter extends BaseCompleter {
|
|
5
|
-
constructor(options: BaseCompleter.IOptions);
|
|
6
|
-
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
7
|
-
items: {
|
|
8
|
-
insertText: string;
|
|
9
|
-
}[];
|
|
10
|
-
}>;
|
|
11
|
-
protected _completer: ChatAnthropic;
|
|
12
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ChatAnthropic } from '@langchain/anthropic';
|
|
2
|
-
import { AIMessage, SystemMessage } from '@langchain/core/messages';
|
|
3
|
-
import { BaseCompleter } from '../../base-completer';
|
|
4
|
-
export class AnthropicCompleter extends BaseCompleter {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super(options);
|
|
7
|
-
this._completer = new ChatAnthropic({ ...options.settings });
|
|
8
|
-
}
|
|
9
|
-
async fetch(request, context) {
|
|
10
|
-
const { text, offset: cursorOffset } = request;
|
|
11
|
-
const prompt = text.slice(0, cursorOffset);
|
|
12
|
-
// Anthropic does not allow whitespace at the end of the AIMessage
|
|
13
|
-
const trimmedPrompt = prompt.trim();
|
|
14
|
-
const messages = [
|
|
15
|
-
new SystemMessage(this.systemPrompt),
|
|
16
|
-
new AIMessage(trimmedPrompt)
|
|
17
|
-
];
|
|
18
|
-
try {
|
|
19
|
-
const response = await this._completer.invoke(messages);
|
|
20
|
-
const items = [];
|
|
21
|
-
// Anthropic can return string or complex content, a list of string/images/other.
|
|
22
|
-
if (typeof response.content === 'string') {
|
|
23
|
-
items.push({
|
|
24
|
-
insertText: response.content
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
response.content.forEach(content => {
|
|
29
|
-
if (content.type !== 'text') {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
items.push({
|
|
33
|
-
insertText: content.text,
|
|
34
|
-
filterText: prompt.substring(trimmedPrompt.length)
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return { items };
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error('Error fetching completions', error);
|
|
42
|
-
return { items: [] };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
_completer;
|
|
46
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"type": "object",
|
|
4
|
-
"properties": {
|
|
5
|
-
"temperature": {
|
|
6
|
-
"type": "number",
|
|
7
|
-
"description": "Amount of randomness injected into the response. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and temp closer to 1 for creative and generative tasks."
|
|
8
|
-
},
|
|
9
|
-
"topK": {
|
|
10
|
-
"type": "number",
|
|
11
|
-
"description": "Only sample from the top K options for each subsequent token. Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it."
|
|
12
|
-
},
|
|
13
|
-
"topP": {
|
|
14
|
-
"type": "number",
|
|
15
|
-
"description": "Does nucleus sampling, in which we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. Defaults to -1, which disables it. Note that you should either alter temperature or top_p, but not both."
|
|
16
|
-
},
|
|
17
|
-
"maxTokens": {
|
|
18
|
-
"type": "number",
|
|
19
|
-
"description": "A maximum number of tokens to generate before stopping."
|
|
20
|
-
},
|
|
21
|
-
"maxTokensToSample": {
|
|
22
|
-
"type": "number",
|
|
23
|
-
"description": "A maximum number of tokens to generate before stopping.",
|
|
24
|
-
"deprecated": "Use \"maxTokens\" instead."
|
|
25
|
-
},
|
|
26
|
-
"stopSequences": {
|
|
27
|
-
"type": "array",
|
|
28
|
-
"items": {
|
|
29
|
-
"type": "string"
|
|
30
|
-
},
|
|
31
|
-
"description": "A list of strings upon which to stop generating. You probably want `[\"\\n\\nHuman:\"]`, as that's the cue for the next turn in the dialog agent."
|
|
32
|
-
},
|
|
33
|
-
"streaming": {
|
|
34
|
-
"type": "boolean",
|
|
35
|
-
"description": "Whether to stream the results or not"
|
|
36
|
-
},
|
|
37
|
-
"anthropicApiKey": {
|
|
38
|
-
"type": "string",
|
|
39
|
-
"description": "Anthropic API key"
|
|
40
|
-
},
|
|
41
|
-
"apiKey": {
|
|
42
|
-
"type": "string",
|
|
43
|
-
"description": "Anthropic API key"
|
|
44
|
-
},
|
|
45
|
-
"anthropicApiUrl": {
|
|
46
|
-
"type": "string",
|
|
47
|
-
"description": "Anthropic API URL"
|
|
48
|
-
},
|
|
49
|
-
"modelName": {
|
|
50
|
-
"type": "string",
|
|
51
|
-
"deprecated": "Use \"model\" instead"
|
|
52
|
-
},
|
|
53
|
-
"model": {
|
|
54
|
-
"type": "string",
|
|
55
|
-
"description": "Model name to use"
|
|
56
|
-
},
|
|
57
|
-
"invocationKwargs": {
|
|
58
|
-
"type": "object",
|
|
59
|
-
"description": "Holds any additional parameters that are valid to pass to {@link * https://console.anthropic.com/docs/api/reference | } * `anthropic.messages`} that are not explicitly specified on this class."
|
|
60
|
-
},
|
|
61
|
-
"streamUsage": {
|
|
62
|
-
"type": "boolean",
|
|
63
|
-
"description": "Whether or not to include token usage data in streamed chunks.",
|
|
64
|
-
"default": false
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
"additionalProperties": false,
|
|
68
|
-
"description": "Input to AnthropicChat class.",
|
|
69
|
-
"definitions": {}
|
|
70
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
-
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
|
|
3
|
-
import { BaseCompleter } from '../../base-completer';
|
|
4
|
-
export declare class ChromeCompleter extends BaseCompleter {
|
|
5
|
-
constructor(options: BaseCompleter.IOptions);
|
|
6
|
-
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
7
|
-
items: {
|
|
8
|
-
insertText: string;
|
|
9
|
-
}[];
|
|
10
|
-
}>;
|
|
11
|
-
protected _completer: ChromeAI;
|
|
12
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
|
|
2
|
-
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
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 ChromeCompleter extends BaseCompleter {
|
|
24
|
-
constructor(options) {
|
|
25
|
-
super(options);
|
|
26
|
-
this._completer = new ChromeAI({ ...options.settings });
|
|
27
|
-
}
|
|
28
|
-
async fetch(request, context) {
|
|
29
|
-
const { text, offset: cursorOffset } = request;
|
|
30
|
-
const prompt = text.slice(0, cursorOffset);
|
|
31
|
-
const trimmedPrompt = prompt.trim();
|
|
32
|
-
const messages = [
|
|
33
|
-
new SystemMessage(this.systemPrompt),
|
|
34
|
-
new HumanMessage(trimmedPrompt)
|
|
35
|
-
];
|
|
36
|
-
try {
|
|
37
|
-
let response = await this._completer.invoke(messages);
|
|
38
|
-
// ChromeAI sometimes returns a string starting with '```',
|
|
39
|
-
// so process the response to remove the code block delimiters
|
|
40
|
-
if (CODE_BLOCK_START_REGEX.test(response)) {
|
|
41
|
-
response = response
|
|
42
|
-
.replace(CODE_BLOCK_START_REGEX, '')
|
|
43
|
-
.replace(CODE_BLOCK_END_REGEX, '');
|
|
44
|
-
}
|
|
45
|
-
const items = [{ insertText: response }];
|
|
46
|
-
return {
|
|
47
|
-
items
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error('Error fetching completion:', error);
|
|
52
|
-
return { items: [] };
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
_completer;
|
|
56
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
declare const _default: "\n<i class=\"fas fa-exclamation-triangle\"></i> Support for ChromeAI is still experimental and only available in Google Chrome.\n\nYou can test ChromeAI is enabled in your browser by going to the following URL: <https://chromeai.org/>\n\nEnable the proper flags in Google Chrome.\n\n- chrome://flags/#prompt-api-for-gemini-nano\n - Select: `Enabled`\n- chrome://flags/#optimization-guide-on-device-model\n - Select: `Enabled BypassPrefRequirement`\n- chrome://components\n - Click `Check for Update` on Optimization Guide On Device Model to download the model\n- [Optional] chrome://flags/#text-safety-classifier\n\n<img src=\"https://github.com/user-attachments/assets/d48f46cc-52ee-4ce5-9eaf-c763cdbee04c\" alt=\"A screenshot showing how to enable the ChromeAI flag in Google Chrome\" width=\"500px\">\n\nThen restart Chrome for these changes to take effect.\n\n<i class=\"fas fa-exclamation-triangle\"></i> On first use, Chrome will download the on-device model, which can be as large as 22GB (according to their docs and at the time of writing).\nDuring the download, ChromeAI may not be available via the extension.\n\n<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i> For more information about Chrome Built-in AI: <https://developer.chrome.com/docs/ai/get-started>\n";
|
|
2
|
-
export default _default;
|
|
3
|
-
/**
|
|
4
|
-
* Check if the browser supports ChromeAI and the model is available.
|
|
5
|
-
*/
|
|
6
|
-
export declare function compatibilityCheck(): Promise<string | null>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export default `
|
|
2
|
-
<i class="fas fa-exclamation-triangle"></i> Support for ChromeAI is still experimental and only available in Google Chrome.
|
|
3
|
-
|
|
4
|
-
You can test ChromeAI is enabled in your browser by going to the following URL: <https://chromeai.org/>
|
|
5
|
-
|
|
6
|
-
Enable the proper flags in Google Chrome.
|
|
7
|
-
|
|
8
|
-
- chrome://flags/#prompt-api-for-gemini-nano
|
|
9
|
-
- Select: \`Enabled\`
|
|
10
|
-
- chrome://flags/#optimization-guide-on-device-model
|
|
11
|
-
- Select: \`Enabled BypassPrefRequirement\`
|
|
12
|
-
- chrome://components
|
|
13
|
-
- Click \`Check for Update\` on Optimization Guide On Device Model to download the model
|
|
14
|
-
- [Optional] chrome://flags/#text-safety-classifier
|
|
15
|
-
|
|
16
|
-
<img src="https://github.com/user-attachments/assets/d48f46cc-52ee-4ce5-9eaf-c763cdbee04c" alt="A screenshot showing how to enable the ChromeAI flag in Google Chrome" width="500px">
|
|
17
|
-
|
|
18
|
-
Then restart Chrome for these changes to take effect.
|
|
19
|
-
|
|
20
|
-
<i class="fas fa-exclamation-triangle"></i> On first use, Chrome will download the on-device model, which can be as large as 22GB (according to their docs and at the time of writing).
|
|
21
|
-
During the download, ChromeAI may not be available via the extension.
|
|
22
|
-
|
|
23
|
-
<i class="fa fa-info-circle" aria-hidden="true"></i> For more information about Chrome Built-in AI: <https://developer.chrome.com/docs/ai/get-started>
|
|
24
|
-
`;
|
|
25
|
-
/**
|
|
26
|
-
* Check if the browser supports ChromeAI and the model is available.
|
|
27
|
-
*/
|
|
28
|
-
export async function compatibilityCheck() {
|
|
29
|
-
// Check if the browser supports the ChromeAI model
|
|
30
|
-
if (typeof window === 'undefined' ||
|
|
31
|
-
!('LanguageModel' in window) ||
|
|
32
|
-
window.LanguageModel === undefined ||
|
|
33
|
-
window.LanguageModel.availability === undefined) {
|
|
34
|
-
return 'Your browser does not support ChromeAI. Please use an updated chrome based browser like Google Chrome, and follow the instructions in settings to enable it.';
|
|
35
|
-
}
|
|
36
|
-
const languageModel = window.LanguageModel;
|
|
37
|
-
if (!(await languageModel.availability())) {
|
|
38
|
-
return 'The ChromeAI model is not available in your browser. Please ensure you have enabled the necessary flags in Google Chrome as described in the instructions in settings.';
|
|
39
|
-
}
|
|
40
|
-
// If the model is available, return null to indicate compatibility
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"type": "object",
|
|
4
|
-
"properties": {
|
|
5
|
-
"concurrency": {
|
|
6
|
-
"type": "number",
|
|
7
|
-
"deprecated": "Use `maxConcurrency` instead"
|
|
8
|
-
},
|
|
9
|
-
"topK": {
|
|
10
|
-
"type": "number"
|
|
11
|
-
},
|
|
12
|
-
"temperature": {
|
|
13
|
-
"type": "number"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"additionalProperties": false,
|
|
17
|
-
"definitions": {}
|
|
18
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CompletionHandler, IInlineCompletionContext } from '@jupyterlab/completer';
|
|
2
|
-
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
3
|
-
import { BaseCompleter } from '../../base-completer';
|
|
4
|
-
export declare class GeminiCompleter extends BaseCompleter {
|
|
5
|
-
constructor(options: BaseCompleter.IOptions);
|
|
6
|
-
fetch(request: CompletionHandler.IRequest, context: IInlineCompletionContext): Promise<{
|
|
7
|
-
items: {
|
|
8
|
-
insertText: string;
|
|
9
|
-
}[];
|
|
10
|
-
}>;
|
|
11
|
-
protected _completer: ChatGoogleGenerativeAI;
|
|
12
|
-
}
|