Skip to content

Tests for MultipartFormDataHelper and OpenAISyncClientTest #44811

Closed
gregocmsft wants to merge 1 commit intoAzure:mainfrom
markmunozmsft:gc_jacococoverageenhancement
Closed

Tests for MultipartFormDataHelper and OpenAISyncClientTest #44811
gregocmsft wants to merge 1 commit intoAzure:mainfrom
markmunozmsft:gc_jacococoverageenhancement

Conversation

@gregocmsft
Copy link
Contributor

+Tests for MultipartFormDataHelper
+Tests for OpenAISyncClientTest - ChatCompletionsStreamOptions

+Tests for OpenAISyncClientTest - ChatCompletionsStreamOptions
@github-actions github-actions bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. OpenAI labels Mar 27, 2025
@github-actions
Copy link
Contributor

Thank you for your contribution @gregocmsft! We will review the pull request and get back to you soon.

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

Copy link
Member

@jpalvarezl jpalvarezl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thank you. I think you just need to add the analogous tests I mentioned in the PR comment and you are good to go!

Comment on lines +1735 to +1783
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testGetCompletionsStreamChatCompletionStreamOptions(HttpClient httpClient,
OpenAIServiceVersion serviceVersion) {
client = getOpenAIClient(httpClient, serviceVersion);
getCompletionsRunner((deploymentId, prompt) -> {
IterableStream<Completions> resultCompletions = client.getCompletionsStream(deploymentId,
new CompletionsOptions(prompt), new ChatCompletionStreamOptions().setIncludeUsage(true));

Object[] result = resultCompletions.stream().toArray();
Completions[] completionsArray = Arrays.copyOf(result, result.length, Completions[].class);

assertTrue(completionsArray.length > 1);
// First element returns the prompt filter results (no output tokens are present)
assertFalse(CoreUtils.isNullOrEmpty(completionsArray[0].getPromptFilterResults()));
// Choices (output tokens) are present in all the elements in between
for (int i = 1; i < completionsArray.length - 2; i++) {
assertCompletionsStream(completionsArray[i]);
}

// Last element returns the completion tokens (no output tokens are present)
assertNotNull(completionsArray[completionsArray.length - 1].getUsage());
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testGetChatCompletionsStreamChatCompletionStreamOptionsUsageTrue(HttpClient httpClient,
OpenAIServiceVersion serviceVersion) {
client = getOpenAIClient(httpClient, serviceVersion);
getChatCompletionsStreamUsageRunner((deploymentId, chatCompletionsOptions) -> {
IterableStream<ChatCompletions> resultChatCompletions = client.getChatCompletionsStream(deploymentId,
chatCompletionsOptions, new ChatCompletionStreamOptions().setIncludeUsage(true));
assertChatCompletionStreamUsage(resultChatCompletions.stream().collect(Collectors.toList()));
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testGetChatCompletionsStreamChatCompletionStreamOptionsUsageFalse(HttpClient httpClient,
OpenAIServiceVersion serviceVersion) {
client = getOpenAIClient(httpClient, serviceVersion);
getChatCompletionsRunner((deploymentId, chatMessages) -> {
IterableStream<ChatCompletions> resultChatCompletions = client.getChatCompletionsStream(deploymentId,
new ChatCompletionsOptions(chatMessages), new ChatCompletionStreamOptions().setIncludeUsage(false));
assertTrue(resultChatCompletions.stream().toArray().length > 1);
resultChatCompletions.forEach(OpenAIClientTestBase::assertChatCompletionsStream);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! I think that all these tests are good. The only thing left to do would be to write the version for the NonAzureOpenAISyncClientTest (which is just copy and pasting this, adjusting the client initialization. After that, adding the async version for both Azure and Non-Azure and you are good to go!

Copy link
Contributor Author

@gregocmsft gregocmsft Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I'm not sure how to generate the versions since I have not used any client initialization for these unit tests. I only worked with the tools of MultipartFormDataHelper but the tests do not interact with the API so no client initialization was needed.

Edit: I see what you're saying but I'm not sure why these tests in particular are here since I did not develop them. I will verify with the team what could happen.

@jpalvarezl
Copy link
Member

The CI failures I see are mostly related to the test recording being missing. Once you've added the other tests, give me a heads up and I will add the recording to this PR so we can move it forward. I think you might also have style check issues, although if you are able to run mvn clean install locally, then you are good.

@gregocmsft gregocmsft closed this May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. OpenAI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants