janpfeifer / gonb

GoNB, a Go Notebook Kernel for Jupyter
https://github.com/janpfeifer/gonb
MIT License
467 stars 32 forks source link

few ideas about gonb #119

Open HaveF opened 1 month ago

HaveF commented 1 month ago

First of all, thank you very much for your repo, I find it very interesting. Because I am a newcomer to the Go language, I am still exploring many places. Because of gonb, then I think it will be very convenient for me to record my learning code and results.

I have some more ideas for reference. Since I noticed that you are an expert in machine learning, I will keep it short.

I don’t know if you know the nbdev library (related to fast ai, you may know it). There are some points in its library that I think we can learn from:

Of course, the objects faced by these two libraries are different, and the usage scenarios will be very different. reinventing the wheel is not a good thing. It's just that I don't have a way to combine the benefits of these two tools. But in short, these are some rough thoughts when I first observed your tool, for reference!

Thanks again for your repo!

janpfeifer commented 1 month ago

hi @HaveF , thanks for the comments, and sharing the ideas -- sorry I'm travelling this week and next, so I'm not so responsive.

I quickly browsed nbdev and loved it -- if I understood correctly. It seems very doable to create a plugin, or separate code in Go that would do something similar (but not exactly the same) for gonb.

I've discussed about adding code generation with AI, probably using Ollama, and it's high in my todo list. It's just that ... it's some amount of work and I confess I haven't figured out exactly what is the abstraction to use: gonb is a kernel, and it can change the code it maintains for the user, but it's not able to create a new cell and inject the generated code there for the user to review / edit. There is a typescript extension for that in JupyterLab, but I never got the time to learn typescript and figure out JupyterLab build system to develop something like that. We are taking contributions if this is a project that entices you.

I haven't figure out btw how the #| default_exp core command works ... I wonder if this is an extension for the ipython kernel, or if nbdev is a kernel itself ? Any ideas how it works ?

cheers

ps.: again apologies if I take a while to respond this coming week.

HaveF commented 1 month ago

@janpfeifer I don’t think it has anything to do with Typescript. nbdev is a pure python package that was developed by itself --- if I understand correctly, it just defines some opinionated annotations by default, then parses the ipynb file and extracts these agreed annotated cells into in a separate file.

This process feels the same as yours.

Whenever a cell is executed, gonb saves the cell content of the cell to a Go file, auto-imports missing dependencies (when it can guess), compiles and runs it. It may seem a lot, but its pretty fast (except maybe the first cell run that is usually a little slower) and feels interactive.

Easy, right ? Now when trying different things, to avoid having to write func main() at every cell, gonb provides a short cut: "%%". Anything after a "%%" will be wrapped inside a func main() { ... }.

%%
fmt.Printf("Hello World!")

My idea is to borrow the concept of nbdev. Image:

Maybe it needs to be designed opinionated annotations, I just gave an example above. Literary programming is very attractive. Feel free to explore in the notebook, leave some ideas, experiments and even tests, and finally export some pure exploration results.

Have a nice trip :-)

HaveF commented 1 month ago

Here is it's nbdev's api design notebook, we can see Jeremy's API design thinking process in it. After he finished the notebook, the api is done. I can only use nbdev now, but I can’t change its code yet(Although I don’t quite understand it yet).