Skip to content

Commit 36396df

Browse files
committed
Remove WithModel(AIModel) and WithModel<TModel>
WithModel(AIModel) and WithModel<TModel> makes more questions than answers. It gives user one clear workflow. Add this flow with register as an example."
1 parent 13aa063 commit 36396df

31 files changed

Lines changed: 320 additions & 217 deletions

Examples/Examples/Agents/AgentExample.cs

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

34
namespace Examples.Agents;
45

@@ -24,13 +25,13 @@ has the best possible counsel as she seeks to reclaim the Iron Throne.
2425
""";
2526

2627
var context = AIHub.Agent()
27-
.WithModel("llama3.2:3b")
28+
.WithModel(Models.Local.Llama3_2_3b)
2829
.WithInitialPrompt(systemPrompt)
2930
.Create();
30-
31+
3132
var result = await context
3233
.ProcessAsync("Where is the Iron Throne located? I need this information for Lady Princess");
3334

3435
Console.WriteLine(result.Message.Content);
3536
}
36-
}
37+
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using MaIN.Core.Hub;
22
using MaIN.Domain.Entities;
33
using MaIN.Domain.Models;
4-
using MaIN.Domain.Models.Concrete;
54
using Grammar = MaIN.Domain.Models.Grammar;
65

76
namespace Examples.Chat;
@@ -13,21 +12,22 @@ public async Task Start()
1312
Console.WriteLine("ChatExample with grammar is running!");
1413

1514
var personGrammar = new Grammar("""
16-
root ::= person
17-
person ::= "{" ws "\"name\":" ws name "," ws "\"age\":" ws age "," ws "\"city\":" ws city ws "}"
18-
name ::= "\"" [A-Za-z ]+ "\""
19-
age ::= [1-9] | [1-9][0-9]
20-
city ::= "\"" [A-Za-z ]+ "\""
21-
ws ::= [ \t]*
22-
""", GrammarFormat.GBNF);
15+
root ::= person
16+
person ::= "{" ws "\"name\":" ws name "," ws "\"age\":" ws age "," ws "\"city\":" ws city ws "}"
17+
name ::= "\"" [A-Za-z ]+ "\""
18+
age ::= [1-9] | [1-9][0-9]
19+
city ::= "\"" [A-Za-z ]+ "\""
20+
ws ::= [ \t]*
21+
""",
22+
GrammarFormat.GBNF);
2323

2424
await AIHub.Chat()
25-
.WithModel<Gemma2_2b>()
25+
.WithModel(Models.Local.Gemma2_2b)
2626
.WithMessage("Generate random person")
2727
.WithInferenceParams(new InferenceParams
2828
{
2929
Grammar = personGrammar
3030
})
3131
.CompleteAsync(interactive: true);
3232
}
33-
}
33+
}

Examples/Examples/Chat/ChatExample.cs

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

44
namespace Examples.Chat;
55

@@ -11,9 +11,9 @@ public async Task Start()
1111

1212
// Using strongly-typed model
1313
await AIHub.Chat()
14-
.WithModel<Gemma2_2b>()
14+
.WithModel(Models.Local.Gemma2_2b)
1515
.EnsureModelDownloaded()
1616
.WithMessage("Where do hedgehogs goes at night?")
1717
.CompleteAsync(interactive: true);
1818
}
19-
}
19+
}

Examples/Examples/Chat/ChatExampleAnthropic.cs

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

55
namespace Examples.Chat;
66

@@ -12,8 +12,8 @@ public async Task Start()
1212
Console.WriteLine("(Anthropic) ChatExample is running!");
1313

1414
await AIHub.Chat()
15-
.WithModel<ClaudeSonnet4>()
15+
.WithModel(Models.Anthropic.ClaudeSonnet4)
1616
.WithMessage("Write a haiku about programming on Monday morning.")
1717
.CompleteAsync(interactive: true);
1818
}
19-
}
19+
}

