Skip to content

Commit c6bc62c

Browse files
committed
[#19] Add handling of LLM API errors, fix namespaces
1 parent 776f846 commit c6bc62c

File tree

94 files changed

+435
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+435
-205
lines changed

Examples/Examples/Agents/Flows/AgentsComposedAsFlowExample.cs

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

4-
namespace Examples.Agents;
4+
namespace Examples.Agents.Flows;
55

66
public class AgentsComposedAsFlowExample : IExample
77
{

Examples/Examples/Chat/ChatExampleXai.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 ChatExampleXai : IExample
77
{

Examples/Examples/Chat/ChatFromExistingExample.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22
using MaIN.Core.Hub;
33
using MaIN.Domain.Exceptions;
4+
using MaIN.Domain.Exceptions.Chats;
45

56
namespace Examples.Chat;
67

Examples/Examples/IExample.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
namespace Examples;
2+
13
public interface IExample
24
{
35
Task Start();

Examples/Examples/Mcp/McpAgentsExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using MaIN.Core.Hub.Utils;
33
using MaIN.Domain.Configuration;
44

5-
namespace Examples;
5+
namespace Examples.Mcp;
66

77
public class McpAgentsExample : IExample
88
{

Examples/Examples/Mcp/McpExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using MaIN.Core.Hub;
33
using MaIN.Domain.Configuration;
44

5-
namespace Examples;
5+
namespace Examples.Mcp;
66

77
public class McpExample : IExample
88
{

Examples/Examples/Program.cs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using Examples.Chat;
55
using Examples.Mcp;
66
using MaIN.Core;
7-
using MaIN.Domain.Exceptions;
87
using Microsoft.Extensions.Configuration;
98
using Microsoft.Extensions.DependencyInjection;
109

11-
1210
var Banner = @"
1311
███╗ ███╗ █████╗ ██╗███╗ ██╗ ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗███████╗
1412
████╗ ████║██╔══██╗██║████╗ ██║ ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔════╝
@@ -148,50 +146,53 @@ async Task RunSelectedExample(IServiceProvider serviceProvider)
148146
}
149147

150148

151-
public class ExampleRegistry(IServiceProvider serviceProvider)
149+
namespace Examples
152150
{
153-
public List<(string Name, IExample Instance)> GetAvailableExamples()
151+
public class ExampleRegistry(IServiceProvider serviceProvider)
154152
{
155-
return new List<(string, IExample)>
153+
public List<(string Name, IExample Instance)> GetAvailableExamples()
156154
{
157-
("\u25a0 Basic Chat", serviceProvider.GetRequiredService<ChatExample>()),
158-
("\u25a0 Chat with Files", serviceProvider.GetRequiredService<ChatWithFilesExample>()),
159-
("\u25a0 Chat with custom grammar", serviceProvider.GetRequiredService<ChatCustomGrammarExample>()),
160-
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
161-
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
162-
("\u25a0 Chat with Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
163-
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
164-
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
165-
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
166-
("\u25a0 Basic Agent", serviceProvider.GetRequiredService<AgentExample>()),
167-
("\u25a0 Conversation Agent", serviceProvider.GetRequiredService<AgentConversationExample>()),
168-
("\u25a0 Agent with Redirect", serviceProvider.GetRequiredService<AgentWithRedirectExample>()),
169-
("\u25a0 Agent with Redirect (Multi backends)", serviceProvider.GetRequiredService<MultiBackendAgentWithRedirectExample>()),
170-
("\u25a0 Agent with Redirect Image", serviceProvider.GetRequiredService<AgentWithRedirectImageExample>()),
171-
("\u25a0 Agent with Become", serviceProvider.GetRequiredService<AgentWithBecomeExample>()),
172-
("\u25a0 Agent with Tools (advanced)", serviceProvider.GetRequiredService<AgentExampleTools>()),
173-
("\u25a0 Agent with Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeFileExample>()),
174-
("\u25a0 Agent with Web Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeWebExample>()),
175-
("\u25a0 Agent with Mcp Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeMcpExample>()),
176-
("\u25a0 Agent with API Data Source", serviceProvider.GetRequiredService<AgentWithApiDataSourceExample>()),
177-
("\u25a0 Agents Talking to Each Other", serviceProvider.GetRequiredService<AgentTalkingToEachOtherExample>()),
178-
("\u25a0 Agents Composed as Flow", serviceProvider.GetRequiredService<AgentsComposedAsFlowExample>()),
179-
("\u25a0 Agents Flow Loaded", serviceProvider.GetRequiredService<AgentsFlowLoadedExample>()),
180-
("\u25a0 OpenAi Chat", serviceProvider.GetRequiredService<ChatExampleOpenAi>()),
181-
("\u25a0 OpenAi Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenOpenAiExample>()),
182-
("\u25a0 OpenAi Agent with Web Data Source", serviceProvider.GetRequiredService<AgentWithWebDataSourceOpenAiExample>()),
183-
("\u25a0 Gemini Chat", serviceProvider.GetRequiredService<ChatExampleGemini>()),
184-
("\u25a0 Gemini Chat with grammar", serviceProvider.GetRequiredService<ChatGrammarExampleGemini>()),
185-
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
186-
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
187-
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
188-
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
189-
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
190-
("\u25a0 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
191-
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
192-
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
193-
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
194-
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
195-
};
155+
return
156+
[
157+
("\u25a0 Basic Chat", serviceProvider.GetRequiredService<ChatExample>()),
158+
("\u25a0 Chat with Files", serviceProvider.GetRequiredService<ChatWithFilesExample>()),
159+
("\u25a0 Chat with custom grammar", serviceProvider.GetRequiredService<ChatCustomGrammarExample>()),
160+
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
161+
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
162+
("\u25a0 Chat with Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
163+
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
164+
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
165+
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
166+
("\u25a0 Basic Agent", serviceProvider.GetRequiredService<AgentExample>()),
167+
("\u25a0 Conversation Agent", serviceProvider.GetRequiredService<AgentConversationExample>()),
168+
("\u25a0 Agent with Redirect", serviceProvider.GetRequiredService<AgentWithRedirectExample>()),
169+
("\u25a0 Agent with Redirect (Multi backends)", serviceProvider.GetRequiredService<MultiBackendAgentWithRedirectExample>()),
170+
("\u25a0 Agent with Redirect Image", serviceProvider.GetRequiredService<AgentWithRedirectImageExample>()),
171+
("\u25a0 Agent with Become", serviceProvider.GetRequiredService<AgentWithBecomeExample>()),
172+
("\u25a0 Agent with Tools (advanced)", serviceProvider.GetRequiredService<AgentExampleTools>()),
173+
("\u25a0 Agent with Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeFileExample>()),
174+
("\u25a0 Agent with Web Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeWebExample>()),
175+
("\u25a0 Agent with Mcp Knowledge", serviceProvider.GetRequiredService<AgentWithKnowledgeMcpExample>()),
176+
("\u25a0 Agent with API Data Source", serviceProvider.GetRequiredService<AgentWithApiDataSourceExample>()),
177+
("\u25a0 Agents Talking to Each Other", serviceProvider.GetRequiredService<AgentTalkingToEachOtherExample>()),
178+
("\u25a0 Agents Composed as Flow", serviceProvider.GetRequiredService<AgentsComposedAsFlowExample>()),
179+
("\u25a0 Agents Flow Loaded", serviceProvider.GetRequiredService<AgentsFlowLoadedExample>()),
180+
("\u25a0 OpenAi Chat", serviceProvider.GetRequiredService<ChatExampleOpenAi>()),
181+
("\u25a0 OpenAi Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenOpenAiExample>()),
182+
("\u25a0 OpenAi Agent with Web Data Source", serviceProvider.GetRequiredService<AgentWithWebDataSourceOpenAiExample>()),
183+
("\u25a0 Gemini Chat", serviceProvider.GetRequiredService<ChatExampleGemini>()),
184+
("\u25a0 Gemini Chat with grammar", serviceProvider.GetRequiredService<ChatGrammarExampleGemini>()),
185+
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
186+
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
187+
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
188+
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
189+
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
190+
("\u25a0 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
191+
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
192+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
193+
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
194+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
195+
];
196+
}
196197
}
197198
}

src/MaIN.Core/Hub/Contexts/AgentContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using MaIN.Domain.Entities.Agents.Knowledge;
1010
using MaIN.Domain.Entities.Tools;
1111
using MaIN.Domain.Exceptions;
12+
using MaIN.Domain.Exceptions.Agents;
1213
using MaIN.Services.Constants;
1314

1415
namespace MaIN.Core.Hub.Contexts;

src/MaIN.Core/Hub/Contexts/ChatContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using MaIN.Domain.Entities;
33
using MaIN.Domain.Entities.Tools;
44
using MaIN.Domain.Exceptions;
5+
using MaIN.Domain.Exceptions.Chats;
56
using MaIN.Domain.Models;
67
using MaIN.Services;
78
using MaIN.Services.Constants;

src/MaIN.Core/Hub/Contexts/FlowContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MaIN.Domain.Entities.Agents;
66
using MaIN.Domain.Entities.Agents.AgentSource;
77
using MaIN.Domain.Exceptions;
8+
using MaIN.Domain.Exceptions.Flows;
89
using MaIN.Services.Dtos;
910
using MaIN.Services.Mappers;
1011
using MaIN.Services.Services.Abstract;

0 commit comments

Comments
 (0)