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

How can i create my own kernel and attach to UI? #3799

Open
rbuergi opened this issue Jan 6, 2025 · 7 comments
Open

How can i create my own kernel and attach to UI? #3799

rbuergi opened this issue Jan 6, 2025 · 7 comments
Labels
question Further information is requested

Comments

@rbuergi
Copy link

rbuergi commented Jan 6, 2025

The package and version I'm asking about:
latest

Question

I have created my own ConnectKernelDirective and connect to a kernel via SignalR (not the one included). However, I don't get the kernel to show up in the UI. When I hack the notebook and put my kernel manually, all works fine.

My questions:

  1. In the implementation, I am using ProxyKernel shipped in dotnet.interactive. How do I have to configure ProxyKernel to show up in the select kernel dropdown? Can I make it the default once it has been connected?
  2. As results i am sometimes issuing interactive views in the form of iframe. This works fine, except for the choice of the height of the control. Is there any way to make the height of the control adapt to the actual content, given it is loaded dynamically in an iframe?

Thanks very much for the support.

@rbuergi rbuergi added the question Further information is requested label Jan 6, 2025
@jonsequitur
Copy link
Contributor

You might not need to use ProxyKernel, though it's not clear to me without more explanation or a peek at your code. The usual use case for ProxyKernel is for kernels written in non-.NET languages, such as the JavaScript and Python kernels.

I'd try skipping the ProxyKernel if possible and seeing if that works. In either case, simply adding the kernel to the root CompositeKernel should cause it to show up in the kernel picker menu.

Sizing an IFRAME based on the outer content is a whole other problem. It's often done using a script hosted in the outer content to send a message over postMessage to a script hosted in the IFRAME. This isn't specific to Polyglot Notebooks. The VS Code web view should behave like a typical browser.

@rbuergi
Copy link
Author

rbuergi commented Jan 7, 2025

Thank you very much for responding so quickly, @jonsequitur . Even though I am launching a c# kernel, I launch it remotely. I am programming a data mesh, the technology is called [MeshWeaver] (https://github.com/Systemorph/MeshWeaver). It is a brand new technology, and I will launch my own YouTube channel to speak about it. I will extensively use polyglot notebooks in these videos.

The kernel is connected via SignalR in the following way:

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ffcc00', 'edgeLabelBackground':'#ffffff', 'tertiaryColor': '#ffcc00'}}}%%
graph TD
    subgraph Notebook
        A[Post command envelope]
    end

    subgraph Mesh
        B[Route]
        E[Route]
    end

    subgraph Kernel
        C[Prepare View]
        D[Submit result formatted as iframe]
    end

    A -->|Post| B
    B -->|Route| C
    C -->|Handle| D
    D -->|Post| E
    E -->|Route| A
Loading

obviously I don't like this solution at all. I am running a blazor app, but I could easily include react code. I am not a react expret but read your code and couldn't see any way to include it in my blazor app.

I also tried to include my blazor renderer into polyglot notebooks but failed because you haven't supported net9. I saw that you completed this. Neverhteless I would like to connect to any instance of the mesh reachable on the internet. Bring computations to the data, not data to the computation! BTW: polyglot notebooks handles it almost perfectly, except the issue that I don't see my kernel in the drop down and the formatting of outputs.

In order to guide you to my code, please have a look at the following classes:

  1. ConnectMeshWeaverDirective: This is inspred by the proxy kernels you ship, especially the aspnet kernel which seems to be abandoned.
  2. KernelHub: This is the SignalR hub inspired by the one from your project which has an API not matching the clien.
  3. KernelContainer: The remote kernel.

If you want working examples, please

  1. Start the project MeshWeaver.Portal. This is a monolith deployment of the mesh, and you can just start it from vscode.
  2. Have a look at the notebooks, e.g. What is a Data Mesh? or Charts.

I am also happy to donate this setup to your project, mine is also under MIT. I think there is a value in such an approach, as in the time of AI and big data we won't be able to download all this stuff onto our computers.

The worst in terms of styling is ChartJs. It cannot deal with the setup in iframe and polyglot notebooks. As charting is important for me, doing a lot of data analysis, I would be happy for any suggestion for better integration than iframe.

Again, thanks a lot for your help.

@jonsequitur
Copy link
Contributor

There's a lot going on here and it's hard for me to comment on. At a glance, I would think that the ProxyKernel and KernelHost should (meaning they're intended to) do what you need, and there's some complexity there in wiring up the proxies that you probably don't want to try to reinvent.

The version of the SignalR connector that's in the repo is a bit outdated and pending a design discussion we'd be happy to help you prepare PRs for this or other feature areas.

@rbuergi
Copy link
Author

rbuergi commented Jan 15, 2025

Thanks again for your answer, @jonsequitur. Let me please repeat my original questions:

  1. When I execute #!connect mesh, I do not get the kernel listed in the kernel selector. What do I have to do to make this work? Also: Can i make this the default kernel going forward?
  2. I have troubles to size the iframes correctly. Is there a better way of including blazor views into polyglot notebooks? Is it possible to include polyglot notebooks in my blazor app? Why don't you publish an npm package for the UI? This would enable me to consume it and write an adapter.

Would it be possible to have a voice conversation on the topic? I would be very keen to see where I can take polyglot notebooks. But I have now invested quite a long time in reading the source and creating my implementation, and I cannot advance without your help. My alternative is to avoid using polyglot notebooks.

@jonsequitur
Copy link
Contributor

jonsequitur commented Jan 15, 2025

When I execute #!connect mesh, I do not get the kernel listed in the kernel selector. What do I have to do to make this work? Also: Can i make this the default kernel going forward?

#!connect doesn't do anything interesting here. If you instantiate a kernel directly in the notebook, it will add it to the kernel selector when you add it to the root CompositeKernel.

Image

As long as your code is returning a new kernel from ConnectKernelDirective<T>.ConnectKernelsAsync, this should be done for you.

@jonsequitur
Copy link
Contributor

I have troubles to size the iframes correctly. Is there a better way of including blazor views into polyglot notebooks? Is it possible to include polyglot notebooks in my blazor app? Why don't you publish an npm package for the UI? This would enable me to consume it and write an adapter.

The UI is mostly VS Code's UI. Embedding this in a webview in another app would be non-trivial and isn't in scope for this project.

But we do have a way to use an external webview or browser as an output (with no editor functionality) for the kernel. I could make suggestions if you can say more about what you're trying to achieve.

@jonsequitur
Copy link
Contributor

Would it be possible to have a voice conversation on the topic?

Absolutely. Feel free to DM me and we can set something up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants