Skip to content

Support running native Ollama - #978

Merged
aaronpowell merged 3 commits into
CommunityToolkit:mainfrom
cdschneider:ollama
Nov 22, 2025
Merged

Support running native Ollama#978
aaronpowell merged 3 commits into
CommunityToolkit:mainfrom
cdschneider:ollama

Conversation

@cdschneider

Copy link
Copy Markdown
Contributor

Closes#608

Adds OllamaExecutableResource to the CommunityToolkit.Aspire.Hosting.Ollama hosting integration for running ollama natively as Aspire resources

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes ⚠️
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Breaking changes are here mainly in updating OllamaResource properties and generic constraints to use a new IOllamaResource interface

Other information

  • Includes Github action/runtime setup to install ollama (using the ai-action/setup-ollama action)
  • Updated Ollama/AppHostTests to use examples/ollama apphost project; from the looks of it, it appeared Ollama AppHost tests were the only one not using an examples/ project

CopilotAI review requested due to automatic review settings November 18, 2025 05:08

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for running Ollama natively as an executable resource in addition to the existing container-based approach. It introduces OllamaExecutableResource alongside a new IOllamaResource interface to support both execution modes uniformly.

Key changes:

  • Introduced IOllamaResource interface to abstract common Ollama resource functionality
  • Added OllamaExecutableResource for running Ollama as a native executable process
  • Updated extension methods and tests to work with both container and executable resources

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests.csprojUpdated project reference to use example AppHost instead of test-specific AppHost
tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AppHostTests.csRefactored tests to validate both container and executable Ollama resources using IOllamaResource
tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AddOllamaTests.csRemoved extraneous blank line
tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AddOllamaLocalTests.csAdded comprehensive test coverage for AddOllamaLocal functionality
src/CommunityToolkit.Aspire.Hosting.Ollama/OpenWebUIResource.csUpdated to use IOllamaResource interface instead of concrete OllamaResource type
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.csAdded AddOllamaLocal method and refactored shared command logic to support both resource types
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.OpenWebUI.csFixed Open WebUI URL generation to properly handle both resource types using ReferenceExpressionBuilder
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResourceBuilderExtensions.Model.csUpdated model extension methods to accept IOllamaResource instead of concrete type
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaResource.csImplements IOllamaResource interface with inherited documentation
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaModelResource.csUpdated to reference IOllamaResource as parent type
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaExecutableResource.csNew executable resource implementation for running Ollama natively
src/CommunityToolkit.Aspire.Hosting.Ollama/IOllamaResource.csNew interface defining common Ollama resource contract
examples/ollama/CommunityToolkit.Aspire.Hosting.Ollama.AppHost/Program.csUpdated example to demonstrate AddOllamaLocal usage
.github/actions/setup-runtimes-caching/action.ymlAdded Ollama installation step to CI workflow

Comment threadtests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AddOllamaLocalTests.cs Outdated
Comment threadtests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/AddOllamaLocalTests.cs Outdated
@cdschneider

Copy link
Copy Markdown
ContributorAuthor

@dotnet-policy-service agree

@aaronpowellaaronpowell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some API changes/suggestions and it looks like we have test failures going on

Comment on lines +121 to +125
- uses: ai-action/setup-ollama@v1
name: Setup Ollama
if: ${{ inputs.name == 'Full' || contains(inputs.name, 'Hosting.Ollama') }}
with:
version: 0.11.8

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best that we set it up on all Ollama tests runs, as we should do CI on both the container and non-container versions of Ollama

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, to avoid any extra workflow/actions setup on non-ollama tests I felt like this was as specific as I could get. The AppHostTests that test both container/non-container versions live in a single test project (CommunityToolkit.Aspire.Hosting.Ollama.Tests)


var ollama = builder.AddOllama("ollama")
.WithDataVolume()
var ollama = builder.AddOllamaLocal("ollama", targetPort: 11435)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a separate resource in the app host so we can have both resources demoed

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Ollama and Ollama local resources exist in this example AppHost (ollama2-named resource is added to builder on line 9). This example previously registered two Ollama (container) resource, I just made one now use local.

Is there another way you want this example modified to demo both container and local options?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you're right, I totally forgot that was the case

/// </remarks>
/// <param name="name">The name of the resource.</param>
/// <param name="command">The command to execute.</param>
public class OllamaExecutableResource(string name, string command) : ExecutableResource(name, command, string.Empty), IOllamaResource

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't command be hard coded?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! Mainly I was following how other executable resources (like Java) were setup where the command name was passed in from the builder/extension method:

varresource=newJavaAppExecutableResource(name,"java",workingDirectory);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right - I wouldn't follow the Java one, it was one of the first ones and the patterns have a evolved since then

<ProjectReference Include="..\..\src\CommunityToolkit.Aspire.OllamaSharp\CommunityToolkit.Aspire.OllamaSharp.csproj" />
<ProjectReference Include="..\CommunityToolkit.Aspire.Testing\CommunityToolkit.Aspire.Testing.csproj" />
<ProjectReference Include="..\..\tests-app-hosts\Ollama.AppHost\Ollama.AppHost.csproj" />
<ProjectReference Include="..\..\examples\ollama\CommunityToolkit.Aspire.Hosting.Ollama.AppHost\CommunityToolkit.Aspire.Hosting.Ollama.AppHost.csproj" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use the custom app host because running on the github actions infra keeps causing memory issues.

…ama command in resource and exclude ollama local from manifest
@cdschneider

Copy link
Copy Markdown
ContributorAuthor

Some API changes/suggestions and it looks like we have test failures going on

Thanks for taking a look @aaronpowell! I've updated this with some of your feedback suggestions, including switching the Hosting.Ollama.Tests to point back to that tests-app-hosts/Ollama.AppHost to help with addressing the CI failures (the previous run looked like it was a runner resource-related issue preventing healthy startups).

@aaronpowell
aaronpowell merged commit f6bc304 into CommunityToolkit:mainNov 22, 2025
107 checks passed
@aaronpowellaaronpowell added this to the 13 milestone Nov 22, 2025
@cdschneider
cdschneider deleted the ollama branch December 9, 2025 21:38
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support native macOS (Apple Silicon) execution without Docker

3 participants

@cdschneider@aaronpowell