Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Examples/Examples/Chat/ChatExampleToolsSimple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class ChatExampleToolsSimple : IExample
public async Task Start()
{
OpenAiExample.Setup(); //We need to provide OpenAi API key
Console.WriteLine("(OpenAi) ChatExample with tools is running!");

Console.WriteLine("(OpenAi) ChatExample with tools is running!");

await AIHub.Chat()
.WithModel("gpt-5-nano")
.WithMessage("What time is it right now?")
Expand All @@ -24,4 +24,4 @@ await AIHub.Chat()
.Build())
.CompleteAsync(interactive: true);
}
}
}
25 changes: 25 additions & 0 deletions Examples/Examples/Chat/ChatExampleToolsSimpleLocalLLM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;

namespace Examples.Chat;

public class ChatExampleToolsSimpleLocalLLM : IExample
{
public async Task Start()
{
Console.WriteLine("Local LLM ChatExample with tools is running!");

await AIHub.Chat()
.WithModel("gemma3:4b")
.WithMessage("What time is it right now?")
.WithTools(new ToolsConfigurationBuilder()
.AddTool(
name: "get_current_time",
description: "Get the current date and time",
execute: Tools.GetCurrentTime)
.WithToolChoice("auto")
.Build())
.CompleteAsync(interactive: true);
}
}
4 changes: 3 additions & 1 deletion Examples/Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static void RegisterExamples(IServiceCollection services)
services.AddTransient<ChatFromExistingExample>();
services.AddTransient<ChatWithReasoningExample>();
services.AddTransient<ChatExampleToolsSimple>();
services.AddTransient<ChatExampleToolsSimpleLocalLLM>();
services.AddTransient<AgentExampleTools>();
services.AddTransient<AgentExample>();
services.AddTransient<AgentConversationExample>();
Expand Down Expand Up @@ -161,6 +162,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
("\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 Tools (simple Local LLM)", serviceProvider.GetRequiredService<ChatExampleToolsSimpleLocalLLM>()),
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
Expand Down Expand Up @@ -197,4 +199,4 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
];
}
};
}
}
3 changes: 3 additions & 0 deletions Releases/0.9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 0.9.0 release

- Add tool calling to local models
2 changes: 1 addition & 1 deletion src/MaIN.Core/.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>MaIN.NET</id>
<version>0.8.1</version>
<version>0.9.0</version>
<authors>Wisedev</authors>
<owners>Wisedev</owners>
<icon>favicon.png</icon>
Expand Down
15 changes: 10 additions & 5 deletions src/MaIN.Domain/Entities/Tools/FunctionCall.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace MaIN.Domain.Entities.Tools;
using System.Text.Json.Serialization;

public class FunctionCall
namespace MaIN.Domain.Entities.Tools;

public sealed record FunctionCall
{
public string Name { get; set; } = null!;
public string Arguments { get; set; } = null!;
}
[JsonPropertyName("name")]
public string Name { get; init; } = string.Empty;

[JsonPropertyName("arguments")]
public string Arguments { get; init; } = "{}";
}
15 changes: 15 additions & 0 deletions src/MaIN.Domain/Entities/Tools/ToolCall.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;

namespace MaIN.Domain.Entities.Tools;

public sealed record ToolCall
{
[JsonPropertyName("id")]
public string Id { get; init; } = string.Empty;

[JsonPropertyName("type")]
public string Type { get; init; } = "function";

[JsonPropertyName("function")]
public FunctionCall Function { get; init; } = new();
}
6 changes: 5 additions & 1 deletion src/MaIN.Domain/Entities/Tools/ToolDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace MaIN.Domain.Entities.Tools;
using System.Text.Json.Serialization;

namespace MaIN.Domain.Entities.Tools;

public class ToolDefinition
{
public string Type { get; set; } = "function";
public FunctionDefinition? Function { get; set; }

[JsonIgnore]
public Func<string, Task<string>>? Execute { get; set; }
}
Loading
Loading