Skip to content

Commit 3f3d452

Browse files
committed
Adding ollama demo app
1 parent 3a580b3 commit 3f3d452

27 files changed

+763
-3
lines changed

CommunityToolkit.Aspire.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Aspire.Hos
4949
EndProject
5050
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}"
5151
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
5260
Global
5361
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5462
Debug|Any CPU = Debug|Any CPU
@@ -123,6 +131,18 @@ Global
123131
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
124132
{1DB27FA0-E7E4-42C1-B062-4DE0128D4FA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
125133
{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
126146
EndGlobalSection
127147
GlobalSection(SolutionProperties) = preSolution
128148
HideSolutionNode = FALSE
@@ -148,6 +168,10 @@ Global
148168
{E8F93376-1367-4A7B-A729-116199804356} = {899F0713-7FC6-4750-BAFC-AC650B35B453}
149169
{6C6696CB-8DCC-4E93-A667-A313D70E0220} = {414151D4-7009-4E78-A5C6-D99EBD1E67D1}
150170
{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}
151175
EndGlobalSection
152176
GlobalSection(ExtensibilityGlobals) = postSolution
153177
SolutionGuid = {08B1D4B8-D2C5-4A64-BB8B-E1A2B29525F0}

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
<PackageVersion Include="xunit" Version="2.9.0" />
3030
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
3131
<!-- External packages -->
32-
<PackageVersion Include="OllamaSharp" Version="1.1.12" />
32+
<PackageVersion Include="OllamaSharp" Version="3.0.7" />
3333
</ItemGroup>
3434
</Project>
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsAspireSharedProject>true</IsAspireSharedProject>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12+
13+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" />
14+
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" />
15+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" />
16+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
17+
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
18+
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
19+
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Diagnostics.HealthChecks;
5+
using Microsoft.Extensions.Logging;
6+
using OpenTelemetry;
7+
using OpenTelemetry.Metrics;
8+
using OpenTelemetry.Trace;
9+
10+
namespace Microsoft.Extensions.Hosting;
11+
12+
// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
13+
// This project should be referenced by each service project in your solution.
14+
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
15+
public static class Extensions
16+
{
17+
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
18+
{
19+
builder.ConfigureOpenTelemetry();
20+
21+
builder.AddDefaultHealthChecks();
22+
23+
builder.Services.AddServiceDiscovery();
24+
25+
builder.Services.ConfigureHttpClientDefaults(http =>
26+
{
27+
// Turn on resilience by default
28+
http.AddStandardResilienceHandler();
29+
30+
// Turn on service discovery by default
31+
http.AddServiceDiscovery();
32+
});
33+
34+
return builder;
35+
}
36+
37+
public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
38+
{
39+
builder.Logging.AddOpenTelemetry(logging =>
40+
{
41+
logging.IncludeFormattedMessage = true;
42+
logging.IncludeScopes = true;
43+
});
44+
45+
builder.Services.AddOpenTelemetry()
46+
.WithMetrics(metrics =>
47+
{
48+
metrics.AddAspNetCoreInstrumentation()
49+
.AddHttpClientInstrumentation()
50+
.AddRuntimeInstrumentation();
51+
})
52+
.WithTracing(tracing =>
53+
{
54+
tracing.AddAspNetCoreInstrumentation()
55+
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
56+
//.AddGrpcClientInstrumentation()
57+
.AddHttpClientInstrumentation();
58+
});
59+
60+
builder.AddOpenTelemetryExporters();
61+
62+
return builder;
63+
}
64+
65+
private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder)
66+
{
67+
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
68+
69+
if (useOtlpExporter)
70+
{
71+
builder.Services.AddOpenTelemetry().UseOtlpExporter();
72+
}
73+
74+
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
75+
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
76+
//{
77+
// builder.Services.AddOpenTelemetry()
78+
// .UseAzureMonitor();
79+
//}
80+
81+
return builder;
82+
}
83+
84+
public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder)
85+
{
86+
builder.Services.AddHealthChecks()
87+
// Add a default liveness check to ensure app is responsive
88+
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
89+
90+
return builder;
91+
}
92+
93+
public static WebApplication MapDefaultEndpoints(this WebApplication app)
94+
{
95+
// Adding health checks endpoints to applications in non-development environments has security implications.
96+
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
97+
if (app.Environment.IsDevelopment())
98+
{
99+
// All health checks must pass for app to be considered ready to accept traffic after starting
100+
app.MapHealthChecks("/health");
101+
102+
// Only health checks tagged with the "live" tag must pass for app to be considered alive
103+
app.MapHealthChecks("/alive", new HealthCheckOptions
104+
{
105+
Predicate = r => r.Tags.Contains("live")
106+
});
107+
}
108+
109+
return app;
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults\CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="OllamaSharp" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
9+
<link rel="stylesheet" href="app.css" />
10+
<link rel="stylesheet" href="CommunityToolkit.Aspire.Hosting.Ollama.Web.styles.css" />
11+
<link rel="icon" type="image/png" href="favicon.png" />
12+
<HeadOutlet />
13+
</head>
14+
15+
<body>
16+
<Routes />
17+
<script src="_framework/blazor.web.js"></script>
18+
</body>
19+
20+
</html>

0 commit comments

Comments
 (0)