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

[.Net] Allow passing a kernel to Interactive Service. #3183

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions dotnet/src/AutoGen.DotnetInteractive/InteractiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>? DisplayEvent;

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

/// <summary>
/// Create an instance of InteractiveService
/// Install dotnet interactive tool to <paramref name="installingDirectory"/>
/// and create an instance of <see cref="InteractiveService"/>.
///
/// When using this constructor, you need to call <see cref="StartAsync(string, CancellationToken)"/> to install dotnet interactive tool
/// and start the kernel.
/// </summary>
/// <param name="installingDirectory">dotnet interactive installing directory</param>
public InteractiveService(string installingDirectory)
{
this.installingDirectory = installingDirectory;
}

/// <summary>
/// Create an instance of <see cref="InteractiveService"/> with a running kernel.
/// When using this constructor, you don't need to call <see cref="StartAsync(string, CancellationToken)"/> to start the kernel.
/// </summary>
/// <param name="kernel"></param>
public InteractiveService(Kernel kernel)
{
this.kernel = kernel;
}

public async Task<bool> StartAsync(string workingDirectory, CancellationToken ct = default)
{
if (this.kernel != null)
{
return true;
}

this.kernel = await this.CreateKernelAsync(workingDirectory, true, ct);
return true;
}
Expand Down
Loading