Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New auto enable mito ai #1495

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 33 additions & 49 deletions mito-ai/src/Extensions/InlineCompleter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const completionPlugin: JupyterFrontEndPlugin<void> = {
requires: [
ICompletionProviderManager,
ISettingRegistry,
IVariableManager
IVariableManager,
],
activate: (
app: JupyterFrontEnd,
completionManager: ICompletionProviderManager,
settingRegistry: ISettingRegistry,
variableManager: IVariableManager
variableManager: IVariableManager,
) => {
if (typeof completionManager.registerInlineProvider === 'undefined') {
// Gracefully short-circuit on JupyterLab 4.0 and Notebook 7.0
Expand Down Expand Up @@ -92,57 +92,41 @@ export const completionPlugin: JupyterFrontEndPlugin<void> = {
};

if (!providers['mito-ai']['enabled']) {

/* The first time the user installs Mito AI, we take a few actions*/

// 1. Dispaly welcome notification
Notification.info(
'Thanks for installing the Mito AI extension. Do you want to enable the Mito AI inline completer?',
'Mito AI is now enabled!',
{
autoClose: false,
actions: [
{
label: 'Enable',
displayType: 'accent',
callback: async () => {
if (
providers['@jupyterlab/inline-completer:history']?.[
'enabled'
] !== false
) {
providers['@jupyterlab/inline-completer:history'][
'enabled'
] = false;
}
providers['mito-ai']['enabled'] = true;
await settingRegistry.set(
JUPYTERLAB_INLINE_COMPLETER_ID,
'providers',
providers
);

// For some reason, it seems that unless the Tab shortcut is registered first,
// Jupyter does not accept it. So we try removing the existing shortcut.
shortcuts = shortcuts.filter((shortcut: {command: string}) => shortcut.command !== 'inline-completer:accept');
shortcuts.push({
command: 'inline-completer:accept',
keys: ['Tab'],
selector: '.jp-mod-inline-completer-active'
});
await settingRegistry.set(
JUPYTERLAB_SHORTCUTS_ID,
'shortcuts',
shortcuts
);
updateConfig();
}
},
{
label: 'Not now',
callback: () => {
updateConfig();
}
}
]
autoClose: 10000
}
);
} else {

// 2. Disable the default inline completer
if (providers['@jupyterlab/inline-completer:history']?.['enabled'] !== false) {
providers['@jupyterlab/inline-completer:history']['enabled'] = false;
}

// 3. Enable the Mito AI inline completer
providers['mito-ai']['enabled'] = true;
await settingRegistry.set(JUPYTERLAB_INLINE_COMPLETER_ID, 'providers', providers);

// 4. Set Tab as the accept button for autocomplete.
// For some reason, it seems that unless the Tab shortcut is registered first,
// Jupyter does not accept it. So we try removing the existing shortcut.
shortcuts = shortcuts.filter((shortcut: {command: string}) => shortcut.command !== 'inline-completer:accept');
shortcuts.push({
command: 'inline-completer:accept',
keys: ['Tab'],
selector: '.jp-mod-inline-completer-active'
});
await settingRegistry.set(
JUPYTERLAB_SHORTCUTS_ID,
'shortcuts',
shortcuts
);

updateConfig();
}
};
Expand Down
6 changes: 0 additions & 6 deletions tests/mitoai_ui_tests/basicInlineComplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import {
const GHOST_SELECTOR = ".jp-GhostText";
const THRESHOLD_IN_MS = 5000;

// Before each test, enable inline completion
test.beforeEach(async ({ page }) => {
await page.locator('button:has-text("Enable")').click();
});


test.describe("inline completion integration test", () => {

test('Inline completion', async ({ page }) => {
Expand Down
Loading