Skip to content

Commit 6d49789

Browse files
committed
fix: minor fixes related to tool-calling
1 parent 64ccee1 commit 6d49789

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Examples/Examples/Chat/ChatExampleToolsSimple.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ public class ChatExampleToolsSimple : IExample
1010
public async Task Start()
1111
{
1212
OpenAiExample.Setup(); //We need to provide OpenAi API key
13-
13+
1414
Console.WriteLine("(OpenAi) ChatExample with tools is running!");
1515

16-
var model = AIHub.Model();
17-
1816
await AIHub.Chat()
1917
.WithModel("gpt-5-nano")
2018
.WithMessage("What time is it right now?")

Examples/Examples/Chat/ChatExampleToolsSimpleLocalLLM.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public async Task Start()
1010
{
1111
Console.WriteLine("Local LLM ChatExample with tools is running!");
1212

13-
var model = AIHub.Model();
14-
1513
await AIHub.Chat()
1614
.WithModel("gemma3:4b")
1715
.WithMessage("What time is it right now?")

src/MaIN.Services/Services/LLMService/LLMService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public LLMService(
5454
CancellationToken cancellationToken = default)
5555
{
5656
if (chat.Messages.Count == 0)
57+
{
5758
return null;
59+
}
5860

5961
var lastMsg = chat.Messages.Last();
6062

@@ -89,7 +91,9 @@ public Task<string[]> GetCurrentModels()
8991
public Task CleanSessionCache(string? id)
9092
{
9193
if (string.IsNullOrEmpty(id) || !_sessionCache.TryRemove(id, out var session))
94+
{
9295
return Task.CompletedTask;
96+
}
9397

9498
session.Executor.Context.Dispose();
9599
return Task.CompletedTask;
@@ -309,7 +313,9 @@ private static async Task ProcessImageMessage(Conversation conversation,
309313
conversation.Prompt(imageEmbeddings!);
310314

311315
while (executor.BatchedTokenCount > 0)
316+
{
312317
await executor.Infer(cancellationToken);
318+
}
313319

314320
var prompt = llmModel.Tokenize($"USER: {lastMsg.Content}\nASSISTANT:", true, false, Encoding.UTF8);
315321
conversation.Prompt(prompt);
@@ -363,7 +369,9 @@ private static string FormatToolsForPrompt(ToolsConfiguration toolsConfig)
363369
foreach (var tool in toolsConfig.Tools)
364370
{
365371
if (tool.Function == null)
372+
{
366373
continue;
374+
}
367375

368376
toolsList.AppendLine($"- {tool.Function.Name}: {tool.Function.Description}");
369377
toolsList.AppendLine($" Parameters: {JsonSerializer.Serialize(tool.Function.Parameters)}");
@@ -673,7 +681,7 @@ await requestOptions.ToolCallback.Invoke(new ToolInvocation
673681

674682
if (iterations >= MaxToolIterations)
675683
{
676-
var errorMessage = "Maximum tool invocation iterations reached. Ending the conversation.";
684+
var errorMessage = "Maximum tool invocation iterations reached. Ending the tool-loop prematurely.";
677685
var iterationMessage = new Message
678686
{
679687
Content = errorMessage,

0 commit comments

Comments
 (0)