Skip to content

Commit 1e3db90

Browse files
committed
Merge branch 'main' into feature/custom_exceptions
# Conflicts: # src/MaIN.Core/Hub/Contexts/ChatContext.cs # src/MaIN.Services/Services/AgentService.cs # src/MaIN.Services/Services/Steps/AnswerStepHandler.cs
2 parents d45740d + 4adaf07 commit 1e3db90

156 files changed

Lines changed: 6993 additions & 324 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.

Examples/Examples.SimpleConsole/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
var model = AIHub.Model();
99

1010
var m = model.GetModel("gemma3:4b");
11-
1211
var x = model.GetModel("llama3.2:3b");
1312
await model.DownloadAsync(x.Name);
1413

Examples/Examples/Agents/AgentExample.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using MaIN.Core.Hub;
2+
using MaIN.Core.Hub.Utils;
3+
using MaIN.Domain.Entities.Agents.Knowledge;
24

35
namespace Examples.Agents;
46

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Core.Hub.Utils;
4+
5+
namespace Examples.Agents;
6+
7+
public class AgentExampleTools : IExample
8+
{
9+
public async Task Start()
10+
{
11+
AnthropicExample.Setup();
12+
Console.WriteLine("(Anthropic) Tool example is running!");
13+
14+
var context = await AIHub.Agent()
15+
.WithModel("claude-sonnet-4-5-20250929")
16+
.WithSteps(StepBuilder.Instance
17+
.Answer()
18+
.Build())
19+
.WithTools(new ToolsConfigurationBuilder()
20+
.AddTool<ListNotesArgs>(
21+
"list_notes",
22+
"List all available notes",
23+
new
24+
{
25+
type = "object",
26+
properties = new
27+
{
28+
folder = new { type = "string", description = "Notes folder", @default = "notes" }
29+
}
30+
},
31+
NoteTools.ListNotes)
32+
.AddTool<ReadNoteArgs>(
33+
"read_note",
34+
"Read the content of a specific note",
35+
new
36+
{
37+
type = "object",
38+
properties = new
39+
{
40+
noteName = new
41+
{ type = "string", description = "Name of the note (without .txt extension)" }
42+
},
43+
required = new[] { "noteName" }
44+
},
45+
NoteTools.ReadNote)
46+
.AddTool<SaveNoteArgs>(
47+
"save_note",
48+
"Save or update a note with new content",
49+
new
50+
{
51+
type = "object",
52+
properties = new
53+
{
54+
noteName = new
55+
{ type = "string", description = "Name of the note (without .txt extension)" },
56+
content = new { type = "string", description = "Content to save in the note" }
57+
},
58+
required = new[] { "noteName", "content" }
59+
},
60+
NoteTools.SaveNote)
61+
.WithToolChoice("auto")
62+
.Build())
63+
.CreateAsync(interactiveResponse: true);
64+
65+
await context.ProcessAsync("What notes do I currently have?");
66+
67+
Console.WriteLine("--//--");
68+
69+
await context.ProcessAsync("Create a new note for a shopping list that includes healthy foods.");
70+
}
71+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Core.Hub.Utils;
4+
using MaIN.Domain.Entities.Agents.AgentSource;
5+
using Microsoft.Identity.Client;
6+
7+
namespace Examples.Agents;
8+
9+
public class AgentWithKnowledgeFileExample : IExample
10+
{
11+
public async Task Start()
12+
{
13+
Console.WriteLine("Agent with knowledge base example");
14+
AIHub.Extensions.DisableLLamaLogs();
15+
var context = await AIHub.Agent()
16+
.WithModel("gemma3:4b")
17+
.WithInitialPrompt("""
18+
You are a helpful assistant that answers questions about a company. Try to
19+
help employees find answers to their questions. Company you work for is TechVibe Solutions.
20+
""")
21+
.WithKnowledge(KnowledgeBuilder.Instance
22+
.AddFile("people.md", "./Files/Knowledge/people.md",
23+
tags: ["workers", "employees", "company"])
24+
.AddFile("organization.md", "./Files/Knowledge/organization.md",
25+
tags:["company structure", "company policy", "company culture", "company overview"])
26+
.AddFile("events.md", "./Files/Knowledge/events.md",
27+
tags: ["company events", "company calendar", "company agenda"])
28+
.AddFile("office_layout.md", "./Files/Knowledge/office_layout.md",
29+
tags: ["company layout", "company facilities", "company environment", "office items", "supplies"]))
30+
.WithSteps(StepBuilder.Instance
31+
.AnswerUseKnowledge()
32+
.Build())
33+
.CreateAsync();
34+
35+
var result = await context
36+
.ProcessAsync("Hey! Where I can find some printer paper?");
37+
Console.WriteLine(result.Message.Content);;
38+
39+
}
40+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Core.Hub.Utils;
4+
using MaIN.Domain.Entities;
5+
using MaIN.Domain.Entities.Agents.AgentSource;
6+
using Microsoft.Identity.Client;
7+
8+
namespace Examples.Agents;
9+
10+
public class AgentWithKnowledgeWebExample : IExample
11+
{
12+
public async Task Start()
13+
{
14+
Console.WriteLine("Piano Learning Assistant with Focused Knowledge Sources");
15+
16+
AIHub.Extensions.DisableLLamaLogs();
17+
var context = await AIHub.Agent()
18+
.WithModel("llama3.2:3b")
19+
.WithMemoryParams(new MemoryParams(){ContextSize = 4096})
20+
.WithInitialPrompt("""
21+
You are an expert piano instructor specializing in teaching specific pieces,
22+
techniques, and solving common playing problems. Help students learn exact
23+
fingerings, chord progressions, and troubleshoot technical issues with
24+
detailed, step-by-step guidance for both classical and popular music.
25+
""")
26+
.WithKnowledge(KnowledgeBuilder.Instance
27+
.AddUrl("piano_scales_major", "https://www.pianoscales.org/major.html",
28+
tags: ["scale_fingerings", "c_major_scale", "d_major_scale", "fingering_patterns"])
29+
.AddUrl("piano_chord_database", "https://www.pianochord.org/",
30+
tags: ["chord_fingerings", "cmaj7_chord", "chord_inversions", "left_hand_chords"])
31+
.AddUrl("fundamentals_practice_book", "https://fundamentals-of-piano-practice.readthedocs.io/",
32+
tags: ["memorization_techniques", "mental_play_method", "practice_efficiency", "difficult_passages"])
33+
.AddUrl("hanon_exercises", "https://www.hanon-online.com/",
34+
tags: ["hanon_exercises", "finger_independence", "daily_technical_work", "exercise_1_through_20"])
35+
.AddUrl("sheet_music_reading",
36+
"https://www.simplifyingtheory.com/how-to-read-sheet-music-for-beginners/",
37+
tags: ["bass_clef_reading", "treble_clef_notes", "note_identification", "staff_reading_speed"])
38+
.AddUrl("piano_fundamentals", "https://music2me.com/en/magazine/learn-piano-in-13-steps",
39+
tags: ["proper_posture", "finger_numbering", "hand_position", "keyboard_orientation"])
40+
.AddUrl("theory_lessons", "https://www.8notes.com/theory/",
41+
tags: ["interval_identification", "key_signatures", "circle_of_fifths", "time_signatures"])
42+
.AddUrl("piano_terms", "https://www.libertyparkmusic.com/musical-terms-learning-piano/",
43+
tags: ["dynamics_markings", "tempo_markings", "articulation_symbols", "expression_terms"]))
44+
.WithSteps(StepBuilder.Instance
45+
.AnswerUseKnowledge()
46+
.Build())
47+
.CreateAsync();
48+
49+
var result = await context
50+
.ProcessAsync("I want to learn the C major scale. What's the exact fingering pattern for both hands?" + "I want short and concrete answer");
51+
52+
Console.WriteLine(result.Message.Content);
53+
}
54+
}

Examples/Examples/Agents/AgentWithWebDataSourceOpenAiExample.cs

Lines changed: 1 addition & 0 deletions
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.Configuration;
45
using MaIN.Domain.Entities.Agents.AgentSource;
56

67
namespace Examples.Agents;

Examples/Examples/Chat/ChatCustomGrammarExample.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
using LLama.Sampling;
21
using MaIN.Core.Hub;
32
using MaIN.Domain.Entities;
3+
using MaIN.Domain.Models;
4+
using Grammar = MaIN.Domain.Models.Grammar;
45

5-
namespace Examples;
6+
namespace Examples.Chat;
67

78
public class ChatCustomGrammarExample : IExample
89
{
910
public async Task Start()
1011
{
1112
Console.WriteLine("ChatExample with grammar is running!");
1213

13-
var personGrammar = """
14-
root ::= person
15-
person ::= "{" ws "\"name\":" ws name "," ws "\"age\":" ws age "," ws "\"city\":" ws city ws "}"
16-
name ::= "\"" [A-Za-z ]+ "\""
17-
age ::= [1-9] | [1-9][0-9]
18-
city ::= "\"" [A-Za-z ]+ "\""
19-
ws ::= [ \t]*
20-
""";
14+
var personGrammar = new Grammar("""
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+
""", GrammarFormat.GBNF);
2122

2223
await AIHub.Chat()
23-
.WithInferenceParams(new InferenceParams()
24+
.WithInferenceParams(new InferenceParams
2425
{
2526
Grammar = personGrammar
2627
})

Examples/Examples/Chat/ChatExample.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
using MaIN.Core.Hub;
22

3-
namespace Examples;
3+
namespace Examples.Chat;
44

55
public class ChatExample : IExample
66
{
77
public async Task Start()
88
{
99
Console.WriteLine("ChatExample is running!");
1010

11-
var context = AIHub.Chat().WithModel("gemma2:2b");
12-
13-
await context
11+
await AIHub.Chat()
12+
.WithModel("gemma2:2b")
1413
.WithMessage("Where do hedgehogs goes at night?")
1514
.CompleteAsync(interactive: true);
1615
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Domain.Configuration;
4+
5+
namespace Examples.Chat;
6+
7+
public class ChatExampleAnthropic : IExample
8+
{
9+
public async Task Start()
10+
{
11+
AnthropicExample.Setup(); //We need to provide Anthropic API key
12+
Console.WriteLine("(Anthropic) ChatExample is running!");
13+
14+
await AIHub.Chat()
15+
.WithModel("claude-sonnet-4-20250514")
16+
.WithMessage("Write a haiku about programming on Monday morning.")
17+
.CompleteAsync(interactive: true);
18+
}
19+
}

Examples/Examples/Chat/ChatExampleGemini.cs

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

4-
namespace Examples;
4+
namespace Examples.Chat;
55

66
public class ChatExampleGemini : IExample
77
{
@@ -11,7 +11,7 @@ public async Task Start()
1111
Console.WriteLine("(Gemini) ChatExample is running!");
1212

1313
await AIHub.Chat()
14-
.WithModel("gemini-2.0-flash")
14+
.WithModel("gemini-2.5-flash")
1515
.WithMessage("Is the killer whale the smartest animal?")
1616
.CompleteAsync(interactive: true);
1717
}

0 commit comments

Comments
 (0)