Skip to content

Commit 08f75d2

Browse files
committed
feat: Implement tool calling to local LLMs
1 parent 39a2fe8 commit 08f75d2

4 files changed

Lines changed: 360 additions & 7 deletions

File tree

Examples/Examples/Chat/ChatExampleToolsSimple.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public async Task Start()
1111
{
1212
OpenAiExample.Setup(); //We need to provide OpenAi API key
1313

14-
Console.WriteLine("(OpenAi) ChatExample with tools is running!");
14+
Console.WriteLine("(OpenAi) ChatExample with tools is running!");
15+
16+
var model = AIHub.Model();
1517

1618
await AIHub.Chat()
1719
.WithModel("gpt-5-nano")
18-
.WithMessage("What time is it right now?")
20+
.WithMessage("What time is it right now? Use tool provided.")
1921
.WithTools(new ToolsConfigurationBuilder()
2022
.AddTool(
2123
name: "get_current_time",
@@ -25,4 +27,4 @@ await AIHub.Chat()
2527
.Build())
2628
.CompleteAsync(interactive: true);
2729
}
28-
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
using MaIN.Core.Hub.Utils;
4+
5+
namespace Examples.Chat;
6+
7+
public class ChatExampleToolsSimpleLocalLLM : IExample
8+
{
9+
public async Task Start()
10+
{
11+
Console.WriteLine("Local LLM ChatExample with tools is running!");
12+
13+
var model = AIHub.Model();
14+
15+
await AIHub.Chat()
16+
.WithModel("gemma3:4b")
17+
.WithMessage("What time is it right now? Use tool provided.")
18+
.WithTools(new ToolsConfigurationBuilder()
19+
.AddTool(
20+
name: "get_current_time",
21+
description: "Get the current date and time",
22+
execute: Tools.GetCurrentTime)
23+
.WithToolChoice("auto")
24+
.Build())
25+
.CompleteAsync(interactive: true);
26+
}
27+
}

Examples/Examples/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static void RegisterExamples(IServiceCollection services)
5252
services.AddTransient<ChatFromExistingExample>();
5353
services.AddTransient<ChatWithReasoningExample>();
5454
services.AddTransient<ChatExampleToolsSimple>();
55+
services.AddTransient<ChatExampleToolsSimpleLocalLLM>();
5556
services.AddTransient<AgentExampleTools>();
5657
services.AddTransient<AgentExample>();
5758
services.AddTransient<AgentConversationExample>();
@@ -146,6 +147,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
146147
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
147148
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
148149
("\u25a0 Chat with Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
150+
("\u25a0 Chat with Tools (simple) Local LLM", serviceProvider.GetRequiredService<ChatExampleToolsSimpleLocalLLM>()),
149151
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
150152
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
151153
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),

0 commit comments

Comments
 (0)