Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add disable sanitizers
  • Loading branch information
mssfang committed May 24, 2024
commit 6746713caf3054ebef09d82724d39f34dfd69754
17 changes: 17 additions & 0 deletions sdk/openai/azure-ai-openai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@

**Chat**

- [AOAI] Added new class `OnYourDataContextProperty` to represent the context property in the On Your Data deployment.
- [AOAI] Added new class `OnYourDataVectorSearchAuthenticationType`, `OnYourDataVectorSearchAuthenticationOptions`, `OnYourDataVectorSearchApiKeyAuthenticationOptions`, `OnYourDataVectorSearchAccessTokenAuthenticationOptions` for the vector search authentication options.
- [AOAI] Added new class `AzureChatExtensionRetrievedDocument` and `AzureChatExtensionRetrieveDocumentFilterReason` to represent the retrieved document and filter reason in the chat extension.
- [AOAI] Added a new property `all_retrieved_documents` in `AzureChatExtensionsMessageContext` class to represent all the retrieved documents in the chat extension.
- [AOAI] Added a new property `indirectAttack` in `ContentFilterResultDetailsForPrompt` class to represent the indirect attack results.
- [AOAI] Added new properties `max_search_queries`, `allow_partial_result`, and `include_contexts` in
`AzureCosmosDBChatExtensionParameters`, `AzureMachineLearningIndexChatExtensionParameters`,
`AzureSearchChatExtensionParameters`, `ElasticsearchChatExtensionParameters`, `PineconeChatExtensionParameters` class
to support additional search queries.

**Embeddings**

- [AOAI] Added a new property `dimensions` in `OnYourDataDeploymentNameVectorizationSource` class to represent the dimensions of the vectorization source.

**Image**

- [AOAI] Added a new property `custom_blocklists` in `ImageGenerationPromptFilterResults` class to represent the prompt filter results.

### Breaking Changes

- Replaced Jackson Databind annotations with `azure-json` functionality for OpenAI service models.
- [AOAI] Added a new class `ContentFilterDetailedResults` to represent detailed content filter results, which replaces the
`customBlocklists` response property type, `List<ContentFilterBlocklistIdResult>` in
`ContentFilterResultDetailsForPrompt` and `ContentFilterResultsForChoice` class.
- [AOAI] Replace the `OnYourDataAuthenticationOptions` by `OnYourDataVectorSearchAuthenticationOptions` in the `OnYourDataEndpointVectorizationSource` class.

### Bugs Fixed

