Skip to content

Commit f0fe24c

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/custom_exceptions
# Conflicts: # Examples/Examples/Program.cs
2 parents 18cc2d4 + e0ec3be commit f0fe24c

File tree

20 files changed

+223
-33
lines changed

20 files changed

+223
-33
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static void RegisterExamples(IServiceCollection services)
7878
services.AddTransient<ChatExampleGroqCloud>();
7979
services.AddTransient<ChatExampleAnthropic>();
8080
services.AddTransient<ChatExampleXai>();
81+
services.AddTransient<ChatExampleOllama>();
8182
}
8283

8384
async Task RunSelectedExample(IServiceProvider serviceProvider)
@@ -194,5 +195,45 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
194195
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
195196
];
196197
}
198+
("\u25a0 Basic Chat", serviceProvider.GetRequiredService<ChatExample>()),
199+
("\u25a0 Chat with Files", serviceProvider.GetRequiredService<ChatWithFilesExample>()),
200+
("\u25a0 Chat with custom grammar", serviceProvider.GetRequiredService<ChatCustomGrammarExample>()),
201+
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
202+
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
203+
("\u25a0 Chat with Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
204+
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
205+
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
206+
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
207+
("\u25a0 Basic Agent", serviceProvider.GetRequiredService<AgentExample>()),
208+
("\u25a0 Conversation Agent", serviceProvider.GetRequiredService<AgentConversationExample>()),
209+
("\u25a0 Agent with Redirect", serviceProvider.GetRequiredService<AgentWithRedirectExample>()),
210+
("\u25a0 Agent with Redirect (Multi backends)", serviceProvider.GetRequiredService<MultiBackendAgentWithRedirectExample>()),
211+
("\u25a0 Agent with Redirect Image", serviceProvider.GetRequiredService<AgentWithRedirectImageExample>()),
212+
("\u25a0 Agent with Become", serviceProvider.GetRequiredService<AgentWithBecomeExample>()),
213+
("\u25a0 Agent with Tools (advanced)", serviceProvider.GetRequiredService<AgentExampleTools>()),
214+
("\u25a0 Agent with Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeFileExample>()),
215+
("\u25a0 Agent with Web Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeWebExample>()),
216+
("\u25a0 Agent with Mcp Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeMcpExample>()),
217+
("\u25a0 Agent with API Data Source", serviceProvider.GetRequiredService<AgentWithApiDataSourceExample>()),
218+
("\u25a0 Agents Talking to Each Other", serviceProvider.GetRequiredService<AgentTalkingToEachOtherExample>()),
219+
("\u25a0 Agents Composed as Flow", serviceProvider.GetRequiredService<AgentsComposedAsFlowExample>()),
220+
("\u25a0 Agents Flow Loaded", serviceProvider.GetRequiredService<AgentsFlowLoadedExample>()),
221+
("\u25a0 OpenAi Chat", serviceProvider.GetRequiredService<ChatExampleOpenAi>()),
222+
("\u25a0 OpenAi Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenOpenAiExample>()),
223+
("\u25a0 OpenAi Agent with Web Data Source", serviceProvider.GetRequiredService<AgentWithWebDataSourceOpenAiExample>()),
224+
("\u25a0 Gemini Chat", serviceProvider.GetRequiredService<ChatExampleGemini>()),
225+
("\u25a0 Gemini Chat with grammar", serviceProvider.GetRequiredService<ChatGrammarExampleGemini>()),
226+
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
227+
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
228+
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
229+
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
230+
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
231+
("\u25a0 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
232+
("\u25a0 Ollama Chat", serviceProvider.GetRequiredService<ChatExampleOllama>()),
233+
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
234+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
235+
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
236+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
237+
};
197238
}
198239
}
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
@@ -11,6 +11,7 @@ public class MaINSettings
1111
public string? DeepSeekKey { get; set; }
1212
public string? AnthropicKey { get; set; }
1313
public string? GroqCloudKey { get; set; }
14+
public string? OllamaKey { get; set; }
1415
public string? XaiKey { get; set; }
1516
public MongoDbSettings? MongoDbSettings { get; set; }
1617
public FileSystemSettings? FileSystemSettings { get; set; }
@@ -28,4 +29,5 @@ public enum BackendType
2829
GroqCloud = 4,
2930
Anthropic = 5,
3031
Xai = 6,
32+
Ollama = 7,
3133
}

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
@@ -77,6 +77,18 @@
7777
apiKeyVariable = LLMApiRegistry.Anthropic.ApiKeyEnvName;
7878
apiName = LLMApiRegistry.Anthropic.ApiName;
7979
break;
80+
81+
case "xai":
82+
Utils.Xai = true;
83+
apiKeyVariable = "XAI_API_KEY";
84+
apiName = "Xai";
85+
break;
86+
87+
case "ollama":
88+
Utils.Ollama = true;
89+
apiKeyVariable = "OLLAMA_API_KEY";
90+
apiName = "Ollama";
91+
break;
8092
}
8193

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

0 commit comments

Comments
 (0)