diff --git a/src/Custom/Assistants/MessageContent.cs b/src/Custom/Assistants/MessageContent.cs index d020a5c30..dab575342 100644 --- a/src/Custom/Assistants/MessageContent.cs +++ b/src/Custom/Assistants/MessageContent.cs @@ -19,7 +19,7 @@ public static MessageContent FromImageFileId( => new InternalMessageContentImageFileObject( imageFile: new( fileId: imageFileId, - detail: detail?.ToString(), + detail: detail?.ToSerialString(), additionalBinaryDataProperties: null)); /// @@ -33,7 +33,7 @@ public static MessageContent FromImageUri(Uri imageUri, MessageImageDetail? deta => new InternalMessageContentImageUrlObject( imageUrl: new( url: imageUri, - detail: detail?.ToString(), + detail: detail?.ToSerialString(), additionalBinaryDataProperties: null)); /// diff --git a/tests/Assistants/AssistantsTests.cs b/tests/Assistants/AssistantsTests.cs index 969055fb9..02cccae22 100644 --- a/tests/Assistants/AssistantsTests.cs +++ b/tests/Assistants/AssistantsTests.cs @@ -301,6 +301,45 @@ public async Task ThreadWithInitialMessagesWorks() Assert.That(messages[1].Content[1].ImageUri.AbsoluteUri, Is.EqualTo("https://test.openai.com/image.png")); } + [Test] + public async Task ThreadWithImageDetailWorks() + { + AssistantClient client = GetTestClient(); + + ThreadCreationOptions options = new() + { + InitialMessages = + { + new( + MessageRole.User, + [ + "Describe this image with auto detail:", + MessageContent.FromImageUri( + new Uri("https://test.openai.com/image.png"), + MessageImageDetail.Auto) + ]) + } + }; + + AssistantThread thread = IsAsync + ? await client.CreateThreadAsync(options) + : client.CreateThread(options); + + Validate(thread); + + MessageCollectionOptions collectionOptions = new() { Order = MessageCollectionOrder.Ascending }; + List messages = IsAsync + ? await client.GetMessagesAsync(thread.Id, collectionOptions).ToListAsync() + : client.GetMessages(thread.Id, collectionOptions).ToList(); + + Assert.That(messages.Count, Is.EqualTo(1)); + Assert.That(messages[0].Role, Is.EqualTo(MessageRole.User)); + Assert.That(messages[0].Content?.Count, Is.EqualTo(2)); + + Assert.That(messages[0].Content[0].Text, Is.EqualTo("Describe this image with auto detail:")); + Assert.That(messages[0].Content[1].ImageUri.AbsoluteUri, Is.EqualTo("https://test.openai.com/image.png")); + } + [Test] public async Task BasicRunOperationsWork() {