Examples/Examples/Chat/ChatExampleGemini.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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;
3+
using MaIN.Domain.Models;
64

75
namespace Examples.Chat;
86

@@ -13,17 +11,8 @@ public async Task Start()
1311
GeminiExample.Setup(); //We need to provide Gemini API key
1412
Console.WriteLine("(Gemini) ChatExample is running!");
1513

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-
2514
await AIHub.Chat()
26-
.WithModel(customModel)
15+
.WithModel(Models.Gemini.Gemini2_5Flash)
2716
.WithMessage("Is the killer whale the smartest animal?")
2817
.CompleteAsync(interactive: true);
2918
}

Examples/Examples/Chat/ChatExampleGroqCloud.cs

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

55
namespace Examples.Chat;
66

@@ -12,8 +12,8 @@ public async Task Start()
1212
Console.WriteLine("(GroqCloud) ChatExample is running!");
1313

1414
await AIHub.Chat()
15-
.WithModel<Llama3_1_8bInstant>()
15+
.WithModel(Models.Groq.Llama3_1_8bInstant)
1616
.WithMessage("Which color do people like the most?")
1717
.CompleteAsync(interactive: true);
1818
}
19-
}
19+
}

Examples/Examples/Chat/ChatExampleOllama.cs

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

55
namespace Examples.Chat;
66

@@ -12,8 +12,8 @@ public async Task Start()
1212
Console.WriteLine("(Ollama) ChatExample is running!");
1313

1414
await AIHub.Chat()
15-
.WithModel<OllamaGemma3_4b>()
15+
.WithModel(Models.Ollama.Gemma3_4b)
1616
.WithMessage("Write a short poem about the color green.")
1717
.CompleteAsync(interactive: true);
1818
}
19-
}
19+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3-
using MaIN.Domain.Models.Concrete;
3+
using MaIN.Domain.Models;
44

55
namespace Examples.Chat;
66

@@ -9,12 +9,12 @@ public class ChatExampleOpenAi : IExample
99
public async Task Start()
1010
{
1111
OpenAiExample.Setup(); //We need to provide OpenAi API key
12-
13-
Console.WriteLine("(OpenAi) ChatExample is running!");
14-
12+
13+
Console.WriteLine("(OpenAi) ChatExample is running!");
14+
1515
await AIHub.Chat()
16-
.WithModel<Gpt5Nano>()
16+
.WithModel(Models.OpenAi.Gpt5Nano)
1717
.WithMessage("What do you consider to be the greatest invention in history?")
1818
.CompleteAsync(interactive: true);
1919
}
20-
}
20+
}

Examples/Examples/Chat/ChatExampleToolsSimple.cs

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

66
namespace Examples.Chat;
77

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

1616
await AIHub.Chat()
17-
.WithModel<Gpt5Nano>()
17+
.WithModel(Models.OpenAi.Gpt5Nano)
1818
.WithMessage("What time is it right now?")
1919
.WithTools(new ToolsConfigurationBuilder()
2020
.AddTool(
2121
name: "get_current_time",
2222
description: "Get the current date and time",
23-
execute: Tools.GetCurrentTime)
23+
execute: Tools.GetCurrentTime)
2424
.WithToolChoice("auto")
2525
.Build())
2626
.CompleteAsync(interactive: true);

Examples/Examples/Chat/ChatExampleToolsSimpleLocalLLM.cs

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

66
namespace Examples.Chat;
77

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

1414
await AIHub.Chat()
15-
.WithModel<Gemma3_4b>()
15+
.WithModel(Models.Local.Gemma3_4b)
1616
.WithMessage("What time is it right now?")
1717
.WithTools(new ToolsConfigurationBuilder()
1818
.AddTool(
@@ -23,4 +23,4 @@ await AIHub.Chat()
2323
.Build())
2424
.CompleteAsync(interactive: true);
2525
}
26-
}
26+
}

0 commit comments

Comments
 (0)