|
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; |
8 | 2 | using System.ClientModel; |
9 | 3 | using System.ClientModel.Primitives; |
10 | 4 | using System.Collections.Generic; |
|
13 | 7 | using System.Text.Json; |
14 | 8 | using System.Threading; |
15 | 9 | 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; |
16 | 16 | using static OpenAI.Tests.TestHelpers; |
17 | 17 |
|
18 | 18 | namespace OpenAI.Tests.Assistants; |
@@ -1028,6 +1028,45 @@ This file describes the favorite foods of several people. |
1028 | 1028 | }); |
1029 | 1029 | } |
1030 | 1030 |
|
| 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 | + |
1031 | 1070 | [Test] |
1032 | 1071 | public void FileSearchStreamingWorksSync() |
1033 | 1072 | { |
|
0 commit comments