Skip to content

Commit 91da0ec

Browse files
authored
Merge pull request #26 from CommunityToolkit/ollama
Ollama
2 parents 0176bc0 + 7380e01 commit 91da0ec

40 files changed

+1248
-1
lines changed

CommunityToolkit.Aspire.sln

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hos
4545
EndProject
4646
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests", "tests\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests\CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests.csproj", "{E8F93376-1367-4A7B-A729-116199804356}"
4747
EndProject
48+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama", "src\CommunityToolkit.Aspire.Hosting.Ollama\CommunityToolkit.Aspire.Hosting.Ollama.csproj", "{6C6696CB-8DCC-4E93-A667-A313D70E0220}"
49+
EndProject
50+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama.Tests", "tests\CommunityToolkit.Aspire.Hosting.Ollama.Tests\CommunityToolkit.Aspire.Hosting.Ollama.Tests.csproj", "{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}"
51+
EndProject
52+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ollama", "ollama", "{14BD8AE7-C8DF-4C7C-8244-7F74C101569D}"
53+
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama.AppHost", "examples\ollama\CommunityToolkit.Aspire.Hosting.Ollama.AppHost\CommunityToolkit.Aspire.Hosting.Ollama.AppHost.csproj", "{F4602DC8-3C17-4834-B640-9A3B27FE278A}"
55+
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults", "examples\ollama\CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults.csproj", "{2F037600-2002-4A13-9359-98FB0D2416BE}"
57+
EndProject
58+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hosting.Ollama.Web", "examples\ollama\CommunityToolkit.Aspire.Hosting.Ollama.Web\CommunityToolkit.Aspire.Hosting.Ollama.Web.csproj", "{0A17021E-5F10-429B-88C8-E4073EADACB6}"
59+
EndProject
4860
Global
4961
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5062
Debug|Any CPU = Debug|Any CPU
@@ -111,6 +123,26 @@ Global
111123
{E8F93376-1367-4A7B-A729-116199804356}.Debug|Any CPU.Build.0 = Debug|Any CPU
112124
{E8F93376-1367-4A7B-A729-116199804356}.Release|Any CPU.ActiveCfg = Release|Any CPU
113125
{E8F93376-1367-4A7B-A729-116199804356}.Release|Any CPU.Build.0 = Release|Any CPU
126+
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127+
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Debug|Any CPU.Build.0 = Debug|Any CPU
128+
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Release|Any CPU.ActiveCfg = Release|Any CPU
129+
{6C6696CB-8DCC-4E93-A667-A313D70E0220}.Release|Any CPU.Build.0 = Release|Any CPU
130+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
132+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
133+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Release|Any CPU.Build.0 = Release|Any CPU
134+
{F4602DC8-3C17-4834-B640-9A3B27FE278A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
135+
{F4602DC8-3C17-4834-B640-9A3B27FE278A}.Debug|Any CPU.Build.0 = Debug|Any CPU
136+
{F4602DC8-3C17-4834-B640-9A3B27FE278A}.Release|Any CPU.ActiveCfg = Release|Any CPU
137+
{F4602DC8-3C17-4834-B640-9A3B27FE278A}.Release|Any CPU.Build.0 = Release|Any CPU
138+
{2F037600-2002-4A13-9359-98FB0D2416BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
139+
{2F037600-2002-4A13-9359-98FB0D2416BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
140+
{2F037600-2002-4A13-9359-98FB0D2416BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
141+
{2F037600-2002-4A13-9359-98FB0D2416BE}.Release|Any CPU.Build.0 = Release|Any CPU
142+
{0A17021E-5F10-429B-88C8-E4073EADACB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
143+
{0A17021E-5F10-429B-88C8-E4073EADACB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
144+
{0A17021E-5F10-429B-88C8-E4073EADACB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
145+
{0A17021E-5F10-429B-88C8-E4073EADACB6}.Release|Any CPU.Build.0 = Release|Any CPU
114146
EndGlobalSection
115147
GlobalSection(SolutionProperties) = preSolution
116148
HideSolutionNode = FALSE
@@ -134,6 +166,12 @@ Global
134166
{261AC321-8982-4C3A-8DBF-DAFC95F97697} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
135167
{D3F5EF2B-CE37-4339-A8BD-50E6C5B2AFA1} = {261AC321-8982-4C3A-8DBF-DAFC95F97697}
136168
{E8F93376-1367-4A7B-A729-116199804356} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
169+
{6C6696CB-8DCC-4E93-A667-A313D70E0220} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
170+
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
171+
{14BD8AE7-C8DF-4C7C-8244-7F74C101569D} = {8519CC01-1370-47C8-AD94-B0F326B1563F}
172+
{F4602DC8-3C17-4834-B640-9A3B27FE278A} = {14BD8AE7-C8DF-4C7C-8244-7F74C101569D}
173+
{2F037600-2002-4A13-9359-98FB0D2416BE} = {14BD8AE7-C8DF-4C7C-8244-7F74C101569D}
174+
{0A17021E-5F10-429B-88C8-E4073EADACB6} = {14BD8AE7-C8DF-4C7C-8244-7F74C101569D}
137175
EndGlobalSection
138176
GlobalSection(ExtensibilityGlobals) = postSolution
139177
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}

Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@
2828
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
2929
<PackageVersion Include="xunit" Version="2.9.0" />
3030
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
31+
<!-- External packages -->
32+
<PackageVersion Include="OllamaSharp" Version="3.0.7" />
3133
</ItemGroup>
3234
</Project>

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository contains the source code for the .NET Aspire Community Toolkit,
1515
| [`Hosting.Azure.StaticWebApps`][swa-integration-docs] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields]][swa-nuget] | [![CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps][swa-shields-preview]][swa-nuget-preview] | A hosting integration for the [Azure Static Web Apps emulator](https://learn.microsoft.com/azure/static-web-apps/static-web-apps-cli-overview) (Note: this does not support deployment of a project to Azure Static Web Apps). |
1616
| [`Hosting.Java`][java-integration-docs] | [![CommunityToolkit.Aspire.Hosting.Java][java-shields]][java-nuget] | [![CommunityToolkit.Aspire.Hosting.Java][java-shields-preview]][java-nuget-preview] | A integration for running Java code in .NET Aspire either using the local JDK or using a container. |
1717
| [`Hosting.NodeJS.Extensions`][nodejs-ext-integration-docs] | [![CommunityToolkit.Aspire.NodeJS.Extensions][nodejs-ext-shields]][nodejs-ext-nuget] | [![CommunityToolkit.Aspire.Hosting.NodeJS.Extensions][nodejs-ext-shields-preview]][nodejs-ext-nuget-preview] | An integration that contains some additional extensions for running Node.js applications |
18+
| [`Hosting.Ollama`][ollama-integration-docs] | [![CommunityToolkit.Aspire.Ollama][ollama-shields]][ollama-nuget] | [![CommunityToolkit.Aspire.Hosting.Ollama][ollama-shields-preview]][ollama-nuget-preview] | An Aspire component leveraging the [Ollama](https://ollama.com) container with support for downloading a model on startup. |
1819

1920
## 🙌 Getting Started
2021

@@ -51,4 +52,8 @@ Made with [contrib.rocks](https://contrib.rocks).
5152
[nodejs-ext-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/
5253
[nodejs-ext-shields-preview]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions?label=nuget%20(preview)
5354
[nodejs-ext-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/absoluteLatest
54-
55+
[ollama-integration-docs]: https://communitytoolkit.github.io/aspire/integrations/hosting-ollama
56+
[ollama-shields]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.Ollama
57+
[ollama-nuget]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Ollama/
58+
[ollama-shields-preview]: https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Hosting.Ollama?label=nuget%20(preview)
59+
[ollama-nuget-preview]: https://nuget.org/packages/CommunityToolkit.Aspire.Hosting.Ollama/absoluteLatest

docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Each integration is a separate NuGet package that you can add to your project. A
77
- [CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps](integrations/hosting-azure-static-web-apps.md)
88
- [CommunityToolkit.Aspire.Hosting.Java](integrations/hosting-java.md)
99
- [CommunityToolkit.Aspire.Hosting.NodeJS.Extensions](integrations/hosting-nodejs-extensions.md)
10+
- [CommunityToolkit.Aspire.Hosting.Ollama](integrations/hosting-ollama.md)

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The Community Toolkit consists of a collection of NuGet packages that can be add
1111
- [CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps](integrations/hosting-azure-static-web-apps.md)
1212
- [CommunityToolkit.Aspire.Hosting.Java](integrations/hosting-java.md)
1313
- [CommunityToolkit.Aspire.Hosting.NodeJS.Extensions](integrations/hosting-nodejs-extensions.md)
14+
- [CommunityToolkit.Aspire.Hosting.Ollama](integrations/hosting-ollama.md)
1415

1516
## .NET Aspire and the Community Toolkit
1617

docs/integrations/hosting-ollama.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# CommunityToolkit.Aspire.Hosting.Ollama
2+
3+
[![CommunityToolkit.Aspire.Ollama](https://img.shields.io/nuget/v/CommunityToolkit.Aspire.Ollama)](https://nuget.org/packages/CommunityToolkit.Aspire.Ollama/) | [![CommunityToolkit.Aspire.Ollama (latest)](<https://img.shields.io/nuget/vpre/CommunityToolkit.Aspire.Ollama?label=nuget%20(preview)>)](https://nuget.org/packages/CommunityToolkit.Aspire.Ollama/absoluteLatest)
4+
5+
## Overview
6+
7+
An Aspire component leveraging the [Ollama](https://ollama.com) container with support for downloading a model on startup.
8+
9+
## Usage
10+
11+
Use the static `AddOllama` method to add this container component to the application builder.
12+
13+
```csharp
14+
// The distributed application builder is created here
15+
16+
var ollama = builder.AddOllama("ollama");
17+
18+
// The builder is used to build and run the app somewhere down here
19+
```
20+
21+
### Configuration
22+
23+
The AddOllama method has optional arguments to set the `name`, `port` and `modelName`.
24+
The `name` is what gets displayed in the Aspire orchestration app against this component.
25+
The `port` is provided randomly by Aspire. If for whatever reason you need a fixed port, you can set that here.
26+
The `modelName` specifies what LLM to pull when it starts up. The default is `llama3`. You can also set this to null to prevent any models being pulled on startup - leaving you with a plain Ollama container to work with.
27+
28+
## Downloading the LLM
29+
30+
When the Ollama container for this component first spins up, this component will download the LLM (llama3 unless otherwise specified).
31+
The progress of this download will be displayed in the State column for this component on the Aspire orchestration app.
32+
Important: Keep the Aspire orchestration app open until the download is complete, otherwise the download will be cancelled.
33+
In the spirit of productivity, we recommend kicking off this process before heading for lunch.
34+
This component binds a volume called "ollama" so that once the model is fully downloaded, it'll be available for subsequent runs.
35+
36+
## Accessing the Ollama server from other Aspire components
37+
38+
You can pass the ollama component to other Aspire components in the usual way:
39+
40+
```csharp
41+
builder.AddMyComponent().WithReference(ollama);
42+
```
43+
44+
Within that component (e.g. a web app), you can fetch the Ollama connection string from the application builder as follows.
45+
Note that if you changed the name of the Ollama component via the `name` argument, then you'll need to use that here when specifying which connection string to get.
46+
47+
```csharp
48+
var connectionString = builder.Configuration.GetConnectionString("Ollama");
49+
```
50+
51+
You can then call any of the Ollama endpoints through this connection string. We recommend using the [OllamaSharp](https://www.nuget.org/packages/OllamaSharp) client to do this.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
<UserSecretsId>f39fb70f-21f3-4af9-89b4-3062ff4431e6</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Ollama.Web\CommunityToolkit.Aspire.Hosting.Ollama.Web.csproj" />
14+
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Ollama\CommunityToolkit.Aspire.Hosting.Ollama.csproj" IsAspireProjectResource="false" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Aspire.Hosting.AppHost" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var ollama = builder.AddOllama("ollama", modelName: "phi3");
4+
5+
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_Ollama_Web>("webfrontend")
6+
.WithExternalHttpEndpoints()
7+
.WithReference(ollama)
8+
.WithEnvironment("ollama:model", "phi3");
9+
10+
builder.Build().Run();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17117;http://localhost:15077",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21075",
13+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22200"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15077",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19024",
25+
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20271"
26+
}
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)