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

support VS Code's Jupyter extension #1244

Open
rootsmusic opened this issue Feb 12, 2025 · 9 comments
Open

support VS Code's Jupyter extension #1244

rootsmusic opened this issue Feb 12, 2025 · 9 comments
Labels
enhancement New feature or request

Comments

@rootsmusic
Copy link

In the docs for Users, please add instructions to configure for use in Visual Studio Code For Windows with .ipynb files.

@rootsmusic rootsmusic added the enhancement New feature or request label Feb 12, 2025
@dlqqq
Copy link
Member

dlqqq commented Feb 17, 2025

@rootsmusic Jupyter AI only officially supports Jupyter Notebook and JupyterLab. As far as I know, there's no way for us to practically support Jupyter AI in VSCode because its frontend is entirely different.

@krassowski Are you aware of any other Jupyter extensions that support Jupyter & VSCode? I don't think anybody has looked into this.

@rootsmusic rootsmusic changed the title DOC: how to configure VS Code support VS Code's Jupyter extension Feb 18, 2025
@krassowski
Copy link
Member

Are you aware of any other Jupyter extensions that support Jupyter & VSCode? I don't think anybody has looked into this.

I believe @ajbozarth looked into this.

But I think in general the jupyter-ai-magics is frontend agnostic, right? Though I do not see why it would require any special configuration for vscode

@srdas
Copy link
Collaborator

srdas commented Feb 20, 2025

There are extensions for VSCode only, such as https://github.com/cline/cline.

@ajbozarth
Copy link
Member

My work eventually went perpindicular to this, I created https://github.com/Qiskit/qiskit-code-assistant-jupyterlab which supports any OpenAI API model to be called by the completer. It did not add any functionality beyond the completer though and that project had its own VSCode extension by the same name.

@rootsmusic
Copy link
Author

rootsmusic commented Feb 20, 2025

@krassowski Since I'm using a conda environment, I ran conda install conda-forge::jupyter-ai-magics. In VS Code For Windows 1.97.2, I opened a new .ipynb file. I ran load_ext jupyter_ai_magics, but the first cell returns the error:

UserWarning: Field "model_id_key" in BaseProvider has conflict with protected namespace "model_".
You may be able to resolve this warning by setting model_config['protected_namespaces'] = ().

@krassowski
Copy link
Member

@rootsmusic It looks like a pydantic version conflict? I believe this has nothing to do with VS Code but something wrong with your environment. Can you run pip check and conda doctor to see if there any suggestions?

@rootsmusic
Copy link
Author

conda doctor shows:
❌ Altered Files:
numpy-base-1.24.3-py310h0a02333_5: 1
scipy-1.10.1-py310hec14841_8: 1
tk-8.6.13-h5226925_1: 10
✅ The environment is listed in the environments.txt file.
✅ There are no packages with missing files.

@krassowski (This environment didn't have errors running numpy. pip check says "No broken requirements found.") Do you think that the UserWarning is related to my environment's altered files?

@rootsmusic
Copy link
Author

rootsmusic commented Feb 20, 2025

@krassowski I've created a clean conda environment and installed ipykernel and jupyter-ai-magics from conda-forge. In VS Code for Windows, I ran import jupyter_ai_magics and load_ext jupyter_ai_magics. When I try to run %ai, the cell returns an error:

UsageError Traceback (most recent call last)
Cell In[5], line 1
----> 1 get_ipython().run_line_magic('ai', '')

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\IPython\core\interactiveshell.py:2482, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2480 kwargs['local_ns'] = self.get_local_scope(stack_depth)
2481 with self.builtin_trap:
-> 2482 result = fn(*args, **kwargs)
2484 # The code below prevents the output from being displayed
2485 # when using magics with decorator @output_can_be_silenced
2486 # when the last Python token in the expression is a ';'.
2487 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\jupyter_ai_magics\magics.py:635, in AiMagics.ai(self, line, cell)
628 args = cell_magic_parser(
629 raw_args,
630 prog_name="%%ai",
631 standalone_mode=False,
632 default_map={"cell_magic_parser": default_map},
633 )
634 else:
--> 635 args = line_magic_parser(
636 raw_args,
637 prog_name="%ai",
638 standalone_mode=False,
639 default_map={"error": default_map},
640 )
642 if args == 0 and self.default_language_model is None:
643 # this happens when --help is called on the root command, in which
644 # case we want to exit early.
645 return

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\click\core.py:1161, in BaseCommand.call(self, *args, **kwargs)
1159 def call(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
1160 """Alias for :meth:main."""
-> 1161 return self.main(*args, **kwargs)

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\click\core.py:1082, in BaseCommand.main(self, args, prog_name, complete_var, standalone_mode, windows_expand_args, **extra)
1080 try:
1081 with self.make_context(prog_name, args, **extra) as ctx:
-> 1082 rv = self.invoke(ctx)
1083 if not standalone_mode:
1084 return rv

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\click\core.py:1691, in MultiCommand.invoke(self, ctx)
1687 if not self.chain:
1688 # Make sure the context is entered so we do not clean up
1689 # resources until the result processor has worked.
1690 with ctx:
-> 1691 cmd_name, cmd, args = self.resolve_command(ctx, args)
1692 assert cmd is not None
1693 ctx.invoked_subcommand = cmd_name

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\click\core.py:1755, in MultiCommand.resolve_command(self, ctx, args)
1753 if split_opt(cmd_name)[0]:
1754 self.parse_args(ctx, ctx.args)
-> 1755 ctx.fail(_("No such command {name!r}.").format(name=original_cmd_name))
1756 return cmd_name if cmd else None, cmd, args[1:]

File c:\ProgramData\anaconda3\envs\idp312\Lib\site-packages\click\core.py:691, in Context.fail(self, message)
685 def fail(self, message: str) -> "te.NoReturn":
686 """Aborts the execution of the program with a specific error
687 message.
688
689 :param message: the error message to fail with.
690 """
--> 691 raise UsageError(message, self)

UsageError: No such command ''.

@krassowski
Copy link
Member

Technically this is a usage error, but the error should be more helpful. What about %ai list? Have a look at https://jupyter-ai.readthedocs.io/en/latest/users/index.html#the-ai-and-ai-magic-commands

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

No branches or pull requests

5 participants