Skip to content

Commit bb2beb4

Browse files
committed
fb
1 parent 5c0f11a commit bb2beb4

File tree

4 files changed

+430
-43
lines changed

4 files changed

+430
-43
lines changed

tests/Assistants/AssistantsTests.cs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@
99
using System.Threading.Tasks;
1010
using Microsoft.ClientModel.TestFramework;
1111
using NUnit.Framework;
12-
using NUnit.Framework;
13-
using NUnit.Framework.Internal;
1412
using NUnit.Framework.Internal;
1513
using OpenAI.Assistants;
16-
using OpenAI.Assistants;
1714
using OpenAI.Files;
18-
using OpenAI.Files;
19-
using OpenAI.Tests.Utility;
2015
using OpenAI.Tests.Utility;
2116
using OpenAI.VectorStores;
22-
using OpenAI.VectorStores;
2317
using static OpenAI.Tests.TestHelpers;
2418

2519
namespace OpenAI.Tests.Assistants;
@@ -89,7 +83,7 @@ protected void Cleanup()
8983
_vectorStoreIdsToDelete.Clear();
9084
}
9185

92-
[Test]
86+
[RecordedTest]
9387
public async Task BasicAssistantOperationsWork()
9488
{
9589
AssistantClient client = GetTestClient();
@@ -144,7 +138,7 @@ public async Task BasicAssistantOperationsWork()
144138
Assert.That(listedAssistant.Metadata.TryGetValue(s_cleanupMetadataKey, out string newMetadataValue) && newMetadataValue == "goodbye!");
145139
}
146140

147-
[Test]
141+
[RecordedTest]
148142
public async Task BasicThreadOperationsWork()
149143
{
150144
AssistantClient client = GetTestClient();
@@ -179,7 +173,7 @@ public async Task BasicThreadOperationsWork()
179173
Assert.That(thread.Metadata.TryGetValue("threadMetadata", out threadMetadataValue) && threadMetadataValue == "newThreadMetadataValue");
180174
}
181175

182-
[Test]
176+
[RecordedTest]
183177
public async Task BasicMessageOperationsWork()
184178
{
185179
AssistantClient client = GetTestClient();
@@ -227,7 +221,7 @@ public async Task BasicMessageOperationsWork()
227221
Assert.That(messages[0].Metadata.TryGetValue("messageMetadata", out metadataValue) && metadataValue == "newValue");
228222
}
229223

230-
[Test]
224+
[RecordedTest]
231225
public async Task ThreadWithInitialMessagesWorks()
232226
{
233227
AssistantClient client = GetTestClient();
@@ -265,7 +259,7 @@ public async Task ThreadWithInitialMessagesWorks()
265259
Assert.That(messages[1].Content[1].ImageUri.AbsoluteUri, Is.EqualTo("https://test.openai.com/image.png"));
266260
}
267261

268-
[Test]
262+
[RecordedTest]
269263
public async Task ThreadWithImageDetailWorks()
270264
{
271265
AssistantClient client = GetTestClient();
@@ -300,7 +294,7 @@ public async Task ThreadWithImageDetailWorks()
300294
Assert.That(messages[0].Content[1].ImageUri.AbsoluteUri, Is.EqualTo("https://test.openai.com/image.png"));
301295
}
302296

303-
[Test]
297+
[RecordedTest]
304298
public async Task BasicRunOperationsWork()
305299
{
306300
AssistantClient client = GetTestClient();
@@ -347,7 +341,7 @@ public async Task BasicRunOperationsWork()
347341
Assert.That(messages[1].Id, Is.EqualTo(message.Id));
348342
}
349343

350-
[Test]
344+
[RecordedTest]
351345
public async Task BasicRunStepFunctionalityWorks()
352346
{
353347
AssistantClient client = GetTestClient();
@@ -434,7 +428,7 @@ public async Task BasicRunStepFunctionalityWorks()
434428
});
435429
}
436430

437-
[Test]
431+
[RecordedTest]
438432
public async Task SettingResponseFormatWorks()
439433
{
440434
AssistantClient client = GetTestClient();
@@ -463,7 +457,7 @@ public async Task SettingResponseFormatWorks()
463457
Assert.That(run.ResponseFormat == AssistantResponseFormat.CreateJsonObjectFormat());
464458
}
465459

466-
[Test]
460+
[RecordedTest]
467461
public async Task FunctionToolsWork()
468462
{
469463
AssistantClient client = GetTestClient();
@@ -542,7 +536,7 @@ public async Task FunctionToolsWork()
542536
Assert.That(messages[0].Content[0].Text.ToLowerInvariant(), Does.Contain("tacos"));
543537
}
544538

545-
[Test]
539+
[RecordedTest]
546540
public async Task StreamingRunWorks()
547541
{
548542
AssistantClient client = GetTestClient();
@@ -651,7 +645,7 @@ public async Task StreamingToolCall()
651645
} while (run?.Status.IsTerminal == false);
652646
}
653647

