-
Couldn't load subscription status.
- Fork 339
Custom Serializer for Message Creation - Resolves Issue 552 #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,3 @@ | ||
| using Microsoft.ClientModel.TestFramework; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Internal; | ||
| using OpenAI.Assistants; | ||
| using OpenAI.Files; | ||
| using OpenAI.Tests.Utility; | ||
| using OpenAI.VectorStores; | ||
| using System; | ||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
|
|
@@ -14,6 +7,19 @@ | |
| using System.Text.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.ClientModel.TestFramework; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Internal; | ||
| using NUnit.Framework.Internal; | ||
| using OpenAI.Assistants; | ||
| using OpenAI.Assistants; | ||
| using OpenAI.Files; | ||
| using OpenAI.Files; | ||
| using OpenAI.Tests.Utility; | ||
| using OpenAI.Tests.Utility; | ||
| using OpenAI.VectorStores; | ||
| using OpenAI.VectorStores; | ||
| using static OpenAI.Tests.TestHelpers; | ||
|
|
||
| namespace OpenAI.Tests.Assistants; | ||
|
|
@@ -30,7 +36,6 @@ | |
| private readonly List<string> _vectorStoreIdsToDelete = []; | ||
|
|
||
| private static readonly DateTimeOffset s_2024 = new(2024, 1, 1, 0, 0, 0, TimeSpan.Zero); | ||
| private static readonly string s_testAssistantName = $".NET SDK Test Assistant - Please Delete Me"; | ||
| private static readonly string s_cleanupMetadataKey = $"test_metadata_cleanup_eligible"; | ||
|
|
||
| private AssistantClient GetTestClient() => GetProxiedOpenAIClient<AssistantClient>(TestScenario.Assistants); | ||
|
|
@@ -847,6 +852,45 @@ | |
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task FileOnMessageWorks() | ||
| { | ||
| // First, we need to upload a simple test file. | ||
| OpenAIFileClient fileClient = GetTestClient<OpenAIFileClient>(TestScenario.Files); | ||
| OpenAIFile testFile = fileClient.UploadFile( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switch to the async version of this method: |
||
| BinaryData.FromString(""" | ||
| This file describes the favorite foods of several people. | ||
| Summanus Ferdinand: tacos | ||
| Tekakwitha Effie: pizza | ||
| Filip Carola: cake | ||
| """).ToStream(), | ||
| "favorite_foods.txt", | ||
| FileUploadPurpose.Assistants); | ||
| Validate(testFile); | ||
|
|
||
| AssistantClient client = GetTestClient(); | ||
|
|
||
| var thread = client.CreateThread(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var assistant = client.CreateAssistant("gpt-4o-mini"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| var message = await client.CreateMessageAsync( | ||
| thread.Value.Id, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Add indentation. |
||
| MessageRole.User, | ||
| new[] { | ||
| MessageContent.FromText("What is this file?"), | ||
| }, | ||
| new MessageCreationOptions() | ||
| { | ||
| Attachments = [ | ||
| new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateFileSearch() }), | ||
| new MessageCreationAttachment(testFile.Id, new List<ToolDefinition>() { ToolDefinition.CreateCodeInterpreter() }) | ||
| ] | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call |
||
|
|
||
| var result = client.CreateRunStreamingAsync(thread.Value.Id, assistant.Value.Id); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task FileSearchStreamingWorks() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fix the duplicated namespaces?