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: Bug: Error in Polyglot Notebook using Ollama Connector #10310

Closed
dschilling opened this issue Jan 27, 2025 · 3 comments
Closed

.Net: Bug: Error in Polyglot Notebook using Ollama Connector #10310

dschilling opened this issue Jan 27, 2025 · 3 comments
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@dschilling
Copy link

dschilling commented Jan 27, 2025

Describe the bug
Notebooks that reference the Microsoft.SemanticKernel.Core and Microsoft.SemanticKernel.Connectors.Ollama nuget packages output errors when they run.

To Reproduce

Create a Polyglot Notebook with these two code blocks:

#r "nuget: Microsoft.SemanticKernel.Core, 1.34.0"
#r "nuget: Microsoft.SemanticKernel.Connectors.Ollama, 1.34.0-alpha"
using Microsoft.SemanticKernel;
using Kernel = Microsoft.SemanticKernel.Kernel;

var builder = Kernel.CreateBuilder();

#pragma warning disable SKEXP0070 // Ollama support is experimental
builder.AddOllamaChatCompletion("llama3.1:8b-instruct-q2_K", new Uri("http://localhost:11434"));
#pragma warning restore SKEXP0070 // Ollama support is experimental

var kernel = builder.Build();
Console.WriteLine("It worked!");
Console.WriteLine(kernel);

Run the code blocks. It produces this output:

Error: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.SemanticKernel.OllamaKernelBuilderExtensions.AddOllamaChatCompletion(IKernelBuilder builder, String modelId, Uri endpoint, String serviceId)
at Submission#1.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

Expected behavior
I expected it to output:

It worked!
Microsoft.SemanticKernel.Kernel

... which is what happens if you create a .NET 8 Console App with the same two nuget packages and that C# code.

Platform

  • Language: [C#]
  • Source: [NuGet package version 1.34.0]
  • AI model: [llama3.1:8b-instruct-q2_K]
  • IDE: [VS Code with Polyglot Notebooks extension]
  • OS: [Windows 11]

Additional context
I have cross posted this issue with the Polyglot Notebooks team. dotnet/interactive#3823

@dschilling dschilling added the bug Something isn't working label Jan 27, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Jan 27, 2025
@github-actions github-actions bot changed the title Bug: Error in Polyglot Notebook using Ollama Connector .Net: Bug: Error in Polyglot Notebook using Ollama Connector Jan 27, 2025
@jonsequitur
Copy link

.NET Interactive now requires the .NET 9 SDK.

@RogerBarreto
Copy link
Member

Ensure you add the 9.0.0 dependency injection first. Ollama Connector depends on Microsoft.Extensions.AI which has a hard dependency on Microsoft.Extensions.DependencyInjection 9.0.0.

To fix, you need to restart your kernel and add the 9.0.0 explicitly as the first package.

#r "nuget: Microsoft.Extensions.DependencyInjection, 9.0.0"
#r "nuget: Microsoft.SemanticKernel.Core, 1.35.0"
#r "nuget: Microsoft.SemanticKernel.Connectors.Ollama, 1.35.0-alpha"

using Microsoft.SemanticKernel;
using Kernel = Microsoft.SemanticKernel.Kernel;

var builder = Kernel.CreateBuilder();

#pragma warning disable SKEXP0070 // Ollama support is experimental
builder.AddOllamaChatCompletion("llama3.1:8b-instruct-q2_K", new Uri("http://localhost:11434"));
#pragma warning restore SKEXP0070 // Ollama support is experimental

var kernel = builder.Build();
Console.WriteLine("It worked!");
Console.WriteLine(kernel);

@dschilling
Copy link
Author

Thanks! After installing the .NET 9 SDK and upgrading to the latest version of the Polyglot Notebooks extension, it is now working. Upgrading the extension was weird. I upgraded, but #!about still said I had the old version, and the Ollama connector still wouldn't work - same ...DependencyInjection.Abstractions, Version=9.0.0.0 error as before. I had to uninstall the extension and reinstall it, and then after that everything was happy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
None yet
Development

No branches or pull requests

5 participants