-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathChatCustomGrammarExample.cs
More file actions
33 lines (29 loc) · 989 Bytes
/
ChatCustomGrammarExample.cs
File metadata and controls
33 lines (29 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using MaIN.Core.Hub;
using MaIN.Domain.Entities;
using MaIN.Domain.Models;
using Grammar = MaIN.Domain.Models.Grammar;
namespace Examples.Chat;
public class ChatCustomGrammarExample : IExample
{
public async Task Start()
{
Console.WriteLine("ChatExample with grammar is running!");
var personGrammar = new Grammar("""
root ::= person
person ::= "{" ws "\"name\":" ws name "," ws "\"age\":" ws age "," ws "\"city\":" ws city ws "}"
name ::= "\"" [A-Za-z ]+ "\""
age ::= [1-9] | [1-9][0-9]
city ::= "\"" [A-Za-z ]+ "\""
ws ::= [ \t]*
""",
GrammarFormat.GBNF);
await AIHub.Chat()
.WithModel(Models.Local.Gemma2_2b)
.WithMessage("Generate random person")
.WithInferenceParams(new LocalInferenceParams
{
Grammar = personGrammar
})
.CompleteAsync(interactive: true);
}
}