Skip to content

Commit a858504

Browse files
committed
Merge branch 'main' into feature/grok
2 parents 65ef696 + 4adaf07 commit a858504

78 files changed

Lines changed: 2371 additions & 790 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: 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+
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using MaIN.Core.Hub;
22

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

55
public class ChatExample : IExample
66
{

Examples/Examples/Chat/ChatExampleAnthropic.cs

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

4-
namespace Examples;
5+
namespace Examples.Chat;
56

67
public class ChatExampleAnthropic : IExample
78
{

Examples/Examples/Chat/ChatExampleGemini.cs

Lines changed: 1 addition & 1 deletion
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
{

Examples/Examples/Chat/ChatExampleGroqCloud.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3-
using MaIN.Domain.Configuration;
43

5-
namespace Examples;
4+
namespace Examples.Chat;
65

76
public class ChatExampleGroqCloud : IExample
87
{

Examples/Examples/Chat/ChatExampleOpenAi.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using Examples.Utils;
22
using MaIN.Core.Hub;
3-
using MaIN.Domain.Configuration;
43

5-
namespace Examples;
4+
namespace Examples.Chat;
65

76
public class ChatExampleOpenAi : IExample
87
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Core.Hub.Utils;
4+
using MaIN.Domain.Configuration;
5+
6+
namespace Examples.Chat;
7+
8+
public class ChatExampleToolsSimple : IExample
9+
{
10+
public async Task Start()
11+
{
12+
OpenAiExample.Setup(); //We need to provide OpenAi API key
13+
14+
Console.WriteLine("(OpenAi) ChatExample with tools is running!");
15+
16+
await AIHub.Chat()
17+
.WithModel("gpt-5-nano")
18+
.WithMessage("What time is it right now?")
19+
.WithTools(new ToolsConfigurationBuilder()
20+
.AddTool(
21+
name: "get_current_time",
22+
description: "Get the current date and time",
23+
execute: Tools.GetCurrentTime)
24+
.WithToolChoice("auto")
25+
.Build())
26+
.CompleteAsync(interactive: true);
27+
}
28+
}

Examples/Examples/Chat/ChatFromExistingExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Text.Json;
22
using MaIN.Core.Hub;
33

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

66
public class ChatFromExistingExample : IExample
77
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Domain.Entities;
4+
using MaIN.Domain.Models;
5+
6+
namespace Examples.Chat;
7+
8+
public class ChatGrammarExampleGemini : IExample
9+
{
10+
public async Task Start()
11+
{
12+
GeminiExample.Setup(); //We need to provide Gemini API key
13+
Console.WriteLine("(Gemini) ChatExample is running!");
14+
15+
var grammarValue = """
16+
{
17+
"$schema": "https://json-schema.org/draft/2020-12/schema",
18+
"title": "User",
19+
"type": "object",
20+
"properties": {
21+
"name": {
22+
"type": "string",
23+
"description": "Full name of the user."
24+
},
25+
"age": {
26+
"type": "integer",
27+
"minimum": 0,
28+
"description": "User's age in years."
29+
},
30+
"email": {
31+
"type": "string",
32+
"format": "email",
33+
"description": "User's email address."
34+
}
35+
},
36+
"required": ["name", "email"]
37+
}
38+
""";
39+
40+
await AIHub.Chat()
41+
.WithInferenceParams(new InferenceParams
42+
{
43+
Grammar = new Grammar(grammarValue, GrammarFormat.JSONSchema)
44+
})
45+
.WithModel("gemini-2.5-flash")
46+
.WithMessage("Generate random person")
47+
.CompleteAsync(interactive: true);
48+
}
49+
}

0 commit comments

Comments
 (0)