From fff49f304699860d97870f1b552a92ba301ab09d Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Sun, 21 Jul 2024 11:36:03 -0700 Subject: [PATCH 1/2] accept a running kernel for Interactive Service --- .../InteractiveService.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs index 7490b64e1267..8d552e8cc021 100644 --- a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs +++ b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs @@ -19,7 +19,7 @@ public class InteractiveService : IDisposable private bool disposedValue; private const string DotnetInteractiveToolNotInstallMessage = "Cannot find a tool in the manifest file that has a command named 'dotnet-interactive'."; //private readonly ProcessJobTracker jobTracker = new ProcessJobTracker(); - private string installingDirectory; + private string? installingDirectory; public event EventHandler? DisplayEvent; @@ -30,7 +30,11 @@ public class InteractiveService : IDisposable public event EventHandler? HoverTextProduced; /// - /// Create an instance of InteractiveService + /// Install dotnet interactive tool to + /// and create an instance of . + /// + /// When using this constructor, you need to call to install dotnet interactive tool + /// and start the kernel. /// /// dotnet interactive installing directory public InteractiveService(string installingDirectory) @@ -38,6 +42,16 @@ public InteractiveService(string installingDirectory) this.installingDirectory = installingDirectory; } + /// + /// Create an instance of with a running kernel. + /// When using this constructor, you don't need to call to start the kernel. + /// + /// + public InteractiveService(Kernel kernel) + { + this.kernel = kernel; + } + public async Task StartAsync(string workingDirectory, CancellationToken ct = default) { this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct); From 28c7bdb42094e71923bca177e4e34e23ff26b8f0 Mon Sep 17 00:00:00 2001 From: XiaoYun Zhang Date: Sun, 21 Jul 2024 11:37:02 -0700 Subject: [PATCH 2/2] add kernel running check --- dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs index 8d552e8cc021..1ca19fcbcfff 100644 --- a/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs +++ b/dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs @@ -54,6 +54,11 @@ public InteractiveService(Kernel kernel) public async Task StartAsync(string workingDirectory, CancellationToken ct = default) { + if (this.kernel != null) + { + return true; + } + this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct); return true; }