Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions sdk/openai/azure-ai-openai-assistants/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,28 @@

### Features Added

- `file_search` tool definitions now have the ability to configure `max_num_results` via the matching, named inner options object
Previously, only a stubbed `{ "type": "file_search" }` was valid. Now, e.g.: `{ "type": "file_search", "file_search": { "max_num_results": 20 } }`
- Added a new property `FileSearchToolDefinitionDetails fileSearch` to `FileSearchToolDefinition` model.
- Added new class `FileSearchToolDefinitionDetails` to represent the details of a file search tool.

- `chunking_strategy` is added as a new optional property when creating a vector store (either via the vector store creation operation
or the helper when creating an assistant) -- this allows customization of the chunk size and overlap used when ingesting data.
See the OpenAI reference for full details.
- Added a new property `VectorStoreChunkingStrategyRequest chunkingStrategy` to `VectorStoreOptions` model.
- Added a new property `VectorStoreChunkingStrategyResponse chunkingStrategy` to `VectorStoreFile` model.
- Added new enum `VectorStoreChunkingStrategyRequestType` and `VectorStoreChunkingStrategyResponseType` to represent the chunking strategy `type` for vector stores.
- Added new class `VectorStoreChunkingStrategyRequest` and `VectorStoreChunkingStrategyResponse` to represent the chunking strategy for vector stores.
- Added new class `VectorStoreAutoChunkingStrategyRequest` and `VectorStoreAutoChunkingStrategyResponse` to represent the `auto` chunking strategy for vector stores.
- Added new class `VectorStoreStaticChunkingStrategyOptions`, `VectorStoreStaticChunkingStrategyRequest` and `VectorStoreStaticChunkingStrategyResponse`
to represent the `static` chunking strategy for vector stores.

### Breaking Changes

- Replaced constructor `CreateFileSearchToolResourceVectorStoreOptions(List<String> fileIds)` by
`CreateFileSearchToolResourceVectorStoreOptions(List<String> fileIds, VectorStoreChunkingStrategyRequest chunkingStrategy)`
in `CreateFileSearchToolResourceVectorStoreOptions` model, to take one more parameter `chunkingStrategy`.

### Bugs Fixed

### Other Changes
Expand Down
5 changes: 4 additions & 1 deletion sdk/openai/azure-ai-openai-assistants/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ CreateToolResourcesOptions createToolResourcesOptions = new CreateToolResourcesO
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
)))));

Assistant assistant = client.createAssistant(
new AssistantCreationOptions(deploymentOrModelId)
Expand Down
4 changes: 2 additions & 2 deletions sdk/openai/azure-ai-openai-assistants/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/assistants/azure-ai-openai-assistants",
"Tag" : "java/assistants/azure-ai-openai-assistants_868e5c86d0"
}
"Tag" : "java/assistants/azure-ai-openai-assistants_ba2f3816c8"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public static void main(String[] args) throws InterruptedException {
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
)))));

// Create assistant passing the file ID
Assistant assistant = client.createAssistant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public void simpleRetrievalOperation() throws InterruptedException {
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
)))));

Assistant assistant = client.createAssistant(
new AssistantCreationOptions(deploymentOrModelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.azure.ai.openai.assistants.models.FileDeletionStatus;
import com.azure.ai.openai.assistants.models.FileDetails;
import com.azure.ai.openai.assistants.models.FilePurpose;
import com.azure.ai.openai.assistants.models.FileSearchToolDefinition;
import com.azure.ai.openai.assistants.models.FunctionDefinition;
import com.azure.ai.openai.assistants.models.FunctionToolDefinition;
import com.azure.ai.openai.assistants.models.MessageRole;
Expand Down Expand Up @@ -214,18 +213,6 @@ void createRunRunner(Consumer<CreateRunOptions> testRunner, String assistantId)
testRunner.accept(new CreateRunOptions(assistantId));
}

void createRetrievalRunner(BiConsumer<FileDetails, AssistantCreationOptions> testRunner) {
FileDetails fileDetails = new FileDetails(
BinaryData.fromFile(openResourceFile("java_sdk_tests_assistants.txt")), "java_sdk_tests_assistants.txt");

AssistantCreationOptions assistantOptions = new AssistantCreationOptions(GPT_4_1106_PREVIEW)
.setName("Java SDK Retrieval Sample")
.setInstructions("You are a helpful assistant that can help fetch data from files you know about.")
.setTools(Arrays.asList(new FileSearchToolDefinition()));

testRunner.accept(fileDetails, assistantOptions);
}

void createFunctionToolCallRunner(BiConsumer<AssistantCreationOptions, AssistantThreadCreationOptions> testRunner) {
FunctionsToolCallHelper functionsToolCallHelper = new FunctionsToolCallHelper();
List<ToolDefinition> toolDefinition = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.azure.ai.openai.assistants.models.ThreadMessageOptions;
import com.azure.ai.openai.assistants.models.ThreadRun;
import com.azure.ai.openai.assistants.implementation.AsyncUtils;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -32,10 +33,11 @@
import static com.azure.ai.openai.assistants.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class AzureFileSearchAsyncTest extends AssistantsClientTestBase {
public class AzureFileSearchAsyncTest extends FileSearchTestBase {

AssistantsAsyncClient client;

Expand All @@ -55,7 +57,10 @@ public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serv
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
)))));
assistantCreationOptions.setToolResources(createToolResourcesOptions);
cleanUp.setFile(openAIFile);
return client.createAssistant(assistantCreationOptions).zipWith(Mono.just(cleanUp));
Expand Down Expand Up @@ -122,4 +127,37 @@ public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serv
.verifyComplete();
});
}

