Skip to content

Commit f5d58dd

Browse files
committed
feat: Implement tool calling to local LLMs
1 parent 6399106 commit f5d58dd

4 files changed

Lines changed: 360 additions & 8 deletions

File tree

Examples/Examples/Chat/ChatExampleToolsSimple.cs

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

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

1517
await AIHub.Chat()
1618
.WithModel("gpt-5-nano")
17-
.WithMessage("What time is it right now?")
19+
.WithMessage("What time is it right now? Use tool provided.")
1820
.WithTools(new ToolsConfigurationBuilder()
1921
.AddTool(
2022
name: "get_current_time",
@@ -24,4 +26,4 @@ await AIHub.Chat()
2426
.Build())
2527
.CompleteAsync(interactive: true);
2628
}
27-
}
29+
}
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static void RegisterExamples(IServiceCollection services)
5151
services.AddTransient<ChatFromExistingExample>();
5252
services.AddTransient<ChatWithReasoningExample>();
5353
services.AddTransient<ChatExampleToolsSimple>();
54+
services.AddTransient<ChatExampleToolsSimpleLocalLLM>();
5455
services.AddTransient<AgentExampleTools>();
5556
services.AddTransient<AgentExample>();
5657
services.AddTransient<AgentConversationExample>();
@@ -161,6 +162,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
161162
("\u25a0 Chat with Files from stream", serviceProvider.GetRequiredService<ChatWithFilesFromStreamExample>()),
162163
("\u25a0 Chat with Vision", serviceProvider.GetRequiredService<ChatWithVisionExample>()),
163164
("\u25a0 Chat with Tools (simple)", serviceProvider.GetRequiredService<ChatExampleToolsSimple>()),
165+
("\u25a0 Chat with Tools (simple Local LLM)", serviceProvider.GetRequiredService<ChatExampleToolsSimpleLocalLLM>()),
164166
("\u25a0 Chat with Image Generation", serviceProvider.GetRequiredService<ChatWithImageGenExample>()),
165167
("\u25a0 Chat from Existing", serviceProvider.GetRequiredService<ChatFromExistingExample>()),
166168
("\u25a0 Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningExample>()),
@@ -197,4 +199,4 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
197199
];
198200
}
199201
};
200-
}
202+
}

0 commit comments

Comments
 (0)