Skip to content

Commit 82a6c7f

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 82a6c7f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,38 @@ public async Task FileSearch(string deploymentName)
9090
}
9191
}
9292

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

0 commit comments

Comments
 (0)