We all know that LLMs and generative AI have been working their way into many products.
Well, it's Jupyter's turn to get a really awesome integration.
We have David Kui here to tell us about Jupyter AI.
Jupyter AI provides a user-friendly and powerful way to apply generative AI to your notebooks.
It lets you choose from many different LLM providers and models to get just the help that you're looking for.
And it does way more than just add a chat pane in the UI.
Listen in to find out.
This is Talk Python to Me, episode 440, recorded October 30th, 2023.
Welcome to Talk Python to Me, a weekly podcast on Python.
This is your host, Michael Kennedy.
Follow me on Mastodon, where I'm @mkennedy and follow the podcast using @talkpython.
Both on Bostodon.org.
Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
We've started streaming most of our episodes live on YouTube.
Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
This episode is sponsored by Posit Connect from the makers of Shiny.
Publish, share, and deploy all of your data projects that you're creating using Python.
Streamlit, Dash, Shiny, Bokeh, FastAPI, Flask, Quattro, Reports, Dashboards, and APIs.
Posit Connect supports all of them.
Try Posit Connect for free by going to talkpython.fm/posit.
P-O-S-I-T.
And it's also brought to you by us over at Talk Python Training.
Did you know that we have over 250 hours of Python courses?
Yeah, that's right.
Check them out at talkpython.fm/courses.
David, welcome to Talk Python to me.
Awesome to have you here.
Yeah, thank you, Michael.
I'm really excited to see what the AIs have to say today.
The AIs?
Yeah, language models, sure.
Yes, exactly, exactly.
Now, you've built a really cool extension for Jupyter that plugs in large language models for people.
And it's looking super interesting.
So I'm excited to talk to you about it.
Yeah, I'm excited to talk about Jupyter AI, too.
I've actually presented this twice at one set.
Actually, three times.
I did a short demo at this tech meetup thing in Seattle.
That was actually the first time Jupyter AI was shown to the public.
And then I presented at PyData Seattle at Microsoft's Redmond campus.
And then I got to present again at JupyterCon in Paris this May.
It was a really wonderful experience.
But yeah.
Wow.
Yeah, you're making the rounds.
Yeah.
I love to talk about Jupyter AI.
It happens to get me some plane tickets.
Just joking.
Honestly, that's like half the bonus of conferences is like awesome places you get to go.
The other half probably is the people you meet.
You know, it's really cool.
Oh, for me, it's like almost like all the people.
Like the people are just so great, especially JupyterCon.
Yeah.
And the JupyterCon videos are now out for JupyterCon 2023.
And there's a ton of good looking talks there.
Yeah.
Lots of really smart people.
I mean, like I was chatting to a few folks there.
And that's like the only place where you're going to find like people who work at these hedge funds and trading firms just lounging so idly and casually.
Right.
Like.
Yeah.
The market's opening and they're chilling.
It's all fine.
Yeah.
It's a, there's a lot of smart people there.
Yeah.
Jupyter more than a lot of programming technologies bring people from all sorts of different places together, different backgrounds.
There's like a huge, yeah, there's like a lot of reasons behind that.
But long story short, Jupyter's pretty awesome.
And that's kind of why I work to contribute to it.
Awesome.
Well, let's start this whole conversation with a bit of background about yourself.
And for people who didn't see your talk and don't know you yet, tell them a bit about you.
I didn't really give much of an intro there either, but sure.
Yeah.
So I've worked for AWS as a software engineer.
And I've been with AWS, specifically the AI ML organization at AWS.
I've been with them for almost two years now.
Right now, I, my manager is actually Brian Granger, who's the co-founder of Project Jupyter.
He also works for AWS.
Yeah.
So he's been offering some technical and product guidance for the things that we're building.
And he's a fantastic gentleman to work with.
Cool.
Yeah.
It's a really neat, neat to have him available as a resource, you know, as a colleague.
Yeah.
You know, it's funny.
Like I actually, yeah, I met him internally.
So when I first joined, I wasn't working for him, but at tech companies, you can do this internal
transfer thing.
And basically my old team was kind of the team I just joined right after I joined, it sort
of started to dissolve a little because they just launched a product at reInvent, which happens
in like December.
And then, so I joined in December and it's like, oh, hi.
So then I, yeah.
And then I joined, I messaged, I saw just, saw Brian Granger's name somehow and I messaged
him and I didn't even know that he was the co-founder of Project Jupyter.
I just wanted to work for him because I used it before.
And yeah, it's a pretty funny story.
Indeed.
I imagine that project is, is really, you know, this Jupyter AI is a great example, but
I just thinking of being say a founder of Jupyter or, or something like that.
And these things take on a life of their own.
And he's probably in awe of all the stuff happening and all the things going on.
And there's probably a lot of stuff in Jupyter.
He doesn't even know about, right?
It's like, that's happening.
Yeah, it's huge.
And yeah.
And like the leadership structure has changed to accommodate that.
So Brian is no longer the benevolent dictator for life.
Jupyter Project Jupyter is now governed by a committee decentralized and democratized just
to allow it to scale.
Yeah, of course.
Let's start by talking about a bit of the role of AI and data science.
I don't know how you feel about it.
Obviously you must be somewhat of an advocate putting this much time and energy into bringing
it to Jupyter.
Wow.
However, personally, when I, I want to know something, I don't think there's a great specific
search result for it straight to ChatGPT or friends.
I think there's, there's such a, such a wealth of information there from, I need to take
this paragraph and clean it up and make it sound better to, I have this program.
I want to convert to another language, or I have this data in this website.
How do I get it?
You know, like just, you can ask so many open-ended questions and really get great answers.
So it seems to me, especially coming from, like I mentioned before, those diverse backgrounds,
people not necessarily being like super deep in programming, maybe they're deep in finance,
but they do programming that having this AI capability to ask like, Hey, I know I
can, but how, what do you think for data science in particular?
This is an interesting topic, right?
Because I think the whole power of language models stems from their ubiquity and versatility
and how they can sort of be very generally applicable.
So like the thing about language models is that they're basically statistical models that have
been trained on a very, very, very large corpus of data.
And that's really to the computer.
The computer doesn't really understand English.
It doesn't really understand natural language.
It has, it's basically making, it has like, when it's trained, it has like knowledge of the
distribution of information and how information sort of interacts with other information.
Because of that, it's a very, it has a very general applicability, right?
And I don't think that's utilities limited to data science.
Now, if we're talking about the field of data science specifically, I think language models
have extraordinary utility and explanatory natural language tests, which I think everybody is
aware of now, now that ChatGPT has been out for almost a year.
But I think in the field of data science and other like deep technical fields, they're especially
applicable because of how complicated some of the work is.
ChatAI can also help analyze and debug code, which JupyterLab also allows you to do.
I know it's statistics, but when you look at it, it seems like it understands, right?
It seems like it understands my question.
And I think one of the really interesting parts is the fact that these LLMs have a context.
I would like you to write a program in Python.
Okay, great.
Tell it to me.
I want a program that does X, Y, Z, and then it writes it in Python, which sounds so simple.
But up until then, things like Siri and all the other voice assistants, they seemed so
disjointed and so not understanding.
You're like, I just asked you about the weather.
And when I ask you how hot it is, you know, like, how do you not understand that that applies
to the weather, right?
There's just in the fact that you converse with them over a series of interactions is pretty
special.
The context.
Yeah.
It's basically implemented just by passing the history, the whole history appended to your
prompt.
So, yeah.
It's not like any super staple magic or whatever, but it's still very interesting, like, how
far you can take it.
And yeah, definitely, like, the context allows you to interact with the AI a lot more conversationally
and humanly.
Like, you don't have to pretend like you're talking to an AI.
You can actually just kind of treat it like a human and it still answers questions very well.
There was even at Google, there was that engineer who said they thought it had become sentient.
And there was that whole drama around that, right?
This is such a crazy coincidence.
But my roommate is actually friends with that gentleman.
Oh, really?
I know.
Wow.
Absolutely crazy coincidence.
Like, it's just fun.
I just thought it was really funny you bringing it up.
It was that, it was a Cajun gentleman, a senior engineer at Google, right?
Yeah.
Very funny, Mike.
It's been a little while.
I don't remember all the details, but yeah, I mean, it's pretty wild and pretty powerful.
I think I've recently read, I'm trying to quick look it up, but I didn't find it.
I think they just used LLMs to discover, like, a new protein folding.
And it's that kind of stuff that makes me think, like, okay, how interesting that it's, you know,
that knowledge wasn't out there in the world, necessarily.
I have a lot to say on that subject.
So personally, I don't believe that language models are actually intelligent.
I think that people are conflating, well, they're certainly not conscious, right?
Absolutely.
Yeah.
As to whether they're intelligent, I don't think they are.
I think that intelligence has a, like, intelligence as we know it, as humans know it, has some
different characteristics that language models don't really exhibit.
They're best thought of as, like, really, really, really good statistical models.
Like, are you familiar with the mirror test?
Maybe, but I don't think so.
Yeah.
So it's, like, this idea in animal psychology, but, like, if a cat sees a mirror, it thinks
it's another cat because it doesn't recognize its own inflection.
Right.
You see them all get, like, big and, like, trying to, like, act big and tough to chase it off,
and it's just them, yeah?
Language models are kind of like that, but for humans, right?
Like, if something mimics human-like qualia closely enough, very tempting to think of it
as human.
Yeah.
We see faces on Mars when it's really just erosion, stuff like that.
Exactly.
I could talk about this, like, for a full hour, but yeah, we should totally move on to
another topic before I go on a tirade.
Well, when you're saying it's not that intelligent, I'm wondering if maybe you've misnamed this project.
Maybe it should just be Jupyter A, like the I?
Do you got to drop the I?
I don't know.
We're just following convention, right?
So I still use the term AI.
Of course.
You got to talk to people.
Yeah.
Emphasize the artificial, huh?
Before we get to Jupyter AI, what came before?
How did people work with things like ChatGPT and other LLMs in Jupyter before stuff like Jupyter AI came along?
I think initially it was a combination.
So the initial motivation for this project came through a combination of sort of a demo put together by Fernando Perez, who is another, I believe.
I think he's another co-founder.
another co-founder of Project Jupyter, and he put together this demo called Jupyter, which is, it's like spelled like Jupyter, except the last letter is an E.
And it's a pun of like ChatGPT, right?
Jupyter.
There was a combination of that demo project set by Fernando and some motivation from my manager, Brian, who also was, you know, as a leader in the AWS AI organization.
You know, he's always trying to think of fancy, fancy new ideas, right?
And this is a pretty fun idea to work out.
So I put together, I think this was sometime in early January, I put together the first demo.
It was private.
And I showed it off to the team and they were like, wow, this has a lot of potential.
Let's see if we can grow it a bit more.
And then as we worked on it for the next few months, it became clear like, oh, wow, this is actually really significant.
Let's keep working on this.
So it's definitely been a collaborative effort to bring Jupyter AI to where it is today.
Sounds like it.
Definitely a lot of contributors over on the GitHub listing.
Let's get into it.
What is Jupyter AI?
People can guess, but it's also different in ways than maybe just plug it in a chat window.
Jupyter AI is actually, right now, it's two packages.
But it's best thought of as just a set of packages that bring generative AI to Project Jupyter as a whole.
So not just Jupyter Lab, but also Jupyter Notebook and IPython.
Even the shell.
How do you, I guess you invoke it by doing like the magic there as well.
It's the IPython shell, which is not the same as like a bash shell for instance, your terminal.
Interesting.
You could dive into a little bit more detail on what these two packages are.
So we have the base Jupyter AI package, which is spelled exactly as you might imagine it.
It's Jupyter hyphen AI.
That is a Jupyter Lab extension that brings a UI to Jupyter Lab, which is the screenshot that you're showing on your screen.
But for viewers without a screen, it basically is the package that adds that chat panel to the left-hand side and allows you to speak conversationally with an AI.
And then the second package is Jupyter AI magics, which is spelled the same, except at the end, it's spelled hyphen magics.
And that is actually the base library that implements some of the AI providers we use and brings things called magic commands to the IPython shell.
And magic commands basically let you invoke the library code, aka like calling link, using it to like call language models, for instance.
And that allows you to do it inside an IPython context.
So what's crazy is that if you run IPython in your terminal shell, you can actually run Jupyter AI from your terminal, which is pretty cool.
Yeah, I didn't realize that.
I mean, it makes sense, of course, but I hadn't really thought about it.
Yeah, I thought more of this like kind of a GUI UI type of thing that was alongside what you were doing.
Yeah.
We try to make it flexible.
And there's reasons for the magic commands, which I can talk about that later, though.
This portion of Talk Python to Me is brought to you by Posit, the makers of Shiny, formerly RStudio, and especially Shiny for Python.
Let me ask you a question.
Are you building awesome things?
Of course you are.
You're a developer or a data scientist.
That's what we do.
And you should check out Posit Connect.
Posit Connect is a way for you to publish, share, and deploy all the data products that you're building using Python.
People ask me the same question all the time.
Michael, I have some cool data science project or notebook that I built.
How do I share it with my users, stakeholders, teammates?
Do I need to learn FastAPI or Flask or maybe Vue or React.js?
Hold on now.
Those are cool technologies, and I'm sure you'd benefit from them.
But maybe stay focused on the data project?
Let Posit Connect handle that side of things?
With Posit Connect, you can rapidly and securely deploy the things you build in Python.
Streamlit, Dash, Shiny, Bokeh, FastAPI, Flask, Quattro, Reports, Dashboards, and APIs.
Posit Connect supports all of them.
And Posit Connect comes with all the bells and whistles to satisfy IT and other enterprise requirements.
Make deployment the easiest step in your workflow with Posit Connect.
For a limited time, you can try Posit Connect for free for three months by going to talkpython.fm.
That's talkpython.fm/P-O-S-I-T.
The link is in your podcast player show notes.
Thank you to the team at Posit for supporting Talk Python.
Now, one thing, you said this, but I want to emphasize it a little bit in that this will run anywhere IPython kernel runs, which is JupyterLab notebook, but also Google Colab, VS Code, other places as well, right?
So pretty much it comes to you wherever your Jupyter type of stuff is, right?
Yeah, and the same goes for your lab extensions.
So the great thing about lab extensions is that they work anywhere where the product is just sort of built on top of JupyterLab, right?
So Google Colab is essentially what Google has is a, well, I can't obvious, I obviously can't attest to what they're actually doing.
But most likely, it's like a set of extensions or CSS themes that are built on top of JupyterLab.
But like the underlying code is still JupyterLab.
It's still mostly JupyterLab.
So you can actually just install extensions and they work just fine, which is another reason why JupyterLab is just pretty awesome.
Yeah, it sure is.
Yeah, JupyterLab itself is basically a pre-selected, pre-configured set of extensions, right?
That's pretty cool.
That is true, yeah.
Giving preference to or showing just what I play with mostly, which is ChatGPT.
There's actually a lot of language models that you can work with, right?
One of the big things, and this is something I'll circle back to later, is that Jupyter AI is meant to be model agnostic, meaning that we don't discriminate against the choice of model or model provider.
Because as an open source project, it's very imperative that we maintain the trust of our users, right?
Users have to be sure that this isn't just some product that exists to force them and force or pigeonhole them into using a certain model provider like OpenAI or Anthropic.
It's the product makes no opinions.
We simply try to support everything as best as we can.
And we've written a lot of code to make sure that all of these models and just play nicely together, essentially.
Like every model provider, like let's say from Anthropic or AI21 or Cohere, every one of these APIs kind of has its own quirks.
Every one of these Python SDKs has its own quirks.
And we work very hard to basically iron out the surface and make everything have the same interface.
We can talk about that later, though.
Sure.
And it also makes it pretty easy to try them out, right?
If you switch from one to the other.
You're like, I wonder how Hugging Face versus OpenAI would do to solve this problem, right?
Absolutely.
Like that's kind of one of the ideas is like while, you know, certain model providers, they might offer a UI if they're very well funded by their investors.
For example, OpenAI to have a UI.
But that UI only allows you to compare between different models from OpenAI, which, you know, like as an independent third party looking to use an AI service, like that information is obviously a little biased, right?
Like you want to see like what other providers have to offer.
Like what does AI21 have?
What does Anthropic have?
And right now it's really, there really is no like cross model provider like UI or like interface in general.
But like that's kind of one of the use cases that Jupyter AI was intended to fit.
Yeah.
Provides a standard way to interact with all these and sort of compare them.
And it's also a UI for them.
And if you're using JupyterLab, yeah.
I'm not familiar with all of these different models and companies.
Do any of those run locally, like things like GPT for all, where it's a local model versus some kind of cloud?
Where's your key?
Where's your billing details and all that?
We actually recently just merged a PR that adds a GPT for all support.
Okay.
That's included in the release.
However, back when we first implemented this a few months ago, I had a few issues with the platform compatibility.
So like it wouldn't, so like some of the binaries that we downloaded from GP for all didn't seem to work well on my M1 Mac, for instance.
I'd say, yes, we do have local model support, but it's a bit experimental right now.
We're still like ironing out the edges and testing, like seeing how we can make the experience better.
Like does it sometimes only get bad output because we forgot to install the shared library?
Those are the type of questions that our team is wrangling with right now.
I see. And maybe I just jumped right into it, but maybe tell people what GPT for all is just real quickly.
GPT for all offers a few local models.
Actually, they offer several, I believe, not just a few.
I think they offer maybe like 10 to 15.
It's the numbers getting quite large.
Yeah.
To the point where I don't know what the right choice is.
I'm like, which one do I download?
There's they say they're all good.
Of course, they're going to say they're good.
I'll be frank.
I don't actually have that much experience with GPT for all.
It's we mainly use them as sort of a provider for like these free and open source language models.
Yeah.
I think they offer UI as well for multiple platforms.
I've only played with them a little bit, just started checking it out.
But it's basically a local.
You download the model.
You run it locally.
You don't pay anything because it's just just running on your machine.
As opposed to, say, OpenAI and others where you've at least got rate limiting and a certain amount of queries before you have to pay and maybe potentially access to better models like ChatGPT-4 versus 3.5 and so on.
That's also taking the characteristics of these service providers for granted, right?
So, yes, definitely, while it does hurt the wallet to pay for usage credits, right?
It's also pretty remarkable how small the latency has gotten with some of these APIs.
I've gotten sub-500 millisecond latency on some of these APIs.
And that's really incredible because when I was using GPT-4-All, the latency was a little bit high on running locally with limited compute resources.
It's really remarkable how fast these APIs are.
It is pretty insane.
Sometimes it drives me crazy.
I'm just only, again, referring to ChatGPT because I don't have the experience with the others to the degree.
But it drives me crazy how it artificially limits the response based on the speed of the response so it looks like it's chatting with you.
I'm like, no, I have four pages of stuff because you just get it out.
You know, it'll say something like, you can ask, I gave you a five-page program.
Let's call it X.
If you say, what is X?
It'll just start printing it slowly, line by line.
Like, you know you just are echoing it back.
Just get it out.
I want to ask you the next question.
You know what I mean?
In that case, that's actually a feature request that we've gotten because it doesn't actually slow down.
Like, it's not just like a pointless animation.
Yeah, the servers are streaming essentially token by token, right?
As the language model generates output.
So it's kind of more like a progress indicator than a superfluous animation.
Yeah.
Yeah, of course.
But if you've got something large, large blocks of text you're working with, it can be a drag.
All right.
I wanted to kind of touch on some of the different features that I pulled out that I thought were cool.
I mean, obviously it goes without saying that Jupyter AI is on GitHub.
I mean, because it's software.
And so it's open source, which I don't know if we said that, but obviously free open source on GitHub.
BSD3 license.
But it's also noteworthy that it's officially under the JupyterLab organization, not under the David account.
You know what I mean?
It's officially part of the JupyterLab subproject.
And yep, as you pointed out, we're under the JupyterLab GitHub org as well.
Yeah, that's awesome.
Let's talk about some of the different things you can do with it.
Some of them will be straightforward, like just like, how do I write a function, Jupyter AI?
And others, I think, are going to be a little more interesting.
So let's start with asking something about your notebook.
Tell us what people can do here.
Asking about your notebook basically means like you can actually teach Jupyter AI about certain files, right?
So the way you do this is via a slash command in the chat UI.
So you type slash learn and then file path.
And it essentially teaches the Jupyter AI about that file.
Now, it works best with files that are written in natural language, right?
So like text files or markup or markdown rather.
Yeah.
So like those, like, especially like developer documentation as well, right?
It works really well with those.
It works best with those kinds of files.
And after Jupyter AI learns about these files, you can then ask questions about the files.
It's learned by prefixing your question with the slash ask command.
That is so cool.
It is pretty cool.
I know it's so cool because what I've done a lot of times, if I want ChatGPT to help me, it's like, I'm like, all right, well, let me copy some code.
Right.
Then I'm going to have a conversation about it.
But a lot of the context of, well, it's actually referencing this other function.
And what does that do?
Or just a broader understanding of what am I actually working on is missing, right?
Because I've only copied it.
You can't paste, you know, 20 files into ChatGPT and start talking about it.
But with this, you can, right?
You can say, learn about, you can say, learn about different things, right?
You can say, learn about your notebook, but you can also probably tell it like, learn about my documentation or learn about my data set.
And now let me talk to you about it.
What's interesting is that the right now, while it works best for natural language documents, we are working on improving the experience for code.
From our testing, like the code is mostly the capabilities of Jupyter AI after learning code is right now mostly limited to explaining what code does, but sort of like explains it from the doc screen.
So we're working on a way to format the code in a manner that is more interpretable to a language model.
Sure.
We're working on ways to improve the experience for code.
But yeah, definitely the long-term vision is to have Jupyter AI literally be able to learn from the whole directory of files or possibly even a URL, like a remote URL to like, like a documentation page.
Yeah.
We have some big ideas there.
We're still working on them.
I want to work with a new package XYZ.
Like, I don't know what XYZ is.
You know what?
Here's where you can learn about it.
Go and figure it out.
Like, query the PyPI API, get the docs page from the metadata, and then go to that URL, scrape it.
Like, lots of things we're exploring.
It's still kind of early days for this, right?
You've been at it about a year or so?
It's been out for a while.
Recently, I've had to work on a few other things as well, like Jupyter AI.
Unfortunately, I cannot give my entire life to Jupyter AI.
So I've been working on a few other things these past few months.
But yeah, there are a lot of things that I envision for Jupyter AI.
I have a much bigger vision for what I want this project to be and what it can be capable of.
Exciting.
So this screenshot that you got here in the section that I'll link to in the show notes
is cool because you can select a piece of a portion, not even a whole cell,
but a portion of code in a cell.
And then you can ask, what does this code do?
We have an integration with the JupyterLab editor APIs.
So you can select a block of code and then include that in your prompt.
And it will be appended to your prompt below, right?
Right.
It's appended to Bob, sorry.
You can basically ask, like, so you can select a block of code.
So in this screenshot right here, there's this block of code that computes the least common
multiple of two integers, right?
And you can select that and then click Include Selection and then ask Jupyter AI,
what does this do?
Which is pretty awesome.
Another checkbox is Replace Selection.
I'm guessing that is like, help me rewrite this code to be more efficient or if there's
any bugs, fix it.
So the Replace Selection checkbox is totally independent.
So you can actually use both at the same time.
And one of the use cases for this is refactoring.
And I've actually applied this in practice a few times where you can basically select a
block of code and then click both Include and Replace Selection.
And then you can format your prompt to say, refactor this block of code.
Do not include any additional help or text.
And when you send that prompt over, it will actually refactor the code for you in your
notebook, which is, yeah, like is, it's pretty great.
That's pretty awesome.
You know, you could do things like refactor this to use guarding clauses.
So it's less nested and less, less arrow code or whatever, right?
Yeah.
Or like add a doc string, right?
Summarize this purpose of this function and then enclose that in the doc string and add it
to the function.
Right.
Or this code is Panda's code, but I'd like to use Polars.
Please rewrite it for Polars, which is not a super compatible API.
It's not like DAST to Panda's, where it's basically the same.
Yeah.
And this kind of circles back to that question that you had asked earlier.
I think I went on a tangent there and didn't fully answer.
But like, what is like the utility of Jupyter AI to like data practitioners, right?
So we're talking data scientists, machine learning engineers, like this, the Include Selection
features.
We've heard great feedback about how helpful it is to like actually explain a data.
So sometimes like you're working with a test set and it's not immediately clear what the
features of this test set are or like what this even does, because sometimes it's like
high dimensional data and they can literally select it and then click Include Selection
and say, and tell Jupyter AI, explain to me what this does.
Just like, what is this like data frame stuff?
Like, whoa, we got data frames in data frames.
Like what's going on here?
Like what even is the structure?
That's awesome.
And I think it's super valuable.
I think the, and this is like a little bit I was getting to before one of the features
that I think is cool.
Whereas if you just go with straight ChatGPT, you copy your code, you paste it into the chat.
Hopefully it doesn't say it's too much text and then you can talk about it.
But then when you get an answer, you've got to grab it, move it back over.
And this just, this fluid back and forth is really nice.
Yeah.
And that's actually one of the design principles that we worked out when first starting this
project officially is the idea that Jupyter AI should be human centered.
As in, you shouldn't be expected to be a developer to know how to use this tool.
Like this tool is for humans, not, not for any specific persona, just for humans in general.
That's awesome.
Yeah.
So in this case, you select the function that does the lowest common denominator bit and
you ask it what it does, it says the code will print out the least common multiple of
two numbers passed to it.
Super simple, very concise.
Okay, great.
Now we can go on to the next thing, right?
Yeah.
There's this LCD function that we're kind of talking about here.
This example is recursive, which I think recursion is pretty insane, right?
As just a concept for people to get their head around.
This is the iterative version.
So this is after they, yeah, this is the iterative.
Oh, this is after.
Yeah.
So if we go back up.
Oh, one of the things you ask it is things like an example is rewrite this function to
be iterative, not recursive.
Right.
Which is actually really, really awesome.
Right.
You're like, this is breaking my brain.
Let's, let's see if we can not do that anymore.
This portion of talk Python to me is brought to you by us.
Have you heard that Python is not good for concurrent programming problems?
Whoever told you that is living in the past because it's prime time for Python's asynchronous features.
With the widespread adoption of async methods and the async and await keywords, Python's ecosystem
has a ton of new and exciting frameworks based on async and await.
That's why we created a course for anyone who wants to learn all of Python's async capabilities,
async techniques and examples in Python.
Just visit talkpython.fm/async and watch the intro video to see if this course is for you.
It's only $49 and you own it forever.
No subscriptions.
And there are discounts for teams as well.
Another thing I wanted to talk about, and you talked a fair amount about this in your presentations that you did.
I can't remember if it was the JupyterCon or the PyData one that I saw, but one of those two.
You talked about generating new notebooks and how it's, it's actually quite a tricky process.
You got to break it down into little steps because if you ask too much from the AI, it kind of doesn't give you a lot of great answers.
Tell us about making new notebooks.
Like why would I even use, like I can go to JupyterLab and say file new, it'll make that for me, right?
So what's this about?
The generate capability is great because it generates a file that is essentially a tutorial,
that can be used as a tutorial to teach you about new subjects, right?
So like you could, for example, submit a prompt, like slash generate a notebook about asyncio
or a demonstration of how to use Matplotlib.
And after, so this will take a bit of time, but eventually Jupyter AI is done thinking and generates a file
and it names a file up and generates a notebook.
And the notebook has a name, it has a title, it has like sections, table of contents,
and each of the cells within it, like is tied to some like topic that is determined to be helpful
and to answer the user's question.
Awesome.
Could I do something like, I have weather data in this format from the US weather service.
Could you generate me a notebook to plot this XYZ and help me answer these questions?
Or like, could I ask it something like that?
Not at the moment.
So like that would best be done.
That would be done best if, since the data is already, like, I'm assuming that the data is already
available, right?
In some kind of like format.
So like in a notebook, you could use a chat UI to like select that entire, select that selection
and then tell it, tell Jupyter AI to generate code to plot that data set.
So right now, generate only takes a natural language prompt as its only argument.
I see.
So it's kind of like stateless in that regard.
So in this case, you can say slash generate a demonstration of how to use matplotlib.
And then the response is great.
I'll start working on your notebook.
It'll take a few minutes, but I'll reply when it's ready.
In the meantime, let's keep talking.
So what happens behind the scenes that takes a few minutes here?
This is a bit interesting.
It does kind of dive deep into like the technical details, which I'm not sure if, which do you
want to just like dive?
Yeah, let's go tell us how it works.
Probably a good chance to explore that.
Yeah.
So slash generate, the first thing is that the prompt is first expanded into essentially
a table of contents.
So basically we tell the language model, generate us a table of contents conforming to this JSON
schema.
And when you pass a JSON schema included in your prompt, the language model will be much
more, will have a much higher likelihood of returning exclusively a JSON object that matches
that JSON schema that you had initially provided.
So in our case, we generate a table of contents.
And then we take that table of contents.
And then we say for each section, we do this in parallel, like generate us some code cells
that are appropriate for teaching this section of the document.
So for example, for matplotlib, right?
Like maybe the first section is your first, like generating your first plot, plotting 3D functions.
And the next one is like plotting complex functions with phase or something like that.
And then with each of these sections, we then send another prompt template to the language
model for each of these sections, asking it to generate the code.
And then at the end, we join it all together and then we save it to disk and then emit that
message and say, we're done.
Maybe the English literature equivalent would be instead of just saying, write me a story about
a person who goes on an adventure and gets lost.
It's like, I want, give me an outline, bullet points of interesting things that would make
up a story of how somebody goes on an adventure and gets lost.
And then for each one of those, you're like, now tell this part of the story.
Now tell this part.
And somehow that makes it more focused and accurate, right?
The main limitation is that because we're a model agnostic, language models are limited
in how much output they can generate, right?
Yeah.
The issue we were running into when we were trying to do the whole thing all at once, like generate
mean the whole notebook is that some language models just couldn't do it.
In an effort to, you know, sort of stay model agnostic, we deliberately implemented, we deliberately
broke this process down into like smaller subtasks, each with its own like prompt template in order
to accommodate these models that may lack the same token size windows that other models have.
I think just even for ones that have large token spaces, I think they still, the more specific
you can be, the more likely you're going to get a focused result instead of a wandering vague result.
Teach me about math or teach me how to factor, you know, how to integrate this differential,
solve this series of differential equations or physics.
Like you're going to get a really different answer to those two questions.
Yeah.
That's also circles back to like a topic I didn't, I did want to call out, but I don't, I don't think
we hit on it.
Is that the chat UI actually does support rendering in both Markdown and LaTeX, which is a markup
language for math.
So you can ask it both complex engineering and mathematical questions, like asking it to explain
you like, yeah.
So like there might be a demo here.
I'm not sure if it's on this page though.
So if I had a Fourier, fast Fourier transform in LaTeX and I put it in there and say, what
is this?
It'll say it's a fast Fourier transform or something like that.
Yes.
And it also works the other way around.
You can also use it to say like, Hey, explain to me what the 2D Laplace equation is, or explain
to me like, what does this do?
Right.
And it will actually generate and format the equation inside the chat UI, which is really
remarkable.
I love that feature.
It's actually really awesome.
And it's also really appropriate for a scientific oriented thing like Jupyter, right?
The remarkable thing is that because chat UBT and like other such language models, like the
ones from Anthropik and AI21, because like they are founded on the premise of where like their
functionality comes from having such a large corpus of data.
They know a remarkable amount of information.
So like we've tried like some example notebooks of quantum computing and explained those really
well.
We try, I tried one of like the Black Scholes options pricing model used in financial engineering.
It's really remarkable.
Like the utility that it offers just by being there in the side panel.
Like you essentially have like a math wizard available to you and to your lab all the time.
It's probably better than a lot of math professors in terms of not necessarily in the depth of
one area.
But, you know, if you ask somebody who does like abstract algebra about real analysis, they're
like, I don't really do that part.
Or if you ask somebody about real analysis about number theory, like I don't really, you can
hit on all the areas, at least a generalist professor sort of thing.
We talked about the slash learn command.
That's pretty excellent already and where that's going.
So I'm pretty excited about that.
Yeah.
It actually does have a lot of interesting technical tidbits to it.
Like the implementation.
Okay.
Yeah.
Actually, this is one of the really challenging things with these chat bots and things.
For example, I've tried to ask ChatGPT if I gave it one, just one of the transcripts from
the show.
I want to have a conversation about it.
It says, ah, that's too much.
I can't do it.
You know, it's just, it's just one, one show.
And in doc, like in your documentation, there might be a lot of files in there, right?
More than just one transcript levels worth.
So that alone, I think it's kind of interesting just how to ingest that much data into it.
Yeah.
And you know, this is a very interesting subject and it actually is a bit complex.
I'm sure it is.
I think there are some other features you want to discuss.
Let's dive into this for just a minute because I think it is interesting.
How do you make, because this makes it yours, right?
It's one thing to ask vaguely, like, tell me about the Laplace equation and how does it
apply to heat transfer?
Like, okay, great.
I have a specific problem with a specific library and I want to solve it.
And you don't seem to understand about enough of it.
So it really limits the usefulness if it doesn't, if it's not a little closer to what you're
actually doing.
And I think this brings it closer.
So yeah, tell us about it.
Language models aren't just governed by like their intelligence, however you measure that,
right?
They're also governed by how much context they can take.
So one of the reasons ChatGPT was so remarkable is that it had a great way of managing context
through conversation history.
And that seemingly small leap and seemingly small feature is what made ChatGPT so remarkably
disruptive to this industry is because of that additional context.
And we think about extending that idea.
How do we give an AI more context, make it even more human-like and personal?
Well, the idea is similar.
We add more context and that's what learning does, right?
And so the way learning works is that we're actually using another set of models called
embedding models.
And embedding models are very, very underrated in the AI-like modeling space, right?
These are really remarkable things.
And they have this one, I'll only cover like the most important characteristic of embedding
models, which is embedding models take syntax and map it to a high-dimensional vector space
called a semantic space.
And inside of the semantic space, nearby vectors indicate semantic similarity.
I know that's like a lot of words, so I'm going to break that idea down, right?
So like canine and dog, let's take these two words as an example, right?
These two words are completely different.
They don't even share a single character and similarity together, right?
They don't have a single letter in common with one another.
And yet we know as humans that these two dogs, these two words mean the same thing.
They refer to a dog.
So like they have different syntax, but the same semantics, the same semantic meaning.
So their vectors would be...
Would be mapped close.
Would be very close by whatever metric you're using, yeah.
If you extend this idea and like you imagine, okay, what if you split a document?
What if you split a file into like one to two sentence chunks?
And then for each of these like sentences, let's just say sentences, for example.
Let's say we split a document to sentences and then we take each of those sentences and then map,
use an embedding model to compute their embedding and then store them inside of a vector store.
Like basically like a local database that has, that just stores all of these vectors in like a file or something, right?
Now imagine what happens if we then take a prompt, like a question that we might have,
encode that as an embedding.
And then we say to the vector store, okay, for this prompt embedding,
find me all of the other embeddings are close to this.
Well, what you've just done in this process is called a semantic search.
So it's kind of like syntax search, except instead of searching based off of key words or tokens or other syntactic traits,
you are searching based off the actual natural language meaning of the word.
This is much more applicable when it comes to like natural language prompts and natural language,
like corpuses of data, because this is like the actual information that's being stored.
Not, we don't care about the characters.
We care about the information that they represent, right?
The essence of it, yeah.
And these vectors are computed by the larger language model?
The vectors, the embeddings are computed by an embedding model.
And they're actually a separate category of model that we have our own special APIs for.
So in our settings panel, you can change the language model.
And I think we already discussed that, right?
Yeah.
But what's interesting is that underneath that, you'll also see a section that says embedding model.
And you can change the embedding model to like, we also offer that same principle of model agnosticism there.
Yeah.
This is very interesting.
Very interesting.
Let's talk a little bit about the format.
You said, obviously, that you can do LaTeX, which you say in, you say math, right?
You tell us, give me math.
Yeah.
Give me math.
Which is, yeah, it's pretty interesting.
But you can do images, markdown, code, HTML, JSON, text.
There's a lot of, a lot of different formats you can get the answer back in.
When you use the AI magics, we can pass them to like a renderer first before we show the output to the user.
Yeah.
And with the AI magic, the %AI in the cell, you can also specify, that's where you put the format potentially,
but you can also specify the model and the service, I guess, for the provider.
The IPython magics are basically stateless in the sense that you always have to specify the model explicitly.
They don't operate off the premise that you are using JupyterLab.
They don't run off the premise that you have JupyterLab installed or are using the lab extension that we offer.
Because of that, like the model is stated explicitly every time.
That's by design.
When you sit down, what is your JupyterAI provider set to?
What's your favorite?
As a developer, I like literally pick a random one to give the most test coverage at all times.
And that's actually a great way of finding bugs.
So, yeah, I don't have a favorite one.
My favorite one is the one that works.
And hopefully that should be all of them.
So.
I guess you can also tell it to forget what I was talking about.
We're going to start over.
That's pretty interesting that you can do that along the way because you maybe had a bunch of conversations.
And we talked about the benefit of it, like knowing the history of that conversation.
But you're like, all right, new idea.
Switching topics.
Chat.
I think the last one I wanted to talk about specifically was interpolating prompts.
Kind of almost like f-strings where you can put in the prompt text, you can put a variable and then other parts of your notebook or program can set that value.
Yeah.
Tell us about this.
You can define a variable in your IPython kernel, right?
So, like, and that's just dumb, but just like how you define any other variable.
But what's interesting is that IPython is actually aware of the variables that you are defining.
So, we can programmatically access that when we implement the magic, right?
Basically, if you define any variable at the top level scope, like let's say poet equals Walt Whitman, right?
So, we have a name variable called poet.
And then you can send a prompt over, like, write a poem in the style of curly braces poet and curly braces.
And when that is run, the value of that variable is interpolated and substitutes around the curly braces.
So, the final prompt becomes write a poem in the style of Walt Whitman.
And when that prompt is sent, well, you can imagine it generates a poem of Walt Whitman.
The variable interpolation that we offer in IPython is very useful for, like, very quick, like, debugging.
So, you can actually reference a cell in the notebook directly.
I think a lot of people don't know this, but, like, in a Jupyter notebook, there's, like, the in and out indicators to the left of each cell.
So, it'll say, like, in dot one, out dot one, right?
So, those are actual variables.
And you can use them here, too.
So, you can reference, like, debug.
Tell me why this code is failing.
Curly braces in dot one.
That's, you just, on the screen there, just scroll there.
Explain what this does, the in bracket 11, or what went wrong in out bracket 11, or, yeah, something like this.
Right.
It's fine long as you don't go and rerun that cell.
Yeah.
But, like you said, this is not for long term.
You can make it independent of the order of execution just by, like, assigning whatever variable that is to, whatever, like, content that is to a named variable.
That way, no matter what order you run them, like.
People might be thinking, when you describe this interpolation thing, just bracket, boom, bracket, curly brace, curly brace, you're like, we already have that in Python.
You just put an F in front of the string, and so on.
But this is in the message that goes to the AI cell magic, not straight Python, right?
That's the relevance.
That's why this is interesting, right?
Yes.
I guess it really comes down to the different models that you select.
So, you opt into this a little bit, or maybe you need to understand it that way.
But talk to us a bit about privacy.
If I select something and say, what does this do?
What happens?
Something important to emphasize here is that whenever you use a language model that's hosted by a third party, so, like, it's running on their servers, right?
Regardless of whether this model is free or not.
Like, the fact that you're sending data to a third party over the internet, like, that's where the privacy and security concerns happen, right?
And that happens, like, whenever, like, you're sending data across the wire over the internet.
But we have some special safeguards in place here, specifically to assuage fears of, like, concerns over privacy and security that a lot of open source users have.
And one of the important ideas here is that Jupyter AI is both transparent and traceable.
So, when we send a prompt to a language model, that's always captured in the server logs by default.
So, that's always being logged.
That's always being captured.
Yeah.
So, like, it's always going to be traceable.
There's no secret back channel.
Like, you tell them, people, this is happening, okay?
Yeah.
So, if, like, an operator needs to audit, like, oh, dang, like, let me check just to make sure nothing scary was sent over to OpenAI.
Well, the operator can review the server logs and make sure that all usage is compliant with whatever privacy policy their company has, right?
And Jupyter AI is also exclusively user-driven, meaning that we will never, by default, send data to a language model, even if you selected one, right?
Like, we will never send data to that language model until explicit action is done by the user.
So, in this case, like, clicking the send button, clicking shift, enter, and running to sell.
Yeah.
Nothing is sent to language model or embedding model until that happens.
That's really all you can do.
That sounds great.
Because you don't control what happens once it hits OpenAI or Anthropic or whatever, right?
That's why the transparency is so important, right?
And, oh, I forgot to touch on traceability.
So, like, with these AI-generated cells, right, so, like, the output cells, in the metadata, we indicate that with, like, the model that was used to generate an output cell, if it comes from the Jupyter AI magic.
So, that way, it's also, like, traceable not just in the logs, but, like, in the actual files metadata and stuff as well.
That's cool, because it'd be really easy to say, have the cell magic, and then, you know, how notebooks store their last output.
Like, if you upload them to GitHub, they'll keep their last output, unless you say clear all cell outputs.
Depending on which model you have selected, you might not get the same output, not even close to the same output.
So, you might want to know, like, well, how did you get that picture?
Oh, I had Anthropic selected and not the other, right?
Like, that is really nice.
I've actually used the server logs myself to debug, like, prompt templates, for instance, right?
So, like, because what we show in the logs is the full prompt.
Like, after applying our template, after applying, like, the edits, like, that's what's actually shown.
So, that's really also really helpful for developers who need to debug what's happening.
Yeah, of course.
Or if you're a scientist and you're looking for reproducibility, I doubt there's much guaranteed reproducibility even across the versions of the same model.
But at least you were in the same ballpark, you know, at least I know what model it came from.
You can set the temperature to zero, but it won't generate very fun output.
That is a workaround if you truly need a reproducibility.
I suppose, yeah.
The temperature being the ability to tell it how creative do you want to be or how focused do you want the answer to be, right?
It's a hyperparameter that basically governs the randomness, like, how far away from the mean it's willing to deviate.
Kind of, yeah, vaguely describable as creativity, yeah.
Yeah, I suppose.
I guess if you're looking for privacy, the GPT for all might be a good option.
Oh, yeah, absolutely.
For that, right?
Because that's not going anywhere.
Yeah.
However, some of them do have license restrictions.
And that's also why we have also taken it this low when it comes to adding more GPT for all support is because different models are licensed differently.
And that's another consideration we have to take in mind.
Yeah.
Yeah, of course.
You're playing in a crazy space with many different companies evolving licenses.
Yeah.
Let's close it out with one more thing here.
Maybe two more things.
One is there's a lot of interest in these agents.
And it sounds, for example, your create a notebook that does this sort of thing, like teach me about Matplotlib, is a little bit agent driven.
Thinking of like Langchain and stuff like that, or even GPT engineer.
What's the story?
Do you have any integrations with that?
Any of those types of things?
We're working on one where basically you won't need to use slash commands anymore.
So this is like, again, like we're just kind of playing around with this, seeing how well it behaves.
But we are trying to use agents to, for example, remove the need to use slash commands.
So when you say, like generate a notebook, like it will just generate one.
You don't have to note a slash command for that.
Like it will just know.
So like, yeah.
However, we don't have any, we don't use agents at the present moment now.
And the reason for that is that they have very, they're not very model agnostic, at least the ones from our research.
Like they only work well for a specific model and a specific prompt template.
But beyond that, it's hard.
All right.
Last question.
Running out of time here.
Yeah.
What's your favorite thing you've done with Jupyter AI?
Not like a feature, but what have you made it do to help you that you really like?
Teach Jupyter AI about Jupyter AI.
That's an easy one.
So we have the documentation.
What did it learn?
Well, learn about itself.
So like I was at a conference and I, so this was at PyData and I actually got enough questions to the point where I did, I just downloaded, I had the documentation already available in my home directory because of some other previous.
Or restructured text them.
Yeah.
And the markdown source.
Okay.
The markdown source.
Right.
And then I just had slash learn.
I just learned that doc.
And then I just had that laptop on the side and told people, like, if you have any questions, try answering that.
Yeah.
In case you don't want to wait in line.
So yeah, that was, yeah, it's pretty remarkable.
Yeah.
The learn feature by far is definitely my favorite.
And it's the one I want to spend the most time developing and pushing it better.
I think there's massive possibility there because to deeply understand what you're working on in a multifaceted way.
What are the documentations?
What is the code?
What is the data?
What is the network topology and servers I can work with?
Like all of that kind of stuff or pick your specialty.
Yep.
And that's how we make AI more human.
Right before it takes over.
So no problem there.
Oh, yeah.
Just kidding.
Yeah.
Let's wrap it up.
I think we're out of time, David.
So final question.
Some notable PyPI package, maybe something awesome you discovered to help you write Jupyter AI.
Anything you want to give a shout out to?
We definitely use Langchain a lot.
And it has some pretty fantastic integrations.
And we're actually built on top of Langchain, really.
But also Dask.
Dask is really nice.
Yeah.
Dask has some great visualization capabilities for when you're doing parallel compute.
It has a great dashboard that's also available in Jupyter Lab.
Yeah.
That shows it running and distributing the work in Jupyter Lab.
It's amazing.
And one of the contributors also reached out once.
He had heard that I was integrating Dask into Jupyter AI.
He actually reached out to help us and offer direct one-on-one guidance with using Dask.
And yeah, it's just been a fantastic experience using Dask.
Yeah.
I have no complaints.
It's just pretty awesome that somebody has finally made parallel and distributed compute better in Python.
For sure.
Yeah.
Yeah, Dask is cool.
Dask is very cool.
All right.
Well, final call to action.
People want to get started with Jupyter AI.
What do you tell them?
I can install Jupyter AI or Konda.
Konda install works too.
It's on both.
Awesome.
Well, really good work.
This is super interesting.
And I think a lot of people are going to find value in it.
So I can see some nice comments in the audience that people are excited as well.
So thanks for being here.
Yeah.
Thank you so much.
Yeah.
See you later.
Bye-bye.
Bye.
This has been another episode of Talk Python to Me.
Thank you to our sponsors.
Be sure to check out what they're offering.
It really helps support the show.
This episode is sponsored by Posit Connect from the makers of Shiny.
Publish, share, and deploy all of your data projects that you're creating using Python.
Streamlit, Dash, Shiny, Bokeh, FastAPI, Flask, Quattro, Reports, Dashboards, and APIs.
Posit Connect supports all of them.
Try Posit Connect for free by going to talkpython.fm/posit.
P-O-S-I-T.
Want to level up your Python?
We have one of the largest catalogs of Python video courses over at Talk Python.
Our content ranges from true beginners to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show.
Open your favorite podcast app and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the
direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show and have your comments featured on the air, be sure to
subscribe to our YouTube channel at talkpython.fm/youtube.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
Bye.
you
Thank you.