Skip to content

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

Closed

Description

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

Activity

  1. changed the title [-]Bug: Error in Polyglot Notebook using Ollama Connector[/-] [+].Net: Bug: Error in Polyglot Notebook using Ollama Connector[/+] on Jan 27, 2025
  2. jonsequitur commented on Jan 28, 2025

    @jonsequitur

    .NET Interactive now requires the .NET 9 SDK.

  3. rogerbarreto commented on Jan 29, 2025

    @rogerbarreto
    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);
  4. dschilling commented on Jan 31, 2025

    @dschilling
    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.

  5. jonsequitur commented on Jan 31, 2025

    @jonsequitur

    Daniel Schilling (@dschilling) This is a known issue (#3757). Until it's fixed, a restart of VS Code should be sufficient to trigger the download of the latest dotnet-interactive tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions