Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Examples/Examples.SimpleConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using MaIN.Core;
using MaIN.Core.Hub;
using MaIN.Domain.Entities;
using OpenAI.Models;

MaINBootstrapper.Initialize();

Expand Down
2 changes: 0 additions & 2 deletions Examples/Examples/Agents/AgentExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.Knowledge;

namespace Examples.Agents;

Expand Down
1 change: 0 additions & 1 deletion Examples/Examples/Agents/AgentWithApiDataSourceExample.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.AgentSource;
using MaIN.Services.Services.Models.Commands;

namespace Examples.Agents;

Expand Down
3 changes: 0 additions & 3 deletions Examples/Examples/Agents/AgentWithKnowledgeFileExample.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.AgentSource;
using Microsoft.Identity.Client;

namespace Examples.Agents;

Expand Down
3 changes: 0 additions & 3 deletions Examples/Examples/Agents/AgentWithKnowledgeWebExample.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities;
using MaIN.Domain.Entities.Agents.AgentSource;
using Microsoft.Identity.Client;

namespace Examples.Agents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Configuration;
using MaIN.Domain.Entities.Agents.AgentSource;

namespace Examples.Agents;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;

namespace Examples.Agents;
namespace Examples.Agents.Flows;

public class AgentsComposedAsFlowExample : IExample
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ You need to use a lot of it. Imagine you are the voice of youth.
""";

var contextSecond = await AIHub.Agent()
.WithBackend(BackendType.OpenAi)
.WithModel("gpt-4o")
.WithInitialPrompt(systemPromptSecond)
.WithBackend(BackendType.OpenAi)
.CreateAsync(interactiveResponse: true);

var context = await AIHub.Agent()
Expand Down
4 changes: 2 additions & 2 deletions Examples/Examples/Chat/ChatCustomGrammarExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public async Task Start()
""", GrammarFormat.GBNF);

await AIHub.Chat()
.WithModel("gemma2:2b")
.WithMessage("Generate random person")
.WithInferenceParams(new InferenceParams
{
Grammar = personGrammar
})
.WithModel("gemma2:2b")
.WithMessage("Generate random person")
.CompleteAsync(interactive: true);
}
}
1 change: 0 additions & 1 deletion Examples/Examples/Chat/ChatExampleAnthropic.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Domain.Configuration;

namespace Examples.Chat;

Expand Down
1 change: 0 additions & 1 deletion Examples/Examples/Chat/ChatExampleToolsSimple.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Configuration;

namespace Examples.Chat;

Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/Chat/ChatExampleXai.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Examples.Utils;
using MaIN.Core.Hub;

namespace Examples;
namespace Examples.Chat;

