Skip to content

Commit 7ab4e2b

Browse files
author
wisedev
committed
feat: fix thinking models tools calls
1 parent 4fb8ec7 commit 7ab4e2b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/MaIN.Domain/Entities/Tools/ToolCall.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Serialization;
23

34
namespace MaIN.Domain.Entities.Tools;
@@ -12,4 +13,8 @@ public sealed record ToolCall
1213

1314
[JsonPropertyName("function")]
1415
public FunctionCall Function { get; init; } = new();
16+
17+
[JsonPropertyName("extra_content")]
18+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
19+
public JsonElement? ExtraContent { get; init; }
1520
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ await _notificationService.DispatchNotification(
346346
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
347347

348348
var choice = chunk?.Choices?.FirstOrDefault();
349+
349350
if (choice?.Delta is not null)
350351
{
351352
// Handle content
@@ -390,6 +391,11 @@ await _notificationService.DispatchNotification(
390391
builder.Type = toolCallChunk.Type;
391392
}
392393

394+
if (toolCallChunk.ExtraContent.HasValue)
395+
{
396+
builder.ExtraContent = toolCallChunk.ExtraContent;
397+
}
398+
393399
if (toolCallChunk.Function is not null)
394400
{
395401
if (!string.IsNullOrEmpty(toolCallChunk.Function.Name))
@@ -1028,6 +1034,7 @@ internal class ToolCallBuilder
10281034
public string Type { get; set; } = "function";
10291035
public string FunctionName { get; set; } = string.Empty;
10301036
public StringBuilder FunctionArguments { get; set; } = new();
1037+
public JsonElement? ExtraContent { get; set; }
10311038

10321039
public ToolCall Build()
10331040
{
@@ -1039,7 +1046,8 @@ public ToolCall Build()
10391046
{
10401047
Name = FunctionName,
10411048
Arguments = FunctionArguments.ToString()
1042-
}
1049+
},
1050+
ExtraContent = ExtraContent
10431051
};
10441052
}
10451053
}
@@ -1090,6 +1098,9 @@ file class ToolCallChunk
10901098
public string? Id { get; set; }
10911099
public string? Type { get; set; }
10921100
public FunctionCallChunk? Function { get; set; }
1101+
1102+
[JsonPropertyName("extra_content")]
1103+
public JsonElement? ExtraContent { get; set; }
10931104
}
10941105

10951106
file class FunctionCallChunk

0 commit comments

Comments
 (0)