Skip to content

Commit 531f29f

Browse files
Add test to confirm user behavior in Issue 552
1 parent 08a1193 commit 531f29f

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

tests/Assistants/AssistantsTests.cs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using NUnit.Framework;
2-
using NUnit.Framework.Internal;
3-
using OpenAI.Assistants;
4-
using OpenAI.Files;
5-
using OpenAI.Tests.Utility;
6-
using OpenAI.VectorStores;
7-
using System;
1+
using System;
82
using System.ClientModel;
93
using System.ClientModel.Primitives;
104
using System.Collections.Generic;
@@ -13,6 +7,12 @@
137
using System.Text.Json;
148
using System.Threading;
159
using System.Threading.Tasks;
10+
using NUnit.Framework;
11+
using NUnit.Framework.Internal;
12+
using OpenAI.Assistants;
13+
using OpenAI.Files;
14+
using OpenAI.Tests.Utility;
15+
using OpenAI.VectorStores;
1616
using static OpenAI.Tests.TestHelpers;
1717

1818
namespace OpenAI.Tests.Assistants;
@@ -1028,6 +1028,45 @@ This file describes the favorite foods of several people.
10281028
});
10291029
}
10301030

1031+
[Test]
1032+
public async Task FileOnMessageWorks()
1033+
{
1034+
// First, we need to upload a simple test file.
1035+
OpenAIFileClient fileClient = GetTestClient<OpenAIFileClient>(TestScenario.Files);
1036+
OpenAIFile testFile = fileClient.UploadFile(
1037+
BinaryData.FromString("""
1038+
This file describes the favorite foods of several people.
1039+
1040+
Summanus Ferdinand: tacos
1041+
Tekakwitha Effie: pizza
1042+
Filip Carola: cake
1043+
""").ToStream(),
1044+
"favorite_foods.txt",
1045+
FileUploadPurpose.Assistants);
1046+
Validate(testFile);
1047+
1048+
AssistantClient client = GetTestClient();
1049+
1050+
var thread = client.CreateThread();
1051+
var assistant = client.CreateAssistant("gpt-4o-mini");
1052+
1053+
var message = await client.CreateMessageAsync(
1054+
thread.Value.Id,
1055+
MessageRole.User,
1056+
new[] {
1057+
MessageContent.FromText("What is this file?"),
1058+
},
1059+
new MessageCreationOptions()
1060+
{
1061+
Attachments = [
1062+
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }),
1063+
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() })
1064+
]
1065+
});
1066+
1067+
var result = client.CreateRunStreamingAsync(thread.Value.Id, assistant.Value.Id);
1068+
}
1069+
10311070
[Test]
10321071
public void FileSearchStreamingWorksSync()
10331072
{

0 commit comments

Comments
 (0)