Skip to content

Commit 1069fb0

Browse files
committed
Add ResponseImageInput test for OpenAI image handling
Introduces a new test method `ResponseImageInput` in `ResponsesTests.cs`. This method verifies the functionality of sending an image and text prompt to the OpenAI API. It checks the response for output items and logs the input items asynchronously, enhancing the test coverage for image input handling.
1 parent 19bf474 commit 1069fb0

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

sdk/openai/Azure.AI.OpenAI/tests/ResponsesTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ public async Task FileSearch(string deploymentName)
9090
}
9191
}
9292

93+
[TestCase(Gpt4oMiniDeployment)]
94+
public async Task ResponseImageInput(string deploymentName)
95+
{
96+
OpenAIClient topLevelClient = GetTestTopLevelClient(DefaultResponsesConfig);
97+
OpenAIFileClient fileClient = topLevelClient.GetOpenAIFileClient();
98+
VectorStoreClient vectorStoreClient = topLevelClient.GetVectorStoreClient();
99+
OpenAIResponseClient client = topLevelClient.GetOpenAIResponseClient(deploymentName);
100+
101+
Uri imageUri = new("https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/Microsoft_logo.svg/512px-Microsoft_logo.svg.png");
102+
ResponseContentPart imagePart = ResponseContentPart.CreateInputImagePart(imageUri);
103+
ResponseContentPart textPart = ResponseContentPart.CreateInputTextPart("Describe this image");
104+
105+
List<ResponseContentPart> contentParts = [imagePart, textPart];
106+
107+
OpenAIResponse response = client.CreateResponse(
108+
inputItems:
109+
[
110+
ResponseItem.CreateSystemMessageItem("You are a helpful assistant that describes images"),
111+
ResponseItem.CreateUserMessageItem(contentParts)
112+
]);
113+
114+
Assert.That(response.OutputItems?.Count, Is.EqualTo(1));
115+
MessageResponseItem? message = response?.OutputItems?[0] as MessageResponseItem;
116+
Assert.That(message, Is.Not.Null);
117+
118+
await foreach (ResponseItem inputItem in client.GetResponseInputItemsAsync(response?.Id))
119+
{
120+
Console.WriteLine(ModelReaderWriter.Write(inputItem).ToString());
121+
}
122+
}
123+
93124
[RecordedTest]
94125
public async Task ComputerToolWithScreenshotRoundTrip()
95126
{
@@ -954,7 +985,6 @@ private static void AssertSerializationRoundTrip<T>(
954985
"""),
955986
false);
956987

957-
[RecordedTest]
958988
[TestCase(Gpt4oMiniDeployment)]
959989
public void ChatbotTellsJokes(string deploymentName)
960990
{

0 commit comments

Comments
 (0)