Skip to content

Commit f1e847d

Browse files
committed
fix: minor fixes related to tool-calling
1 parent 8600dcb commit f1e847d

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

Examples/Examples/Chat/ChatExampleToolsSimple.cs

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

15-
var model = AIHub.Model();
16-
1715
await AIHub.Chat()
1816
.WithModel("gpt-5-nano")
1917
.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
@@ -55,7 +55,9 @@ public LLMService(
5555
CancellationToken cancellationToken = default)
5656
{
5757
if (chat.Messages.Count == 0)
58+
{
5859
return null;
60+
}
5961

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

@@ -90,7 +92,9 @@ public Task<string[]> GetCurrentModels()
9092
public Task CleanSessionCache(string? id)
9193
{
9294
if (string.IsNullOrEmpty(id) || !_sessionCache.TryRemove(id, out var session))
95+
{
9396
return Task.CompletedTask;
97+
}
9498

9599
session.Executor.Context.Dispose();
96100
return Task.CompletedTask;
@@ -310,7 +314,9 @@ private static async Task ProcessImageMessage(Conversation conversation,
310314
conversation.Prompt(imageEmbeddings!);
311315

312316
while (executor.BatchedTokenCount > 0)
317+
{
313318
await executor.Infer(cancellationToken);
319+
}
314320

315321
var prompt = llmModel.Tokenize($"USER: {lastMsg.Content}\nASSISTANT:", true, false, Encoding.UTF8);
316322
conversation.Prompt(prompt);
@@ -364,7 +370,9 @@ private static string FormatToolsForPrompt(ToolsConfiguration toolsConfig)
364370
foreach (var tool in toolsConfig.Tools)
365371
{
366372
if (tool.Function == null)
373+
{
367374
continue;
375+
}
368376

369377
toolsList.AppendLine($"- {tool.Function.Name}: {tool.Function.Description}");
370378
toolsList.AppendLine($" Parameters: {JsonSerializer.Serialize(tool.Function.Parameters)}");
@@ -671,7 +679,7 @@ await requestOptions.ToolCallback.Invoke(new ToolInvocation
671679

672680
if (iterations >= MaxToolIterations)
673681
{
674-
var errorMessage = "Maximum tool invocation iterations reached. Ending the conversation.";
682+
var errorMessage = "Maximum tool invocation iterations reached. Ending the tool-loop prematurely.";
675683
var iterationMessage = new Message
676684
{
677685
Content = errorMessage,

0 commit comments

Comments
 (0)