Skip to content

Commit d1b1316

Browse files
Fix for #552
1 parent 531f29f commit d1b1316

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/Custom/Assistants/MessageCreationAttachment.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,47 @@ public partial class MessageCreationAttachment
2626
public IReadOnlyList<ToolDefinition> Tools { get; }
2727

2828
private void SerializeTools(Utf8JsonWriter writer, ModelReaderWriterOptions options)
29-
=> writer.WriteObjectValue(Tools, options);
29+
{
30+
if (Tools is null)
31+
{
32+
writer.WriteNullValue();
33+
return;
34+
}
35+
36+
writer.WriteStartArray();
37+
foreach (ToolDefinition tool in Tools)
38+
{
39+
using var ms = new System.IO.MemoryStream();
40+
using (var tempWriter = new Utf8JsonWriter(ms))
41+
{
42+
tempWriter.WriteObjectValue(tool, options);
43+
tempWriter.Flush();
44+
}
45+
46+
using (JsonDocument doc = JsonDocument.Parse(ms.ToArray()))
47+
{
48+
JsonElement root = doc.RootElement;
49+
if (root.ValueKind == JsonValueKind.Object)
50+
{
51+
writer.WriteStartObject();
52+
foreach (var prop in root.EnumerateObject())
53+
{
54+
if (prop.NameEquals("file_search"u8))
55+
{
56+
continue;
57+
}
58+
prop.WriteTo(writer);
59+
}
60+
writer.WriteEndObject();
61+
}
62+
else
63+
{
64+
root.WriteTo(writer);
65+
}
66+
}
67+
}
68+
writer.WriteEndArray();
69+
}
3070

3171
private static void DeserializeTools(JsonProperty property, ref IReadOnlyList<ToolDefinition> tools)
3272
{

tests/Assistants/AssistantsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class AssistantsTests : SyncAsyncTestBase
3131
private readonly List<string> _vectorStoreIdsToDelete = [];
3232

3333
private static readonly DateTimeOffset s_2024 = new(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
34-
private static readonly string s_testAssistantName = $".NET SDK Test Assistant - Please Delete Me";
3534
private static readonly string s_cleanupMetadataKey = $"test_metadata_cleanup_eligible";
3635

3736
private static AssistantClient GetTestClient() => GetTestClient<AssistantClient>(TestScenario.Assistants);

0 commit comments

Comments
 (0)