public class ChatExampleXai : IExample
{
Expand Down
15 changes: 12 additions & 3 deletions Examples/Examples/Chat/ChatFromExistingExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using MaIN.Core.Hub;
using MaIN.Domain.Exceptions.Chats;

namespace Examples.Chat;

Expand All @@ -18,8 +19,16 @@ public async Task Start()
await result.WithMessage("And about physics?")
.CompleteAsync();

var chatNewContext = await AIHub.Chat().FromExisting(result.GetChatId());
var messages = chatNewContext.GetChatHistory();
Console.WriteLine(JsonSerializer.Serialize(messages));
try
{
var chatNewContext = await AIHub.Chat().FromExisting(result.GetChatId());
var messages = chatNewContext.GetChatHistory();
Console.WriteLine(JsonSerializer.Serialize(messages));
}
catch (ChatNotFoundException ex)
{
Console.WriteLine(ex.PublicErrorMessage);
}

}
}
14 changes: 7 additions & 7 deletions Examples/Examples/Chat/ChatGrammarExampleGemini.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public async Task Start()
""";

await AIHub.Chat()
.WithInferenceParams(new InferenceParams
{
Grammar = new Grammar(grammarValue, GrammarFormat.JSONSchema)
})
.WithModel("gemini-2.5-flash")
.WithMessage("Generate random person")
.CompleteAsync(interactive: true);
.WithModel("gemini-2.5-flash")
.WithMessage("Generate random person")
.WithInferenceParams(new InferenceParams
{
Grammar = new Grammar(grammarValue, GrammarFormat.JSONSchema)
})
.CompleteAsync(interactive: true);
}
}
2 changes: 1 addition & 1 deletion Examples/Examples/Chat/ChatWithImageGenOpenAiExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public async Task Start()
OpenAiExample.Setup(); // We need to provide OpenAi API key

var result = await AIHub.Chat()
.EnableVisual()
.WithModel("dall-e-3")
.EnableVisual()
.WithMessage("Generate rock style cow playing guitar")
.CompleteAsync();

Expand Down
2 changes: 2 additions & 0 deletions Examples/Examples/IExample.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
namespace Examples;

public interface IExample
{
Task Start();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/Mcp/AgentWithKnowledgeMcpExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public async Task Start()

AIHub.Extensions.DisableLLamaLogs();
var context = await AIHub.Agent()
.WithBackend(BackendType.OpenAi)
.WithModel("gpt-4.1-mini")
.WithBackend(BackendType.OpenAi)
.WithKnowledge(KnowledgeBuilder.Instance
.AddMcp(new MaIN.Domain.Entities.Mcp
{
Expand Down
4 changes: 2 additions & 2 deletions Examples/Examples/Mcp/McpAgentsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Configuration;

namespace Examples;
namespace Examples.Mcp;

public class McpAgentsExample : IExample
{
Expand All @@ -17,6 +17,7 @@ public async Task Start()
.CreateAsync(interactiveResponse: true);

var context = await AIHub.Agent()
.WithModel("gpt-4o-mini")
.WithBackend(BackendType.OpenAi)
.WithMcpConfig(new MaIN.Domain.Entities.Mcp
{
Expand All @@ -29,7 +30,6 @@ public async Task Start()
Command = "docker",
Model = "gpt-4o-mini"
})
.WithModel("gpt-4o-mini")
.WithSteps(StepBuilder.Instance
.Mcp()
.Redirect(agentId: contextSecond.GetAgentId())
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/Mcp/McpExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using MaIN.Core.Hub;
using MaIN.Domain.Configuration;

namespace Examples;
namespace Examples.Mcp;

public class McpExample : IExample
{
Expand Down
103 changes: 59 additions & 44 deletions Examples/Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;


var Banner = @"
███╗ ███╗ █████╗ ██╗███╗ ██╗ ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗███████╗
████╗ ████║██╔══██╗██║████╗ ██║ ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔════╝
Expand Down Expand Up @@ -121,7 +120,20 @@ async Task RunSelectedExample(IServiceProvider serviceProvider)
Console.ResetColor();

var selectedExample = examples[selection - 1].Instance;
await selectedExample.Start();
try
{
await selectedExample.Start();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("╔════════════════════════════════════════════════════════════════════╗");
Console.WriteLine("║ Error ║");
Console.WriteLine("╚════════════════════════════════════════════════════════════════════╝");
Console.ResetColor();

Console.WriteLine(ex.Message);
}
}
else
{
Expand All @@ -134,50 +146,53 @@ async Task RunSelectedExample(IServiceProvider serviceProvider)
}


public class ExampleRegistry(IServiceProvider serviceProvider)
namespace Examples
{
public List<(string Name, IExample Instance)> GetAvailableExamples()
public class ExampleRegistry(IServiceProvider serviceProvider)
{
return new List<(string, IExample)>
public List<(string Name, IExample Instance)> GetAvailableExamples()
{
("\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 Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
("\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 Tools (advanced)", serviceProvider.GetRequiredService<AgentExampleTools>()),
("\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 grammar", serviceProvider.GetRequiredService<ChatGrammarExampleGemini>()),
("\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 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
("\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>())
};
return
[
("\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 Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
("\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 Tools (advanced)", serviceProvider.GetRequiredService<AgentExampleTools>()),
("\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 grammar", serviceProvider.GetRequiredService<ChatGrammarExampleGemini>()),
("\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 xAI Chat", serviceProvider.GetRequiredService<ChatExampleXai>()),
("\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>())
];
}
}
}
2 changes: 0 additions & 2 deletions Examples/Examples/Utils/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Text.Json;

namespace Examples.Utils;

public static class Tools
Expand Down
3 changes: 2 additions & 1 deletion MaIN.Core.IntegrationTests/ChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public async Task Should_AnswerGameFromImage_ChatWithVision()

var result = await AIHub.Chat()
.WithModel("llama3.2:3b")
.WithMessage("What is the title of game?")

.WithMemoryParams(new MemoryParams
{
AnswerTokens = 1000
})
.WithMessage("What is the title of game?")
.WithFiles(images)
.CompleteAsync();

Expand Down
4 changes: 0 additions & 4 deletions MaIN.Core.IntegrationTests/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System.Net.Sockets;
using MaIN.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand Down
1 change: 0 additions & 1 deletion src/MaIN.Core.UnitTests/AgentContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using MaIN.Domain.Entities;
using MaIN.Domain.Entities.Agents;
using MaIN.Domain.Entities.Agents.Knowledge;
using MaIN.Services.Dtos;
using MaIN.Services.Services.Abstract;
using MaIN.Services.Services.Models;
using Moq;
Expand Down
1 change: 0 additions & 1 deletion src/MaIN.Core.UnitTests/ChatContextTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using MaIN.Core.Hub.Contexts;
using MaIN.Domain.Entities;
using MaIN.Services.Dtos;
using MaIN.Services.Services.Abstract;
using MaIN.Services.Services.Models;
using Moq;
Expand Down
Loading