@Disabled("file_search tools are not supported in Azure")
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters")
public void fileSearchWithMaxNumberResult(HttpClient httpClient, AssistantsServiceVersion serviceVersion) {
client = getAssistantsAsyncClient(httpClient, serviceVersion);

fileSearchWithMaxNumberResultRunner((fileDetails, assistantCreationOptions) -> {
// Upload file
StepVerifier.create(client.uploadFile(fileDetails, FilePurpose.ASSISTANTS)
.flatMap(openAIFile -> {
// Create assistant
AsyncUtils cleanUp = new AsyncUtils();
CreateToolResourcesOptions createToolResourcesOptions = new CreateToolResourcesOptions();
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
))
)
)
);
assistantCreationOptions.setToolResources(createToolResourcesOptions);

cleanUp.setFile(openAIFile);
return client.createAssistant(assistantCreationOptions)
.zipWith(Mono.just(cleanUp));
})
).verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.azure.ai.openai.assistants.models.ThreadMessage;
import com.azure.ai.openai.assistants.models.ThreadMessageOptions;
import com.azure.ai.openai.assistants.models.ThreadRun;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -30,16 +31,17 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class AzureFileSearchSyncTest extends AssistantsClientTestBase {
public class AzureFileSearchSyncTest extends FileSearchTestBase {

AssistantsClient client;

@Disabled("Retrieval tools are not supported in Azure")
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters")
public void basicRetrieval(HttpClient httpClient, AssistantsServiceVersion serviceVersion) {
public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) {
client = getAssistantsClient(httpClient, serviceVersion);

createRetrievalRunner((fileDetails, assistantCreationOptions) -> {
Expand All @@ -51,7 +53,10 @@ public void basicRetrieval(HttpClient httpClient, AssistantsServiceVersion servi
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null
)))));
assistantCreationOptions.setToolResources(createToolResourcesOptions);
Assistant assistant = client.createAssistant(assistantCreationOptions);

Expand Down Expand Up @@ -97,5 +102,38 @@ public void basicRetrieval(HttpClient httpClient, AssistantsServiceVersion servi
});
}

@Disabled("file_search tools are not supported in Azure")
@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters")
public void fileSearchWithMaxNumberResult(HttpClient httpClient, AssistantsServiceVersion serviceVersion) {
client = getAssistantsClient(httpClient, serviceVersion);

fileSearchWithMaxNumberResultRunner((fileDetails, assistantCreationOptions) -> {
// Upload file for assistant
OpenAIFile openAIFile = client.uploadFile(fileDetails, FilePurpose.ASSISTANTS);

// Create assistant
CreateToolResourcesOptions createToolResourcesOptions = new CreateToolResourcesOptions();
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(
new CreateFileSearchToolResourceVectorStoreOptions(
Arrays.asList(openAIFile.getId()),
null)
)
)
)
);
assistantCreationOptions.setToolResources(createToolResourcesOptions);

assertThrows(HttpResponseException.class, () -> {
Assistant assistant = client.createAssistant(assistantCreationOptions);
client.deleteAssistant(assistant.getId());
});

// cleanup
client.deleteFile(openAIFile.getId());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void runThreadSimpleTest(HttpClient httpClient, AssistantsServiceVersion
streamEvents.forEach(AssistantsClientTestBase::assertStreamUpdate);
}, mathTutorAssistantId);
}

@ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS)
@MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters")
public void runThreadWithTools(HttpClient httpClient, AssistantsServiceVersion serviceVersion) {
Expand Down
Loading