654-
[Test]
648+
[RecordedTest]
655649
public async Task FileSearchWorks()
656650
{
657651
// First, we need to upload a simple test file.
@@ -852,12 +846,13 @@ This file describes the favorite foods of several people.
852846
});
853847
}
854848

855-
[Test]
849+
[RecordedTest]
850+
[LiveOnly]
856851
public async Task FileOnMessageWorks()
857852
{
858853
// First, we need to upload a simple test file.
859854
OpenAIFileClient fileClient = GetTestClient<OpenAIFileClient>(TestScenario.Files);
860-
OpenAIFile testFile = fileClient.UploadFile(
855+
OpenAIFile testFile = await fileClient.UploadFileAsync(
861856
BinaryData.FromString("""
862857
This file describes the favorite foods of several people.
863858
@@ -871,27 +866,32 @@ This file describes the favorite foods of several people.
871866

872867
AssistantClient client = GetTestClient();
873868

874-
var thread = client.CreateThread();
875-
var assistant = client.CreateAssistant("gpt-4o-mini");
876-
877-
var message = await client.CreateMessageAsync(
878-
thread.Value.Id,
879-
MessageRole.User,
880-
new[] {
881-
MessageContent.FromText("What is this file?"),
882-
},
883-
new MessageCreationOptions()
884-
{
885-
Attachments = [
886-
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }),
887-
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() })
888-
]
889-
});
869+
AssistantThread thread = await client.CreateThreadAsync();
870+
Validate(thread);
871+
872+
Assistant assistant = await client.CreateAssistantAsync("gpt-4o-mini");
873+
Validate(assistant);
874+
875+
ThreadMessage message = await client.CreateMessageAsync(
876+
thread.Id,
877+
MessageRole.User,
878+
new[] {
879+
MessageContent.FromText("What is this file?"),
880+
},
881+
new MessageCreationOptions()
882+
{
883+
Attachments = [
884+
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }),
885+
new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() })
886+
]
887+
}
888+
);
889+
Validate(message);
890890

891-
var result = client.CreateRunStreamingAsync(thread.Value.Id, assistant.Value.Id);
891+
var result = client.CreateRunStreamingAsync(thread.Id, assistant.Id);
892892
}
893893

894-
[Test]
894+
[RecordedTest]
895895
public async Task FileSearchStreamingWorks()
896896
{
897897
const string fileContent = """
@@ -986,7 +986,7 @@ public async Task FileSearchStreamingWorks()
986986
Assert.That(message, Does.Contain("cake"));
987987
}
988988

989-
[Test]
989+
[RecordedTest]
990990
public async Task Pagination_CanEnumerateAssistantsAsync()
991991
{
992992
const int TestAssistantCount = 10;
@@ -1029,7 +1029,7 @@ public async Task Pagination_CanEnumerateAssistantsAsync()
10291029
Assert.That(count, Is.GreaterThanOrEqualTo(TestAssistantCount));
10301030
}
10311031

1032-
[Test]
1032+
[RecordedTest]
10331033
public async Task Pagination_CanPageThroughAssistantCollection()
10341034
{
10351035
const int TestAssistantCount = 10;
@@ -1094,7 +1094,7 @@ private static IEnumerable<Assistant> GetAssistantsFromPage(ClientResult page)
10941094
return els.Select(el => ModelReaderWriter.Read<Assistant>(BinaryData.FromString(el.GetRawText())));
10951095
}
10961096

1097-
[Test]
1097+
[RecordedTest]
10981098
public async Task Pagination_CanRehydrateAssistantPageCollectionFromBytes()
10991099
{
11001100
const int TestAssistantCount = 10;
@@ -1166,7 +1166,7 @@ public async Task Pagination_CanRehydrateAssistantPageCollectionFromBytes()
11661166
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
11671167
}
11681168

1169-
[Test]
1169+
[RecordedTest]
11701170
public async Task Pagination_CanRehydrateAssistantPageCollectionFromPageToken()
11711171
{
11721172
const int TestAssistantCount = 10;
@@ -1248,7 +1248,7 @@ public async Task Pagination_CanRehydrateAssistantPageCollectionFromPageToken()
12481248
Assert.That(pageCount, Is.GreaterThanOrEqualTo(TestAssistantCount / TestPageSizeLimit));
12491249
}
12501250

1251-
[Test]
1251+
[RecordedTest]
12521252
public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytes()
12531253
{
12541254
AssistantClient client = GetTestClient();
@@ -1337,7 +1337,7 @@ public async Task Pagination_CanRehydrateRunStepPageCollectionFromBytes()
13371337
Assert.That(rehydratedRunSteps, Is.EqualTo(runSteps).AsCollection);
13381338
}
13391339

1340-
[Test]
1340+
[RecordedTest]
13411341
public async Task MessagesWithRoles()
13421342
{
13431343
AssistantClient client = GetTestClient();

0 commit comments

Comments
 (0)