Expand Down
2 changes: 1 addition & 1 deletion sdk/openai/azure-ai-openai/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/openai/azure-ai-openai",
"Tag": "java/openai/azure-ai-openai_4a8899256e"
"Tag": "java/openai/azure-ai-openai_959f9440df"
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersi
ChatChoice chatChoice = chatCompletions.getChoices().get(0);
MyFunctionCallArguments arguments = assertFunctionCall(
chatChoice,
"Sanitized",
MyFunctionCallArguments.class);
assertTrue(arguments.getLocation().contains("San Francisco"));
assertEquals(arguments.getUnit(), "CELSIUS");
Expand Down Expand Up @@ -756,7 +755,6 @@ public void testGetChatCompletionsToolCall(HttpClient httpClient, OpenAIServiceV

ChatCompletionsFunctionToolCall functionToolCall = (ChatCompletionsFunctionToolCall) responseMessage.getToolCalls().get(0);
assertNotNull(functionToolCall);
assertEquals(functionToolCall.getFunction().getName(), "Sanitized"); // see base class
assertFalse(functionToolCall.getFunction().getArguments() == null
|| functionToolCall.getFunction().getArguments().isEmpty());
return client.getChatCompletions(modelId, getChatCompletionsOptionWithToolCallFollowUp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersi
ChatChoice chatChoice = chatCompletions.getChoices().get(0);
MyFunctionCallArguments arguments = assertFunctionCall(
chatChoice,
"Sanitized",
MyFunctionCallArguments.class);
assertTrue(arguments.getLocation().contains("San Francisco"));
assertEquals(arguments.getUnit(), "CELSIUS");
Expand Down Expand Up @@ -681,7 +680,6 @@ public void testGetChatCompletionsToolCall(HttpClient httpClient, OpenAIServiceV

ChatCompletionsFunctionToolCall functionToolCall = (ChatCompletionsFunctionToolCall) responseMessage.getToolCalls().get(0);
assertNotNull(functionToolCall);
assertEquals(functionToolCall.getFunction().getName(), "Sanitized");
assertFalse(functionToolCall.getFunction().getArguments() == null
|| functionToolCall.getFunction().getArguments().isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.ai.openai.models.AudioTranscriptionFormat;
import com.azure.ai.openai.models.AudioTranscriptionTimestampGranularity;
import com.azure.ai.openai.models.AudioTranslationFormat;
import com.azure.ai.openai.models.AzureChatExtensionsMessageContext;
import com.azure.ai.openai.models.AzureSearchChatExtensionConfiguration;
import com.azure.ai.openai.models.AzureSearchChatExtensionParameters;
import com.azure.ai.openai.models.ChatChoice;
Expand All @@ -25,6 +26,7 @@
import com.azure.ai.openai.models.FunctionCall;
import com.azure.ai.openai.models.FunctionCallConfig;
import com.azure.ai.openai.models.OnYourDataApiKeyAuthenticationOptions;
import com.azure.ai.openai.models.OnYourDataContextProperty;
import com.azure.ai.openai.models.SpeechGenerationResponseFormat;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceNotFoundException;
Expand Down Expand Up @@ -308,7 +310,6 @@ public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersi
ChatChoice chatChoice = chatCompletions.getChoices().get(0);
MyFunctionCallArguments arguments = assertFunctionCall(
chatChoice,
"Sanitized",
MyFunctionCallArguments.class);
assertTrue(arguments.getLocation().contains("San Francisco"));
assertEquals(arguments.getUnit(), "CELSIUS");
Expand Down Expand Up @@ -494,6 +495,41 @@ public void testChatCompletionsBasicSearchExtension(HttpClient httpClient, OpenA
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testChatCompletionSearchExtensionContextPropertyFilter(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
client = getOpenAIAsyncClient(httpClient, serviceVersion);

getChatCompletionsAzureChatSearchRunner((deploymentName, chatCompletionsOptions) -> {
AzureSearchChatExtensionParameters searchParameters = new AzureSearchChatExtensionParameters(
"https://openaisdktestsearch.search.windows.net",
"openai-test-index-carbon-wiki"
);

// Only have citations in the search results, default are 'citations' and 'intent'.
List<OnYourDataContextProperty> contextProperties = new ArrayList<>();
contextProperties.add(OnYourDataContextProperty.CITATIONS);

searchParameters.setAuthentication(new OnYourDataApiKeyAuthenticationOptions(getAzureCognitiveSearchKey()))
.setIncludeContexts(contextProperties);

AzureSearchChatExtensionConfiguration cognitiveSearchConfiguration =
new AzureSearchChatExtensionConfiguration(searchParameters);

chatCompletionsOptions.setDataSources(Arrays.asList(cognitiveSearchConfiguration));

StepVerifier.create(client.getChatCompletions(deploymentName, chatCompletionsOptions))
.assertNext(chatCompletions -> {
AzureChatExtensionsMessageContext context = chatCompletions.getChoices().get(0)
.getMessage().getContext();
assertNotNull(context);
assertNull(context.getIntent());
assertFalse(CoreUtils.isNullOrEmpty(context.getCitations()));
})
.verifyComplete();
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testChatCompletionsStreamingBasicSearchExtension(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
Expand Down Expand Up @@ -893,7 +929,6 @@ public void testGetChatCompletionsToolCall(HttpClient httpClient, OpenAIServiceV

ChatCompletionsFunctionToolCall functionToolCall = (ChatCompletionsFunctionToolCall) responseMessage.getToolCalls().get(0);
assertNotNull(functionToolCall);
assertEquals(functionToolCall.getFunction().getName(), "Sanitized"); // see base class
assertFalse(functionToolCall.getFunction().getArguments() == null
|| functionToolCall.getFunction().getArguments().isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.azure.ai.openai.models.AudioTranslation;
import com.azure.ai.openai.models.AudioTranslationOptions;
import com.azure.ai.openai.models.AzureChatExtensionDataSourceResponseCitation;
import com.azure.ai.openai.models.AzureChatExtensionRetrievedDocument;
import com.azure.ai.openai.models.AzureChatExtensionsMessageContext;
import com.azure.ai.openai.models.ChatChoice;
import com.azure.ai.openai.models.ChatCompletions;
Expand Down Expand Up @@ -96,17 +97,25 @@ OpenAIClientBuilder getOpenAIClientBuilder(HttpClient httpClient, OpenAIServiceV
OpenAIClientBuilder builder = new OpenAIClientBuilder()
.httpClient(httpClient)
.serviceVersion(serviceVersion);

if (getTestMode() != TestMode.LIVE) {
TestMode testMode = getTestMode();
if (testMode != TestMode.LIVE) {
addTestRecordCustomSanitizers();
addCustomMatchers();
}

if (getTestMode() == TestMode.PLAYBACK) {
// TODO: Remove this block once the azure-core-test has fixed the issue.
// AZSDK3430 is already in the default remove list:
// https://github.com/Azure/azure-sdk-for-java/blob/f0d4e21415eb49400a989d09bc5e5af97f0cc438/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java#L50
if (getTestMode() == TestMode.RECORD) {
// Disable "$..id"=AZSDK3430 sanitizers for both azure and non-azure clients.
interceptorManager.removeSanitizers(Arrays.asList("AZSDK3430"));
}

if (testMode == TestMode.PLAYBACK) {
builder
.endpoint("https://localhost:8080")
.credential(new AzureKeyCredential(FAKE_API_KEY));
} else if (getTestMode() == TestMode.RECORD) {
} else if (testMode == TestMode.RECORD) {
builder
.addPolicy(interceptorManager.getRecordPolicy())
.endpoint(Configuration.getGlobalConfiguration().get("AZURE_OPENAI_ENDPOINT"))
Expand All @@ -126,8 +135,16 @@ OpenAIClientBuilder getNonAzureOpenAIClientBuilder(HttpClient httpClient) {
if (getTestMode() != TestMode.LIVE) {
addTestRecordCustomSanitizers();
addCustomMatchers();
// Disable `AZSDK2015` and `AZSDK3430` sanitizers for non-Azure tests
interceptorManager.removeSanitizers(Arrays.asList("AZSDK2015", "AZSDK3430"));
// Disable "Set-Cookie"=AZSDK2015 for non-azure client only.
interceptorManager.removeSanitizers(Arrays.asList("AZSDK2015"));
}

// TODO: Remove this block once the azure-core-test has fixed the issue.
// AZSDK3430 is already in the default remove list:
// https://github.com/Azure/azure-sdk-for-java/blob/f0d4e21415eb49400a989d09bc5e5af97f0cc438/sdk/core/azure-core-test/src/main/java/com/azure/core/test/utils/TestProxyUtils.java#L50
if (getTestMode() == TestMode.RECORD) {
// Disable "$..id"=AZSDK3430 sanitizers for both azure and non-azure clients.
interceptorManager.removeSanitizers(Arrays.asList("AZSDK3430"));
}

if (getTestMode() == TestMode.PLAYBACK) {
Expand Down Expand Up @@ -580,11 +597,10 @@ static void assertImageGenerationsForAzure(ImageGenerations actual) {
assertNotNull(imageGenerationData.getPromptFilterResults());
}

static <T> T assertFunctionCall(ChatChoice actual, String functionName, Class<T> myPropertiesClazz) {
static <T> T assertFunctionCall(ChatChoice actual, Class<T> myPropertiesClazz) {
assertEquals(0, actual.getIndex());
assertEquals("function_call", actual.getFinishReason().toString());
FunctionCall functionCall = actual.getMessage().getFunctionCall();
assertEquals(functionName, functionCall.getName());
BinaryData argumentJson = BinaryData.fromString(functionCall.getArguments());
return argumentJson.toObject(myPropertiesClazz);
}
Expand Down Expand Up @@ -643,6 +659,15 @@ static void assertChatCompletionsCognitiveSearch(ChatCompletions chatCompletions
assertNotNull(messageContext.getIntent());
AzureChatExtensionDataSourceResponseCitation firstResponseCitation = messageContext.getCitations().get(0);
assertNotNull(firstResponseCitation.getContent());
List<AzureChatExtensionRetrievedDocument> allRetrievedDocuments = messageContext.getAllRetrievedDocuments();

if (!CoreUtils.isNullOrEmpty(allRetrievedDocuments)) {
for (AzureChatExtensionRetrievedDocument retrievedDocument : allRetrievedDocuments) {
assertNotNull(retrievedDocument.getContent());
assertFalse(CoreUtils.isNullOrEmpty(retrievedDocument.getSearchQueries()));
assertNotNull(retrievedDocument.getFilterReason());
}
}
}

// Some of the quirks of stream ChatCompletions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.ai.openai.models.AudioTranscriptionTimestampGranularity;
import com.azure.ai.openai.models.AudioTranslation;
import com.azure.ai.openai.models.AudioTranslationFormat;
import com.azure.ai.openai.models.AzureChatExtensionsMessageContext;
import com.azure.ai.openai.models.AzureSearchChatExtensionConfiguration;
import com.azure.ai.openai.models.AzureSearchChatExtensionParameters;
import com.azure.ai.openai.models.ChatChoice;
Expand All @@ -26,6 +27,7 @@
import com.azure.ai.openai.models.FunctionCall;
import com.azure.ai.openai.models.FunctionCallConfig;
import com.azure.ai.openai.models.OnYourDataApiKeyAuthenticationOptions;
import com.azure.ai.openai.models.OnYourDataContextProperty;
import com.azure.ai.openai.models.SpeechGenerationResponseFormat;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceNotFoundException;
Expand All @@ -39,6 +41,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -260,7 +263,6 @@ public void testChatFunctionAutoPreset(HttpClient httpClient, OpenAIServiceVersi
ChatChoice chatChoice = chatCompletions.getChoices().get(0);
MyFunctionCallArguments arguments = assertFunctionCall(
chatChoice,
"Sanitized",
MyFunctionCallArguments.class);
assertTrue(arguments.getLocation().contains("San Francisco"));
assertEquals(arguments.getUnit(), "CELSIUS");
Expand Down Expand Up @@ -423,6 +425,36 @@ public void testChatCompletionsBasicSearchExtension(HttpClient httpClient, OpenA
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testChatCompletionSearchExtensionContextPropertyFilter(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
client = getOpenAIClient(httpClient, serviceVersion);

getChatCompletionsAzureChatSearchRunner((deploymentName, chatCompletionsOptions) -> {
AzureSearchChatExtensionParameters searchParameters = new AzureSearchChatExtensionParameters(
"https://openaisdktestsearch.search.windows.net",
"openai-test-index-carbon-wiki"
);

// Only have citations in the search results, default are 'citations' and 'intent'.
List<OnYourDataContextProperty> contextProperties = new ArrayList<>();
contextProperties.add(OnYourDataContextProperty.CITATIONS);

searchParameters.setAuthentication(new OnYourDataApiKeyAuthenticationOptions(getAzureCognitiveSearchKey()))
.setIncludeContexts(contextProperties);
AzureSearchChatExtensionConfiguration cognitiveSearchConfiguration =
new AzureSearchChatExtensionConfiguration(searchParameters);

chatCompletionsOptions.setDataSources(Arrays.asList(cognitiveSearchConfiguration));
ChatCompletions chatCompletions = client.getChatCompletions(deploymentName, chatCompletionsOptions);

AzureChatExtensionsMessageContext context = chatCompletions.getChoices().get(0).getMessage().getContext();
assertNotNull(context);
assertNull(context.getIntent());
assertFalse(CoreUtils.isNullOrEmpty(context.getCitations()));
});
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.TestUtils#getTestParameters")
public void testChatCompletionsStreamingBasicSearchExtension(HttpClient httpClient, OpenAIServiceVersion serviceVersion) {
Expand Down Expand Up @@ -800,7 +832,6 @@ public void testGetChatCompletionsToolCall(HttpClient httpClient, OpenAIServiceV

ChatCompletionsFunctionToolCall functionToolCall = (ChatCompletionsFunctionToolCall) responseMessage.getToolCalls().get(0);
assertNotNull(functionToolCall);
assertEquals(functionToolCall.getFunction().getName(), "Sanitized"); // see base class
assertFalse(functionToolCall.getFunction().getArguments() == null
|| functionToolCall.getFunction().getArguments().isEmpty());

Expand Down