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

Add 'Generative AI' submenu #971

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Add 'Generative AI' submenu #971

merged 1 commit into from
Aug 29, 2024

Conversation

dlqqq
Copy link
Member

@dlqqq dlqqq commented Aug 29, 2024

Description

  • This feature is experimental and may be removed in a future release.
  • Adds a "Generative AI" submenu that provides 4 menu items:
    • Explain code
    • Fix code
    • Optimize code
    • Refactor code
  • "Fix code" calls /fix, and only works when a code cell with an error output is selected as the active cell.
  • "{Explain,Optimize,Refactor} code" simply includes the user's selection with a basic prompt {Explain,Optimize,Refactor} the code below.
    • If a text selection exists, that selection is used to provide the code sent to the language model. Otherwise, if an active cell is selected, then that cell's source is used to provide the code. If neither exist, the menu item is disabled.
    • These commands also work outside of notebooks, given any text selection within an editor.
  • When these menu items are invoked, the chat panel is opened automatically if it is not already open.

Demo

Screen.Recording.2024-08-29.at.8.06.48.AM.mov

Future work

  • In the future, the submenu should not be titled "Generative AI", but instead be titled according to the persona of the currently selected language model.
    • So by default, it should read "Jupyternaut". However, if a custom persona "Bagel AI" is used, then the submenu should be titled "Bagel AI".
  • We are also currently exploring an alternative UX for improving code within editors. Work is still in progress. This should however be a good stopgap solution for allowing users to perform basic AI tasks through the UI.

@dlqqq dlqqq added the enhancement New feature or request label Aug 29, 2024
@dlqqq dlqqq self-assigned this Aug 29, 2024
Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the code and it looks great! Awesome PR.

One small note: For the ModuleNotFoundError the fix action is not available. Not sure we want to be that inclusive as it is not a typical error. See:
image
It could add a line of code to install the missing module if fix was possible. See that it works with `/fix' in chat as intended:
image

Great idea to add it to the right-click menu because the Gen AI submenu can be used to add more functionality as needed in addition to the four actions currently included.

@dlqqq
Copy link
Member Author

dlqqq commented Aug 29, 2024

@srdas One weird caveat is that to fix/explain/optimize/refactor a cell, you have to left-click on the cell first to make it the active cell, and then right-click to select the AI task you want to perform.

Right-clicking on a cell does not make it the active cell in JupyterLab. This is existing behavior that is also shown by the other context menu options. See the demo video below, where I right click on a cell that is not the active cell, then click delete. Notice that the cell I right-clicked on is not deleted.

Screen.Recording.2024-08-29.at.1.06.41.PM.mov

@srdas
Copy link
Collaborator

srdas commented Aug 29, 2024

Right-clicking on a cell does not make it the active cell in JupyterLab. This is existing behavior that is also shown by the other context menu options. See the demo video below, where I right click on a cell that is not the active cell, then click delete. Notice that the cell I right-clicked on is not deleted.

@dlqqq Thanks, I retested it and it is working correctly after the left-click + right-click. Perfect!

Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good

@dlqqq dlqqq merged commit 79158ab into jupyterlab:main Aug 29, 2024
9 checks passed
@dlqqq dlqqq deleted the ai-menu branch August 29, 2024 20:18
@brichet brichet mentioned this pull request Sep 12, 2024
11 tasks
Marchlak pushed a commit to Marchlak/jupyter-ai that referenced this pull request Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants