# How to install OpenAI npm package in the Javascript kernel in JupyterLite?

**URL:** https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065
**Category:** Kernels
**Created:** [April 22, 2023, 2:47am UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065 "2023-04-22T02:47:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Work\_LY](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/work_ly/32/9712_2.png) [@Work\_LY](https://discourse.jupyter.org/u/Work_LY)
#### Post date: [April 22, 2023, 2:47am UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065/1 "2023-04-22T02:47:31Z")

</div>

OpenAI’s ChatGPT is very hot. I am willing to try it in JupyterLite with OpenAI’s APIs. So I can access its service in browsers easily, even on mobile.  
But I couldn’t find a way to install it in the Javascript kernel in JupyterLite.  
Any ideas?  
Thank you in advance,

---

<div class="post-metadata">

### Author: ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)
#### Post date: [April 22, 2023, 1:06pm UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065/2 "2023-04-22T13:06:44Z")

</div>

It kinda takes a lot: moved the long post to [this gist](https://gist.github.com/bollwyvl/82ab55902e0291e40893d4586156bb33).

In a nutshell:

- patch imports and importMaps with [jspm](https://jspm.org/)
- do some `async` skullduggery
- put your key in
- greet AI overlords, if that’s what you’re into (i didn’t bother trying)

As a bonus, a second notebook shows how to use the Pyodide JS compatibility layer to basically do the same thing in python, and it’s actually not too bad to read.

---

<div class="post-metadata">

### Author: ![Work\_LY](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/work_ly/32/9712_2.png) [@Work\_LY](https://discourse.jupyter.org/u/Work_LY)
#### Post date: [April 22, 2023, 1:36pm UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065/3 "2023-04-22T13:36:19Z")

</div>

It works. Thank you very much.

To be honest, it is more complicated than I expected. So is there a way we can pre-build the OpenAI npm package into the JupyterLite deployment? Maybe it is easier for downstream developers.

---

<div class="post-metadata">

### Author: ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)
#### Post date: [April 22, 2023, 1:59pm UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065/4 "2023-04-22T13:59:53Z")

</div>

> downstream developers

Sure, specifically as JS developers comfortable with npm, etc, they can do whatever they want with a custom [kernel](https://jupyterlite.readthedocs.io/en/latest/howto/extensions/kernel.html), with the packages compiled in at build time, and then release these in a way that works with the core `jupyter lite build` system for a (theoretically) reproducible system.

It’s also theoretically possible to do some of this from a “plain” labextension, but this wouldn’t work much at all in a stock JupyterLab, so likely better to handle in the “server”.

More generally, `importMaps` _could_ be made to work in the core kernel, but at present, the JS ecosystem is not yet ready for the general case of modules (safari only added this last month), and adding a hardcoded dependency on a specific CDN has been avoided thus far.

As for a dependency on a specific, for-pay SaaS with no particular self-hostable alternative… definitely not going in core.

---

<div class="post-metadata">

### Author: ![Saravana\_Shanmuganat](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/saravana_shanmuganat/32/9738_2.png) [@Saravana\_Shanmuganat](https://discourse.jupyter.org/u/Saravana_Shanmuganat)
#### Post date: [April 26, 2023, 11:36am UTC](https://discourse.jupyter.org/t/how-to-install-openai-npm-package-in-the-javascript-kernel-in-jupyterlite/19065/5 "2023-04-26T11:36:04Z")

</div>

Hi bollwyvl,  
We are just working on jupyterhub. And we had a question when we started to work. We just want to restrict Jupiter kernal for some users. If there any steps please let me know.  
Thanks

Regards  
Saran
