Skip to content

Commit e0ec3be

Browse files
authored
Feat: Ollama integration (#118)
1 parent 563ca6b commit e0ec3be

File tree

21 files changed

+184
-37
lines changed

21 files changed

+184
-37
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
4+
namespace Examples.Chat;
5+
6+
public class ChatExampleOllama : IExample
7+
{
8+
public async Task Start()
9+
{
10+
OllamaExample.Setup(); // We need to set Ollama backend type and optionally provide Ollama API key
11+
Console.WriteLine("(Ollama) ChatExample is running!");
12+
13+
await AIHub.Chat()
14+
.WithModel("gemma3:4b")
15+
.WithMessage("Write a short poem about the color green.")
16+
.CompleteAsync(interactive: true);
17+
}
18+
}

Examples/Examples/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static void RegisterExamples(IServiceCollection services)
7979
services.AddTransient<ChatExampleGroqCloud>();
8080
services.AddTransient<ChatExampleAnthropic>();
8181
services.AddTransient<ChatExampleXai>();
82+
services.AddTransient<ChatExampleOllama>();
8283
}
8384

8485
async Task RunSelectedExample(IServiceProvider serviceProvider)
@@ -174,6 +175,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
174175
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
175176
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
176177
("\u25a0 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
178+
("\u25a0 Ollama Chat", serviceProvider.GetRequiredService<ChatExampleOllama>()),
177179
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
178180
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
179181
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using MaIN.Core;
2+
using MaIN.Domain.Configuration;
3+
4+
namespace Examples.Utils;
5+
6+
public class OllamaExample
7+
{
8+
public static void Setup()
9+
{
10+
MaINBootstrapper.Initialize(configureSettings: (options) =>
11+
{
12+
options.BackendType = BackendType.Ollama;
13+
//options.OllamaKey = "<YOUR_OLLAMA_KEY>"; // set only if you want to use Ollama cloud
14+
});
15+
}
16+
}

MaIN.Core.IntegrationTests/MaIN.Core.IntegrationTests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.22" />
1211
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
13-
<PackageReference Include="Moq" Version="4.20.72" />
1412
<PackageReference Include="xunit" Version="2.9.3" />
1513
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
1614
<PrivateAssets>all</PrivateAssets>
@@ -19,7 +17,7 @@
1917
</ItemGroup>
2018

2119
<ItemGroup>
22-
<Using Include="Xunit"/>
20+
<Using Include="Xunit" />
2321
</ItemGroup>
2422

2523
<ItemGroup>

Releases/0.8.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.8.1 release
2+
3+
- Add Ollama integration

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.8.0</version>
5+
<version>0.8.1</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Core/MaIN.Core.csproj

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="GTranslate" Version="2.3.1" />
11-
<PackageReference Include="HtmlAgilityPack" Version="1.12.4" />
12-
<PackageReference Include="LLamaSharp" Version="0.25.0" />
1310
<PackageReference Include="LLamaSharp.Backend.Cuda12" Version="0.25.0" />
14-
<PackageReference Include="LLamaSharp.kernel-memory" Version="0.25.0" />
15-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1" />
16-
<PackageReference Include="Microsoft.KernelMemory" Version="0.98.250508.3" />
17-
<PackageReference Include="Microsoft.KernelMemory.SemanticKernelPlugin" Version="0.98.250508.3" />
18-
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
19-
<PackageReference Include="Tesseract" Version="5.2.0" />
2011
<PackageReference Include="Tesseract.Data.English" Version="4.0.0" />
2112
</ItemGroup>
2213

@@ -33,7 +24,7 @@
3324
</ItemGroup>
3425

3526
<Target Name="link_deps" AfterTargets="AfterBuild" Condition="$([MSBuild]::IsOSPlatform('OSX'))">
36-
<Exec Command="ln -sf /opt/homebrew/lib/libleptonica.dylib $(OutDir)x64/libleptonica-1.82.0.dylib"/>
37-
<Exec Command="ln -sf /opt/homebrew/lib/libtesseract.dylib $(OutDir)x64/libtesseract50.dylib"/>
27+
<Exec Command="ln -sf /opt/homebrew/lib/libleptonica.dylib $(OutDir)x64/libleptonica-1.82.0.dylib" />
28+
<Exec Command="ln -sf /opt/homebrew/lib/libtesseract.dylib $(OutDir)x64/libtesseract50.dylib" />
3829
</Target>
3930
</Project>

src/MaIN.Domain/Configuration/MaINSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class MaINSettings
1313
public string? DeepSeekKey { get; set; }
1414
public string? AnthropicKey { get; set; }
1515
public string? GroqCloudKey { get; set; }
16+
public string? OllamaKey { get; set; }
1617
public string? XaiKey { get; set; }
1718
public MongoDbSettings? MongoDbSettings { get; set; }
1819
public FileSystemSettings? FileSystemSettings { get; set; }
@@ -30,4 +31,5 @@ public enum BackendType
3031
GroqCloud = 4,
3132
Anthropic = 5,
3233
Xai = 6,
34+
Ollama = 7,
3335
}

src/MaIN.InferPage/MaIN.InferPage.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Costura.Fody" Version="6.0.0">
12-
<PrivateAssets>all</PrivateAssets>
13-
</PackageReference>
1411
<PackageReference Include="Markdig" Version="0.44.0" />
15-
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.13.2" />
1612
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.13.2" />
1713
</ItemGroup>
1814

src/MaIN.InferPage/Program.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@
7676
apiKeyVariable = "ANTHROPIC_API_KEY";
7777
apiName = "Anthropic";
7878
break;
79+
80+
case "xai":
81+
Utils.Xai = true;
82+
apiKeyVariable = "XAI_API_KEY";
83+
apiName = "Xai";
84+
break;
85+
86+
case "ollama":
87+
Utils.Ollama = true;
88+
apiKeyVariable = "OLLAMA_API_KEY";
89+
apiName = "Ollama";
90+
break;
7991
}
8092

8193
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
@@ -128,6 +140,20 @@
128140
settings.BackendType = BackendType.Anthropic;
129141
});
130142
}
143+
else if (Utils.Xai)
144+
{
145+
builder.Services.AddMaIN(builder.Configuration, settings =>
146+
{
147+
settings.BackendType = BackendType.Xai;
148+
});
149+
}
150+
else if (Utils.Ollama)
151+
{
152+
builder.Services.AddMaIN(builder.Configuration, settings =>
153+
{
154+
settings.BackendType = BackendType.Ollama;
155+
});
156+
}
131157
else
132158
{
133159
if (Utils.Path == null && !KnownModels.IsModelSupported(Utils.Model!))

0 commit comments

Comments
 (0)