Skip to content

.NET: How to run Ollama Sample? #5565

@ddobric

Description

@ddobric

Trying to compile the following sample:

https://learn.microsoft.com/en-us/agent-framework/agents/providers/ollama?tabs=ollama-native&pivots=programming-language-csharp

using System;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;

// Create an Ollama agent using Microsoft.Extensions.AI.Ollama
// Requires: dotnet add package Microsoft.Extensions.AI.Ollama --prerelease
var chatClient = new OllamaChatClient(
    new Uri("http://localhost:11434"),
    modelId: "llama3.2");

AIAgent agent = chatClient.AsAIAgent(
    instructions: "You are a helpful assistant running locally via Ollama.");

Console.WriteLine(await agent.RunAsync("What is the largest city in France?"));

Unfortunately, it is not clear which nuget package should be used for type OllamaChatClient?

Also, following the project file references, it is not clear where this type comes from.

  <ItemGroup>
    <PackageReference Include="OllamaSharp" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\..\..\src\Microsoft.Agents.AI\Microsoft.Agents.AI.csproj" />
  </ItemGroup>

I guess it is some sync issue between the documentation of published packages.

After adding the package Microsoft.Extensions.AI.Ollama and slightly changing the code, the sample compiles.

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions