-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathProgram.cs
More file actions
174 lines (155 loc) · 11.6 KB
/
Program.cs
File metadata and controls
174 lines (155 loc) · 11.6 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using Examples;
using Examples.Agents;
using Examples.Agents.Flows;
using Examples.Mcp;
using MaIN.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var Banner = @"
███╗ ███╗ █████╗ ██╗███╗ ██╗ ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗███████╗
████╗ ████║██╔══██╗██║████╗ ██║ ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔════╝
██╔████╔██║███████║██║██╔██╗ ██║ █████╗ ╚███╔╝ ███████║██╔████╔██║██████╔╝██║ █████╗ ███████╗
██║╚██╔╝██║██╔══██║██║██║╚██╗██║ ██╔══╝ ██╔██╗ ██╔══██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝ ╚════██║
██║ ╚═╝ ██║██║ ██║██║██║ ╚████║ ███████╗██╔╝ ██╗██║ ██║██║ ╚═╝ ██║██║ ███████╗███████╗███████║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚══════╝
╔══════════════════════════════════════════════════════════════════════════════════════════════════════╗
Interactive Example Runner v1.0 ";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(Banner);
Console.ResetColor();
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(configuration);
services.AddMaIN(configuration);
RegisterExamples(services);
var serviceProvider = services.BuildServiceProvider();
serviceProvider.UseMaIN();
await RunSelectedExample(serviceProvider);
static void RegisterExamples(IServiceCollection services)
{
services.AddTransient<ExampleRegistry>();
services.AddTransient<McpExample>();
services.AddTransient<ChatExample>();
services.AddTransient<ChatCustomGrammarExample>();
services.AddTransient<ChatWithFilesExample>();
services.AddTransient<ChatWithFilesFromStreamExample>();
services.AddTransient<ChatWithVisionExample>();
services.AddTransient<ChatWithImageGenExample>();
services.AddTransient<ChatFromExistingExample>();
services.AddTransient<ChatWithReasoningExample>();
services.AddTransient<AgentExample>();
services.AddTransient<AgentConversationExample>();
services.AddTransient<AgentWithRedirectExample>();
services.AddTransient<MultiBackendAgentWithRedirectExample>();
services.AddTransient<McpAgentsExample>();
services.AddTransient<AgentWithRedirectImageExample>();
services.AddTransient<AgentWithBecomeExample>();
services.AddTransient<AgentWithApiDataSourceExample>();
services.AddTransient<AgentTalkingToEachOtherExample>();
services.AddTransient<AgentWithKnowledgeFileExample>();
services.AddTransient<AgentWithKnowledgeWebExample>();
services.AddTransient<AgentWithKnowledgeMcpExample>();
services.AddTransient<AgentsComposedAsFlowExample>();
services.AddTransient<AgentsFlowLoadedExample>();
services.AddTransient<ChatExampleOpenAi>();
services.AddTransient<AgentWithWebDataSourceOpenAiExample>();
services.AddTransient<ChatWithImageGenOpenAiExample>();
services.AddTransient<ChatExampleGemini>();
services.AddTransient<ChatWithImageGenGeminiExample>();
services.AddTransient<ChatWithFilesExampleGemini>();
services.AddTransient<ChatWithReasoningDeepSeekExample>();
services.AddTransient<ChatWithTextToSpeechExample>();
services.AddTransient<ChatExampleGroqCloud>();
services.AddTransient<ChatExampleAnthropic>();
}
async Task RunSelectedExample(IServiceProvider serviceProvider)
{
var registry = serviceProvider.GetRequiredService<ExampleRegistry>();
var examples = registry.GetAvailableExamples();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n┌─────────────────────────────────────────────┐");
Console.WriteLine("│ Available Examples │");
Console.WriteLine("└─────────────────────────────────────────────┘");
Console.ResetColor();
for (int i = 0; i < examples.Count; i++)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"\n [{i + 1}] ");
Console.ForegroundColor = ConsoleColor.White;
Console.Write(examples[i].Name);
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n┌─────────────────────────────────────────────┐");
Console.Write($"│ >> Select example (1-{examples.Count}): ");
Console.CursorLeft = 45;
Console.WriteLine("│");
Console.WriteLine("└─────────────────────────────────────────────┘");
Console.ForegroundColor = ConsoleColor.White;
if (int.TryParse(Console.ReadLine(), out int selection) && selection > 0 && selection <= examples.Count)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(Banner);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"\n>> Running: {examples[selection - 1].Name}");
Console.WriteLine("╔════════════════════════════════════════════════════════════════════╗");
Console.WriteLine("║ Output Below ║");
Console.WriteLine("╚════════════════════════════════════════════════════════════════════╝");
Console.ResetColor();
var selectedExample = examples[selection - 1].Instance;
await selectedExample.Start();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\n╔════════════════════════════════════════════════════╗");
Console.WriteLine("║ [X] Error: Invalid selection. Please try again. ║");
Console.WriteLine("╚════════════════════════════════════════════════════╝");
Console.ResetColor();
}
}
public class ExampleRegistry(IServiceProvider serviceProvider)
{
public List<(string Name, IExample Instance)> GetAvailableExamples()
{
return new List<(string, IExample)>
{
("\u25a0 Basic Chat", serviceProvider.GetRequiredService<ChatExample>()),
("\u25a0 Chat with Files", serviceProvider.GetRequiredService<ChatWithFilesExample>()),
("\u25a0 Chat with custom grammar", serviceProvider.GetRequiredService<ChatCustomGrammarExample>()),
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
("\u25a0 Basic Agent", serviceProvider.GetRequiredService<AgentExample>()),
("\u25a0 Conversation Agent", serviceProvider.GetRequiredService<AgentConversationExample>()),
("\u25a0 Agent with Redirect", serviceProvider.GetRequiredService<AgentWithRedirectExample>()),
("\u25a0 Agent with Redirect (Multi backends)", serviceProvider.GetRequiredService<MultiBackendAgentWithRedirectExample>()),
("\u25a0 Agent with Redirect Image", serviceProvider.GetRequiredService<AgentWithRedirectImageExample>()),
("\u25a0 Agent with Become", serviceProvider.GetRequiredService<AgentWithBecomeExample>()),
("\u25a0 Agent with Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeFileExample>()),
("\u25a0 Agent with Web Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeWebExample>()),
("\u25a0 Agent with Mcp Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeMcpExample>()),
("\u25a0 Agent with API Data Source", serviceProvider.GetRequiredService<AgentWithApiDataSourceExample>()),
("\u25a0 Agents Talking to Each Other", serviceProvider.GetRequiredService<AgentTalkingToEachOtherExample>()),
("\u25a0 Agents Composed as Flow", serviceProvider.GetRequiredService<AgentsComposedAsFlowExample>()),
("\u25a0 Agents Flow Loaded", serviceProvider.GetRequiredService<AgentsFlowLoadedExample>()),
("\u25a0 OpenAi Chat", serviceProvider.GetRequiredService<ChatExampleOpenAi>()),
("\u25a0 OpenAi Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenOpenAiExample>()),
("\u25a0 OpenAi Agent with Web Data Source", serviceProvider.GetRequiredService<AgentWithWebDataSourceOpenAiExample>()),
("\u25a0 Gemini Chat", serviceProvider.GetRequiredService<ChatExampleGemini>()),
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
};
}
}