Skip to content

Commit 66013e3

Browse files
authored
Refactor/model configuration (#119)
- Add Abstract AIModel class - Add generic implementations and capabilities interfaces - Apply models in the code and add predefined cloud models - Make TTS models implement ITTSModel - Fix and add tests - register test model before each test
1 parent a939360 commit 66013e3

64 files changed

Lines changed: 1417 additions & 297 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
using MaIN.Core;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Models.Concrete;
34

45
MaINBootstrapper.Initialize();
56

6-
var model = AIHub.Model();
7+
var modelContext = AIHub.Model();
78

8-
var m = model.GetModel("gemma3:4b");
9-
var x = model.GetModel("llama3.2:3b");
10-
await model.DownloadAsync(x.Name);
9+
// Get models using ModelRegistry
10+
var gemma = modelContext.GetModel("gemma3-4b");
11+
var llama = modelContext.GetModel("llama3.2-3b");
1112

13+
// Or use strongly-typed models directly
14+
var gemma2b = new Gemma2_2b();
15+
Console.WriteLine($"Model: {gemma2b.Name}, File: {gemma2b.FileName}");
1216

17+
// Download a model
18+
await modelContext.DownloadAsync(gemma2b.Id);

Examples/Examples/Chat/ChatCustomGrammarExample.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MaIN.Core.Hub;
22
using MaIN.Domain.Entities;
33
using MaIN.Domain.Models;
4+
using MaIN.Domain.Models.Concrete;
45
using Grammar = MaIN.Domain.Models.Grammar;
56

67
namespace Examples.Chat;
@@ -21,7 +22,7 @@ public async Task Start()
2122
""", GrammarFormat.GBNF);
2223

2324
await AIHub.Chat()
24-
.WithModel("gemma2:2b")
25+
.WithModel<Gemma2_2b>()
2526
.WithMessage("Generate random person")
2627
.WithInferenceParams(new InferenceParams
2728
{

Examples/Examples/Chat/ChatExample.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MaIN.Core.Hub;
2+
using MaIN.Domain.Models.Concrete;
23

34
namespace Examples.Chat;
45

@@ -8,8 +9,9 @@ public async Task Start()
89
{
910
Console.WriteLine("ChatExample is running!");
1011

12+
// Using strongly-typed model
1113
await AIHub.Chat()
12-
.WithModel("gemma2:2b")
14+
.WithModel<Gemma2_2b>()
1315
.WithMessage("Where do hedgehogs goes at night?")
1416
.CompleteAsync(interactive: true);
1517
}

Examples/Examples/Chat/ChatExampleAnthropic.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Models.Concrete;
34

45
namespace Examples.Chat;
56

@@ -11,7 +12,7 @@ public async Task Start()
1112
Console.WriteLine("(Anthropic) ChatExample is running!");
1213

1314
await AIHub.Chat()
14-
.WithModel("claude-sonnet-4-20250514")
15+
.WithModel<ClaudeSonnet4>()
1516
.WithMessage("Write a haiku about programming on Monday morning.")
1617
.CompleteAsync(interactive: true);
1718
}

Examples/Examples/Chat/ChatExampleGemini.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Configuration;
4+
using MaIN.Domain.Models.Abstract;
5+
using MaIN.Domain.Models.Concrete;
36

47
namespace Examples.Chat;
58

@@ -10,9 +13,18 @@ public async Task Start()
1013
GeminiExample.Setup(); //We need to provide Gemini API key
1114
Console.WriteLine("(Gemini) ChatExample is running!");
1215

16+
// Get built-in Gemini 2.5 Flash model
17+
var model = AIHub.Model().GetModel(new Gemini2_5Flash().Id);
18+
19+
// Or create the model manually if not available in the hub
20+
var customModel = new GenericCloudModel(
21+
"gemini-2.5-flash",
22+
BackendType.Gemini
23+
);
24+
1325
await AIHub.Chat()
14-
.WithModel("gemini-2.5-flash")
26+
.WithModel(customModel)
1527
.WithMessage("Is the killer whale the smartest animal?")
1628
.CompleteAsync(interactive: true);
1729
}
18-
}
30+
}

Examples/Examples/Chat/ChatExampleGroqCloud.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Models.Concrete;
34

45
namespace Examples.Chat;
56

@@ -11,7 +12,7 @@ public async Task Start()
1112
Console.WriteLine("(GroqCloud) ChatExample is running!");
1213

1314
await AIHub.Chat()
14-
.WithModel("llama-3.1-8b-instant")
15+
.WithModel<Llama3_1_8bInstant>()
1516
.WithMessage("Which color do people like the most?")
1617
.CompleteAsync(interactive: true);
1718
}

Examples/Examples/Chat/ChatExampleOllama.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Models.Concrete;
34

45
namespace Examples.Chat;
56

@@ -11,7 +12,7 @@ public async Task Start()
1112
Console.WriteLine("(Ollama) ChatExample is running!");
1213

1314
await AIHub.Chat()
14-
.WithModel("gemma3:4b")
15+
.WithModel<OllamaGemma3_4b>()
1516
.WithMessage("Write a short poem about the color green.")
1617
.CompleteAsync(interactive: true);
1718
}

Examples/Examples/Chat/ChatExampleOpenAi.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Models.Concrete;
34

45
namespace Examples.Chat;
56

@@ -12,7 +13,7 @@ public async Task Start()
1213
Console.WriteLine("(OpenAi) ChatExample is running!");
1314

1415
await AIHub.Chat()
15-
.WithModel("gpt-5-nano")
16+
.WithModel<Gpt5Nano>()
1617
.WithMessage("What do you consider to be the greatest invention in history?")
1718
.CompleteAsync(interactive: true);
1819
}

Examples/Examples/Chat/ChatExampleToolsSimple.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
33
using MaIN.Core.Hub.Utils;
4+
using MaIN.Domain.Models.Concrete;
45

56
namespace Examples.Chat;
67

@@ -13,7 +14,7 @@ public async Task Start()
1314
Console.WriteLine("(OpenAi) ChatExample with tools is running!");
1415

1516
await AIHub.Chat()
16-
.WithModel("gpt-5-nano")
17+
.WithModel<Gpt5Nano>()
1718
.WithMessage("What time is it right now?")
1819
.WithTools(new ToolsConfigurationBuilder()
1920
.AddTool(

Examples/Examples/Chat/ChatExampleToolsSimpleLocalLLM.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
33
using MaIN.Core.Hub.Utils;
4+
using MaIN.Domain.Models.Concrete;
45

56
namespace Examples.Chat;
67

@@ -11,7 +12,7 @@ public async Task Start()
1112
Console.WriteLine("Local LLM ChatExample with tools is running!");
1213

1314
await AIHub.Chat()
14-
.WithModel("gemma3:4b")
15+
.WithModel<Gemma3_4b>()
1516
.WithMessage("What time is it right now?")
1617
.WithTools(new ToolsConfigurationBuilder()
1718
.AddTool(

0 commit comments

Comments
 (0)