Skip to content

Commit 06e6b3f

Browse files
[.Net] Allow passing a kernel to Interactive Service. (microsoft#3183)
* accept a running kernel for Interactive Service * add kernel running check
1 parent c19f44f commit 06e6b3f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class InteractiveService : IDisposable
1919
private bool disposedValue;
2020
private const string DotnetInteractiveToolNotInstallMessage = "Cannot find a tool in the manifest file that has a command named 'dotnet-interactive'.";
2121
//private readonly ProcessJobTracker jobTracker = new ProcessJobTracker();
22-
private string installingDirectory;
22+
private string? installingDirectory;
2323

2424
public event EventHandler<DisplayEvent>? DisplayEvent;
2525

@@ -30,16 +30,35 @@ public class InteractiveService : IDisposable
3030
public event EventHandler<HoverTextProduced>? HoverTextProduced;
3131

3232
/// <summary>
33-
/// Create an instance of InteractiveService
33+
/// Install dotnet interactive tool to <paramref name="installingDirectory"/>
34+
/// and create an instance of <see cref="InteractiveService"/>.
35+
///
36+
/// When using this constructor, you need to call <see cref="StartAsync(string, CancellationToken)"/> to install dotnet interactive tool
37+
/// and start the kernel.
3438
/// </summary>
3539
/// <param name="installingDirectory">dotnet interactive installing directory</param>
3640
public InteractiveService(string installingDirectory)
3741
{
3842
this.installingDirectory = installingDirectory;
3943
}
4044

45+
/// <summary>
46+
/// Create an instance of <see cref="InteractiveService"/> with a running kernel.
47+
/// When using this constructor, you don't need to call <see cref="StartAsync(string, CancellationToken)"/> to start the kernel.
48+
/// </summary>
49+
/// <param name="kernel"></param>
50+
public InteractiveService(Kernel kernel)
51+
{
52+
this.kernel = kernel;
53+
}
54+
4155
public async Task<bool> StartAsync(string workingDirectory, CancellationToken ct = default)
4256
{
57+
if (this.kernel != null)
58+
{
59+
return true;
60+
}
61+
4362
this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct);
4463
return true;
4564
}

0 commit comments

Comments
 (0)