From 0879248587cb01be601faf8a88db6ba66101127b Mon Sep 17 00:00:00 2001 From: Shawn Fang <45607042+mssfang@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:05:55 -0700 Subject: [PATCH] [OpenAI-Assistant] Added support for 2024-07-01 (#41464) * Added support 2024-07-01 service API version (#41473) --- .../azure-ai-openai-assistants/CHANGELOG.md | 16 ++ .../azure-ai-openai-assistants/README.md | 3 +- .../azure-ai-openai-assistants/assets.json | 4 +- .../assistants/AssistantsAsyncClient.java | 59 +++++++ .../openai/assistants/AssistantsClient.java | 58 +++++++ .../assistants/AssistantsServiceVersion.java | 9 +- .../implementation/AssistantsClientImpl.java | 54 +++++- .../CreateVectorStoreFileBatchRequest.java | 44 ++++- .../models/CreateVectorStoreFileRequest.java | 44 ++++- ...eSearchToolResourceVectorStoreOptions.java | 56 ++++-- .../models/FileSearchToolDefinition.java | 35 +++- .../FileSearchToolDefinitionDetails.java | 103 +++++++++++ ...ateCodeInterpreterToolResourceOptions.java | 4 +- ...ectorStoreAutoChunkingStrategyRequest.java | 80 +++++++++ ...ctorStoreAutoChunkingStrategyResponse.java | 81 +++++++++ .../VectorStoreChunkingStrategyRequest.java | 110 ++++++++++++ ...ectorStoreChunkingStrategyRequestType.java | 58 +++++++ .../VectorStoreChunkingStrategyResponse.java | 110 ++++++++++++ ...ctorStoreChunkingStrategyResponseType.java | 58 +++++++ .../assistants/models/VectorStoreFile.java | 75 +++++--- .../assistants/models/VectorStoreOptions.java | 35 ++++ ...torStoreStaticChunkingStrategyOptions.java | 109 ++++++++++++ ...torStoreStaticChunkingStrategyRequest.java | 105 ++++++++++++ ...orStoreStaticChunkingStrategyResponse.java | 105 ++++++++++++ ...-openai-assistants_apiview_properties.json | 10 ++ .../assistants/FileSearchToolSample.java | 3 +- .../ai/openai/assistants/ReadmeSamples.java | 3 +- .../assistants/AssistantsClientTestBase.java | 13 -- .../assistants/AzureFileSearchAsyncTest.java | 160 ++++++++++-------- .../assistants/AzureFileSearchSyncTest.java | 40 ++++- .../assistants/AzureStreamingSyncTest.java | 1 + .../AzureVectorStoreAsyncTests.java | 159 +++++++++++++---- .../assistants/AzureVectorStoreSyncTests.java | 121 +++++++++++-- .../assistants/FileSearchAsyncTest.java | 36 +++- .../openai/assistants/FileSearchSyncTest.java | 36 +++- .../openai/assistants/FileSearchTestBase.java | 51 ++++++ .../assistants/VectorStoreAsyncTests.java | 131 +++++++++++--- .../assistants/VectorStoreSyncTests.java | 119 +++++++++++-- .../assistants/VectorStoreTestBase.java | 57 +++++++ .../tsp-location.yaml | 2 +- 40 files changed, 2114 insertions(+), 243 deletions(-) create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinitionDetails.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyRequest.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyResponse.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequest.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequestType.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponse.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponseType.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyOptions.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyRequest.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyResponse.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchTestBase.java create mode 100644 sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreTestBase.java diff --git a/sdk/openai/azure-ai-openai-assistants/CHANGELOG.md b/sdk/openai/azure-ai-openai-assistants/CHANGELOG.md index 95dc3d85282d..af4ea7a7465a 100644 --- a/sdk/openai/azure-ai-openai-assistants/CHANGELOG.md +++ b/sdk/openai/azure-ai-openai-assistants/CHANGELOG.md @@ -4,6 +4,22 @@ ### 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 ### Bugs Fixed diff --git a/sdk/openai/azure-ai-openai-assistants/README.md b/sdk/openai/azure-ai-openai-assistants/README.md index 2167db2e0ed0..b3301c2bef63 100644 --- a/sdk/openai/azure-ai-openai-assistants/README.md +++ b/sdk/openai/azure-ai-openai-assistants/README.md @@ -168,7 +168,8 @@ 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())))))); Assistant assistant = client.createAssistant( new AssistantCreationOptions(deploymentOrModelId) diff --git a/sdk/openai/azure-ai-openai-assistants/assets.json b/sdk/openai/azure-ai-openai-assistants/assets.json index bb5b7fab51bf..7de07bd5a222 100644 --- a/sdk/openai/azure-ai-openai-assistants/assets.json +++ b/sdk/openai/azure-ai-openai-assistants/assets.json @@ -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" -} \ No newline at end of file + "Tag" : "java/assistants/azure-ai-openai-assistants_19cb2164a3" +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsAsyncClient.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsAsyncClient.java index 872a1f436733..5e1a26b677ed 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsAsyncClient.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsAsyncClient.java @@ -39,6 +39,7 @@ import com.azure.ai.openai.assistants.models.UpdateAssistantOptions; import com.azure.ai.openai.assistants.models.UpdateAssistantThreadOptions; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequest; import com.azure.ai.openai.assistants.models.VectorStoreDeletionStatus; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; @@ -3751,4 +3752,62 @@ public Mono> listVectorStoreFileBatchFiles(String .map(vectorStoreFileList -> PageableListAccessHelper.create(vectorStoreFileList.getData(), vectorStoreFileList.getFirstId(), vectorStoreFileList.getLastId(), vectorStoreFileList.isHasMore())); } + + /** + * Create a vector store file by attaching a file to a vector store. + * + * @param vectorStoreId The ID of the vector store for which to create a File. + * @param fileId A File ID that the vector store should use. Useful for tools like `file_search` that can access + * files. + * @param chunkingStrategy The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return description of a file attached to a vector store on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createVectorStoreFile(String vectorStoreId, String fileId, + VectorStoreChunkingStrategyRequest chunkingStrategy) { + // Generated convenience method for createVectorStoreFileWithResponse + RequestOptions requestOptions = new RequestOptions(); + CreateVectorStoreFileRequest createVectorStoreFileRequestObj + = new CreateVectorStoreFileRequest(fileId).setChunkingStrategy(chunkingStrategy); + BinaryData createVectorStoreFileRequest = BinaryData.fromObject(createVectorStoreFileRequestObj); + return createVectorStoreFileWithResponse(vectorStoreId, createVectorStoreFileRequest, requestOptions) + .flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(VectorStoreFile.class)); + } + + /** + * Create a vector store file batch. + * + * @param vectorStoreId The ID of the vector store for which to create a File Batch. + * @param fileIds A list of File IDs that the vector store should use. Useful for tools like `file_search` that can + * access files. + * @param chunkingStrategy The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a batch of files attached to a vector store on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono createVectorStoreFileBatch(String vectorStoreId, List fileIds, + VectorStoreChunkingStrategyRequest chunkingStrategy) { + // Generated convenience method for createVectorStoreFileBatchWithResponse + RequestOptions requestOptions = new RequestOptions(); + CreateVectorStoreFileBatchRequest createVectorStoreFileBatchRequestObj + = new CreateVectorStoreFileBatchRequest(fileIds).setChunkingStrategy(chunkingStrategy); + BinaryData createVectorStoreFileBatchRequest = BinaryData.fromObject(createVectorStoreFileBatchRequestObj); + return createVectorStoreFileBatchWithResponse(vectorStoreId, createVectorStoreFileBatchRequest, requestOptions) + .flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(VectorStoreFileBatch.class)); + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsClient.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsClient.java index 7b8f04ed9f74..b7f1ab2fd9fe 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsClient.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsClient.java @@ -39,6 +39,7 @@ import com.azure.ai.openai.assistants.models.UpdateAssistantOptions; import com.azure.ai.openai.assistants.models.UpdateAssistantThreadOptions; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequest; import com.azure.ai.openai.assistants.models.VectorStoreDeletionStatus; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; @@ -3765,4 +3766,61 @@ public PageableList listVectorStoreFileBatchFiles(String vector return PageableListAccessHelper.create(vectorStoreFileList.getData(), vectorStoreFileList.getFirstId(), vectorStoreFileList.getLastId(), vectorStoreFileList.isHasMore()); } + + /** + * Create a vector store file by attaching a file to a vector store. + * + * @param vectorStoreId The ID of the vector store for which to create a File. + * @param fileId A File ID that the vector store should use. Useful for tools like `file_search` that can access + * files. + * @param chunkingStrategy The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return description of a file attached to a vector store. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public VectorStoreFile createVectorStoreFile(String vectorStoreId, String fileId, + VectorStoreChunkingStrategyRequest chunkingStrategy) { + // Generated convenience method for createVectorStoreFileWithResponse + RequestOptions requestOptions = new RequestOptions(); + CreateVectorStoreFileRequest createVectorStoreFileRequestObj + = new CreateVectorStoreFileRequest(fileId).setChunkingStrategy(chunkingStrategy); + BinaryData createVectorStoreFileRequest = BinaryData.fromObject(createVectorStoreFileRequestObj); + return createVectorStoreFileWithResponse(vectorStoreId, createVectorStoreFileRequest, requestOptions).getValue() + .toObject(VectorStoreFile.class); + } + + /** + * Create a vector store file batch. + * + * @param vectorStoreId The ID of the vector store for which to create a File Batch. + * @param fileIds A list of File IDs that the vector store should use. Useful for tools like `file_search` that can + * access files. + * @param chunkingStrategy The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a batch of files attached to a vector store. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public VectorStoreFileBatch createVectorStoreFileBatch(String vectorStoreId, List fileIds, + VectorStoreChunkingStrategyRequest chunkingStrategy) { + // Generated convenience method for createVectorStoreFileBatchWithResponse + RequestOptions requestOptions = new RequestOptions(); + CreateVectorStoreFileBatchRequest createVectorStoreFileBatchRequestObj + = new CreateVectorStoreFileBatchRequest(fileIds).setChunkingStrategy(chunkingStrategy); + BinaryData createVectorStoreFileBatchRequest = BinaryData.fromObject(createVectorStoreFileBatchRequestObj); + return createVectorStoreFileBatchWithResponse(vectorStoreId, createVectorStoreFileBatchRequest, requestOptions) + .getValue() + .toObject(VectorStoreFileBatch.class); + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsServiceVersion.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsServiceVersion.java index a715a01de4e4..9e9fadb08ff1 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsServiceVersion.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/AssistantsServiceVersion.java @@ -18,7 +18,12 @@ public enum AssistantsServiceVersion implements ServiceVersion { /** * Enum value 2024-05-01-preview. */ - V2024_05_01_PREVIEW("2024-05-01-preview"); + V2024_05_01_PREVIEW("2024-05-01-preview"), + + /** + * Enum value 2024-07-01-preview. + */ + V2024_07_01_PREVIEW("2024-07-01-preview"); private final String version; @@ -40,6 +45,6 @@ public String getVersion() { * @return The latest {@link AssistantsServiceVersion}. */ public static AssistantsServiceVersion getLatest() { - return V2024_05_01_PREVIEW; + return V2024_07_01_PREVIEW; } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/AssistantsClientImpl.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/AssistantsClientImpl.java index 2574bcdd978c..d1e2ade5c274 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/AssistantsClientImpl.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/AssistantsClientImpl.java @@ -1437,7 +1437,7 @@ public Response getAssistantWithResponse(String assistantId, Request * ] * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -1529,7 +1529,7 @@ public Mono> updateAssistantWithResponseAsync(String assist * ] * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -1909,7 +1909,7 @@ public Response getThreadWithResponse(String threadId, RequestOption * { * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -1977,7 +1977,7 @@ public Mono> updateThreadWithResponseAsync(String threadId, * { * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -3767,7 +3767,7 @@ public Response cancelRunWithResponse(String threadId, String runId, * ] * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -3909,7 +3909,7 @@ public Mono> createThreadAndRunWithResponseAsync(BinaryData * ] * tool_resources (Optional): { * code_interpreter (Optional): { - * fileIds (Optional): [ + * file_ids (Optional): [ * String (Optional) * ] * } @@ -4740,6 +4740,9 @@ public Response listVectorStoresWithResponse(RequestOptions requestO * anchor: String(last_active_at) (Required) * days: int (Required) * } + * chunking_strategy (Optional): { + * type: String(auto/static) (Required) + * } * metadata (Optional): { * String: String (Required) * } @@ -4807,6 +4810,9 @@ public Mono> createVectorStoreWithResponseAsync(BinaryData * anchor: String(last_active_at) (Required) * days: int (Required) * } + * chunking_strategy (Optional): { + * type: String(auto/static) (Required) + * } * metadata (Optional): { * String: String (Required) * } @@ -5177,6 +5183,9 @@ public Response deleteVectorStoreWithResponse(String vectorStoreId, * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * ] * first_id: String (Required) @@ -5240,6 +5249,9 @@ public Mono> listVectorStoreFilesWithResponseAsync(String v * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * ] * first_id: String (Required) @@ -5270,6 +5282,9 @@ public Response listVectorStoreFilesWithResponse(String vectorStoreI *
{@code
      * {
      *     file_id: String (Required)
+     *     chunking_strategy (Optional): {
+     *         type: String(auto/static) (Required)
+     *     }
      * }
      * }
* @@ -5287,6 +5302,9 @@ public Response listVectorStoreFilesWithResponse(String vectorStoreI * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * } * @@ -5316,6 +5334,9 @@ public Mono> createVectorStoreFileWithResponseAsync(String *
{@code
      * {
      *     file_id: String (Required)
+     *     chunking_strategy (Optional): {
+     *         type: String(auto/static) (Required)
+     *     }
      * }
      * }
* @@ -5333,6 +5354,9 @@ public Mono> createVectorStoreFileWithResponseAsync(String * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * } * @@ -5370,6 +5394,9 @@ public Response createVectorStoreFileWithResponse(String vectorStore * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * } * @@ -5407,6 +5434,9 @@ public Mono> getVectorStoreFileWithResponseAsync(String vec * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * } * @@ -5499,6 +5529,9 @@ public Response deleteVectorStoreFileWithResponse(String vectorStore * file_ids (Required): [ * String (Required) * ] + * chunking_strategy (Optional): { + * type: String(auto/static) (Required) + * } * } * } * @@ -5549,6 +5582,9 @@ public Mono> createVectorStoreFileBatchWithResponseAsync(St * file_ids (Required): [ * String (Required) * ] + * chunking_strategy (Optional): { + * type: String(auto/static) (Required) + * } * } * } * @@ -5783,6 +5819,9 @@ public Response cancelVectorStoreFileBatchWithResponse(String vector * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * ] * first_id: String (Required) @@ -5847,6 +5886,9 @@ public Mono> listVectorStoreFileBatchFilesWithResponseAsync * code: String(internal_error/file_not_found/parsing_error/unhandled_mime_type) (Required) * message: String (Required) * } + * chunking_strategy (Required): { + * type: String(other/static) (Required) + * } * } * ] * first_id: String (Required) diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileBatchRequest.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileBatchRequest.java index ef39d1f4bd26..129ffd6a0013 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileBatchRequest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileBatchRequest.java @@ -3,8 +3,9 @@ // Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.ai.openai.assistants.implementation.models; +import com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequest; +import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -15,7 +16,7 @@ /** * The CreateVectorStoreFileBatchRequest model. */ -@Immutable +@Fluent public final class CreateVectorStoreFileBatchRequest implements JsonSerializable { /* @@ -53,6 +54,7 @@ public List getFileIds() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeArrayField("file_ids", this.fileIds, (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("chunking_strategy", this.chunkingStrategy); return jsonWriter.writeEndObject(); } @@ -69,16 +71,52 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { public static CreateVectorStoreFileBatchRequest fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { List fileIds = null; + VectorStoreChunkingStrategyRequest chunkingStrategy = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); if ("file_ids".equals(fieldName)) { fileIds = reader.readArray(reader1 -> reader1.getString()); + } else if ("chunking_strategy".equals(fieldName)) { + chunkingStrategy = VectorStoreChunkingStrategyRequest.fromJson(reader); } else { reader.skipChildren(); } } - return new CreateVectorStoreFileBatchRequest(fileIds); + CreateVectorStoreFileBatchRequest deserializedCreateVectorStoreFileBatchRequest + = new CreateVectorStoreFileBatchRequest(fileIds); + deserializedCreateVectorStoreFileBatchRequest.chunkingStrategy = chunkingStrategy; + return deserializedCreateVectorStoreFileBatchRequest; }); } + + /* + * The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + */ + @Generated + private VectorStoreChunkingStrategyRequest chunkingStrategy; + + /** + * Get the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. + * + * @return the chunkingStrategy value. + */ + @Generated + public VectorStoreChunkingStrategyRequest getChunkingStrategy() { + return this.chunkingStrategy; + } + + /** + * Set the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. + * + * @param chunkingStrategy the chunkingStrategy value to set. + * @return the CreateVectorStoreFileBatchRequest object itself. + */ + @Generated + public CreateVectorStoreFileBatchRequest setChunkingStrategy(VectorStoreChunkingStrategyRequest chunkingStrategy) { + this.chunkingStrategy = chunkingStrategy; + return this; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileRequest.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileRequest.java index 1ce2d4c1a4c7..895c186508a4 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileRequest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/implementation/models/CreateVectorStoreFileRequest.java @@ -3,8 +3,9 @@ // Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.ai.openai.assistants.implementation.models; +import com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequest; +import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -14,7 +15,7 @@ /** * The CreateVectorStoreFileRequest model. */ -@Immutable +@Fluent public final class CreateVectorStoreFileRequest implements JsonSerializable { /* @@ -52,6 +53,7 @@ public String getFileId() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("file_id", this.fileId); + jsonWriter.writeJsonField("chunking_strategy", this.chunkingStrategy); return jsonWriter.writeEndObject(); } @@ -68,16 +70,52 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { public static CreateVectorStoreFileRequest fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { String fileId = null; + VectorStoreChunkingStrategyRequest chunkingStrategy = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); if ("file_id".equals(fieldName)) { fileId = reader.getString(); + } else if ("chunking_strategy".equals(fieldName)) { + chunkingStrategy = VectorStoreChunkingStrategyRequest.fromJson(reader); } else { reader.skipChildren(); } } - return new CreateVectorStoreFileRequest(fileId); + CreateVectorStoreFileRequest deserializedCreateVectorStoreFileRequest + = new CreateVectorStoreFileRequest(fileId); + deserializedCreateVectorStoreFileRequest.chunkingStrategy = chunkingStrategy; + return deserializedCreateVectorStoreFileRequest; }); } + + /* + * The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. + */ + @Generated + private VectorStoreChunkingStrategyRequest chunkingStrategy; + + /** + * Get the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. + * + * @return the chunkingStrategy value. + */ + @Generated + public VectorStoreChunkingStrategyRequest getChunkingStrategy() { + return this.chunkingStrategy; + } + + /** + * Set the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. + * + * @param chunkingStrategy the chunkingStrategy value to set. + * @return the CreateVectorStoreFileRequest object itself. + */ + @Generated + public CreateVectorStoreFileRequest setChunkingStrategy(VectorStoreChunkingStrategyRequest chunkingStrategy) { + this.chunkingStrategy = chunkingStrategy; + return this; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/CreateFileSearchToolResourceVectorStoreOptions.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/CreateFileSearchToolResourceVectorStoreOptions.java index 164d842b2109..df7e514a8323 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/CreateFileSearchToolResourceVectorStoreOptions.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/CreateFileSearchToolResourceVectorStoreOptions.java @@ -34,16 +34,6 @@ public final class CreateFileSearchToolResourceVectorStoreOptions @Generated private Map metadata; - /** - * Creates an instance of CreateFileSearchToolResourceVectorStoreOptions class. - * - * @param fileIds the fileIds value to set. - */ - @Generated - public CreateFileSearchToolResourceVectorStoreOptions(List fileIds) { - this.fileIds = fileIds; - } - /** * Get the fileIds property: A list of file IDs to add to the vector store. There can be a maximum of 10000 files in * a vector store. @@ -89,6 +79,7 @@ public CreateFileSearchToolResourceVectorStoreOptions setMetadata(Map writer.writeString(element)); + jsonWriter.writeJsonField("chunking_strategy", this.chunkingStrategy); jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); } @@ -106,12 +97,15 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { public static CreateFileSearchToolResourceVectorStoreOptions fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { List fileIds = null; + VectorStoreChunkingStrategyRequest chunkingStrategy = null; Map metadata = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); if ("file_ids".equals(fieldName)) { fileIds = reader.readArray(reader1 -> reader1.getString()); + } else if ("chunking_strategy".equals(fieldName)) { + chunkingStrategy = VectorStoreChunkingStrategyRequest.fromJson(reader); } else if ("metadata".equals(fieldName)) { metadata = reader.readMap(reader1 -> reader1.getString()); } else { @@ -119,9 +113,49 @@ public static CreateFileSearchToolResourceVectorStoreOptions fromJson(JsonReader } } CreateFileSearchToolResourceVectorStoreOptions deserializedCreateFileSearchToolResourceVectorStoreOptions - = new CreateFileSearchToolResourceVectorStoreOptions(fileIds); + = new CreateFileSearchToolResourceVectorStoreOptions(fileIds, chunkingStrategy); deserializedCreateFileSearchToolResourceVectorStoreOptions.metadata = metadata; return deserializedCreateFileSearchToolResourceVectorStoreOptions; }); } + + /* + * The chunking strategy used to chunk the file(s). If not set, will use the `auto` strategy. + */ + @Generated + private final VectorStoreChunkingStrategyRequest chunkingStrategy; + + /** + * Creates an instance of CreateFileSearchToolResourceVectorStoreOptions class. + * + * @param fileIds the fileIds value to set. + */ + public CreateFileSearchToolResourceVectorStoreOptions(List fileIds) { + this.fileIds = fileIds; + this.chunkingStrategy = null; + } + + /** + * Creates an instance of CreateFileSearchToolResourceVectorStoreOptions class. + * + * @param fileIds the fileIds value to set. + * @param chunkingStrategy the chunkingStrategy value to set. + */ + @Generated + public CreateFileSearchToolResourceVectorStoreOptions(List fileIds, + VectorStoreChunkingStrategyRequest chunkingStrategy) { + this.fileIds = fileIds; + this.chunkingStrategy = chunkingStrategy; + } + + /** + * Get the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the + * `auto` strategy. + * + * @return the chunkingStrategy value. + */ + @Generated + public VectorStoreChunkingStrategyRequest getChunkingStrategy() { + return this.chunkingStrategy; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinition.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinition.java index ce59229776ca..8a4833151fe6 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinition.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinition.java @@ -3,8 +3,8 @@ // Code generated by Microsoft (R) TypeSpec Code Generator. package com.azure.ai.openai.assistants.models; +import com.azure.core.annotation.Fluent; import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; import com.azure.json.JsonReader; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; @@ -13,7 +13,7 @@ /** * The input definition information for a file search tool as used to configure an assistant. */ -@Immutable +@Fluent public final class FileSearchToolDefinition extends ToolDefinition { /* @@ -48,6 +48,7 @@ public String getType() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("type", this.type); + jsonWriter.writeJsonField("file_search", this.fileSearch); return jsonWriter.writeEndObject(); } @@ -68,6 +69,8 @@ public static FileSearchToolDefinition fromJson(JsonReader jsonReader) throws IO reader.nextToken(); if ("type".equals(fieldName)) { deserializedFileSearchToolDefinition.type = reader.getString(); + } else if ("file_search".equals(fieldName)) { + deserializedFileSearchToolDefinition.fileSearch = FileSearchToolDefinitionDetails.fromJson(reader); } else { reader.skipChildren(); } @@ -75,4 +78,32 @@ public static FileSearchToolDefinition fromJson(JsonReader jsonReader) throws IO return deserializedFileSearchToolDefinition; }); } + + /* + * Options overrides for the file search tool. + */ + @Generated + private FileSearchToolDefinitionDetails fileSearch; + + /** + * Get the fileSearch property: Options overrides for the file search tool. + * + * @return the fileSearch value. + */ + @Generated + public FileSearchToolDefinitionDetails getFileSearch() { + return this.fileSearch; + } + + /** + * Set the fileSearch property: Options overrides for the file search tool. + * + * @param fileSearch the fileSearch value to set. + * @return the FileSearchToolDefinition object itself. + */ + @Generated + public FileSearchToolDefinition setFileSearch(FileSearchToolDefinitionDetails fileSearch) { + this.fileSearch = fileSearch; + return this; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinitionDetails.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinitionDetails.java new file mode 100644 index 000000000000..5210d26ab7c1 --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/FileSearchToolDefinitionDetails.java @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Options overrides for the file search tool. + */ +@Fluent +public final class FileSearchToolDefinitionDetails implements JsonSerializable { + + /* + * The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for + * gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + * + * Note that the file search tool may output fewer than `max_num_results` results. See the file search tool + * documentation for more information. + */ + @Generated + private Integer maxNumResults; + + /** + * Creates an instance of FileSearchToolDefinitionDetails class. + */ + @Generated + public FileSearchToolDefinitionDetails() { + } + + /** + * Get the maxNumResults property: The maximum number of results the file search tool should output. The default is + * 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + * + * Note that the file search tool may output fewer than `max_num_results` results. See the file search tool + * documentation for more information. + * + * @return the maxNumResults value. + */ + @Generated + public Integer getMaxNumResults() { + return this.maxNumResults; + } + + /** + * Set the maxNumResults property: The maximum number of results the file search tool should output. The default is + * 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive. + * + * Note that the file search tool may output fewer than `max_num_results` results. See the file search tool + * documentation for more information. + * + * @param maxNumResults the maxNumResults value to set. + * @return the FileSearchToolDefinitionDetails object itself. + */ + @Generated + public FileSearchToolDefinitionDetails setMaxNumResults(Integer maxNumResults) { + this.maxNumResults = maxNumResults; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeNumberField("max_num_results", this.maxNumResults); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of FileSearchToolDefinitionDetails from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of FileSearchToolDefinitionDetails if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the FileSearchToolDefinitionDetails. + */ + @Generated + public static FileSearchToolDefinitionDetails fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + FileSearchToolDefinitionDetails deserializedFileSearchToolDefinitionDetails + = new FileSearchToolDefinitionDetails(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("max_num_results".equals(fieldName)) { + deserializedFileSearchToolDefinitionDetails.maxNumResults = reader.getNullable(JsonReader::getInt); + } else { + reader.skipChildren(); + } + } + return deserializedFileSearchToolDefinitionDetails; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/UpdateCodeInterpreterToolResourceOptions.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/UpdateCodeInterpreterToolResourceOptions.java index 14ec574ec84c..9ace038ac79d 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/UpdateCodeInterpreterToolResourceOptions.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/UpdateCodeInterpreterToolResourceOptions.java @@ -61,7 +61,7 @@ public UpdateCodeInterpreterToolResourceOptions setFileIds(List fileIds) @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeArrayField("fileIds", this.fileIds, (writer, element) -> writer.writeString(element)); + jsonWriter.writeArrayField("file_ids", this.fileIds, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); } @@ -81,7 +81,7 @@ public static UpdateCodeInterpreterToolResourceOptions fromJson(JsonReader jsonR while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("fileIds".equals(fieldName)) { + if ("file_ids".equals(fieldName)) { List fileIds = reader.readArray(reader1 -> reader1.getString()); deserializedUpdateCodeInterpreterToolResourceOptions.fileIds = fileIds; } else { diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyRequest.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyRequest.java new file mode 100644 index 000000000000..84522040310e --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyRequest.java @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The default strategy. This strategy currently uses a max_chunk_size_tokens of 800 and chunk_overlap_tokens of 400. + */ +@Immutable +public final class VectorStoreAutoChunkingStrategyRequest extends VectorStoreChunkingStrategyRequest { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyRequestType type = VectorStoreChunkingStrategyRequestType.AUTO; + + /** + * Creates an instance of VectorStoreAutoChunkingStrategyRequest class. + */ + @Generated + public VectorStoreAutoChunkingStrategyRequest() { + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + @Override + public VectorStoreChunkingStrategyRequestType getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreAutoChunkingStrategyRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreAutoChunkingStrategyRequest if the JsonReader was pointing to an instance of + * it, or null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the VectorStoreAutoChunkingStrategyRequest. + */ + @Generated + public static VectorStoreAutoChunkingStrategyRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreAutoChunkingStrategyRequest deserializedVectorStoreAutoChunkingStrategyRequest + = new VectorStoreAutoChunkingStrategyRequest(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("type".equals(fieldName)) { + deserializedVectorStoreAutoChunkingStrategyRequest.type + = VectorStoreChunkingStrategyRequestType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + return deserializedVectorStoreAutoChunkingStrategyRequest; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyResponse.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyResponse.java new file mode 100644 index 000000000000..73e65c62979f --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreAutoChunkingStrategyResponse.java @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * This is returned when the chunking strategy is unknown. Typically, this is because the file was indexed before the + * chunking_strategy concept was introduced in the API. + */ +@Immutable +public final class VectorStoreAutoChunkingStrategyResponse extends VectorStoreChunkingStrategyResponse { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyResponseType type = VectorStoreChunkingStrategyResponseType.OTHER; + + /** + * Creates an instance of VectorStoreAutoChunkingStrategyResponse class. + */ + @Generated + private VectorStoreAutoChunkingStrategyResponse() { + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + @Override + public VectorStoreChunkingStrategyResponseType getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreAutoChunkingStrategyResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreAutoChunkingStrategyResponse if the JsonReader was pointing to an instance of + * it, or null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the VectorStoreAutoChunkingStrategyResponse. + */ + @Generated + public static VectorStoreAutoChunkingStrategyResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreAutoChunkingStrategyResponse deserializedVectorStoreAutoChunkingStrategyResponse + = new VectorStoreAutoChunkingStrategyResponse(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("type".equals(fieldName)) { + deserializedVectorStoreAutoChunkingStrategyResponse.type + = VectorStoreChunkingStrategyResponseType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + return deserializedVectorStoreAutoChunkingStrategyResponse; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequest.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequest.java new file mode 100644 index 000000000000..b8f2ce389b63 --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequest.java @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * An abstract representation of a vector store chunking strategy configuration. + */ +@Immutable +public class VectorStoreChunkingStrategyRequest implements JsonSerializable { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyRequestType type + = VectorStoreChunkingStrategyRequestType.fromString("VectorStoreChunkingStrategyRequest"); + + /** + * Creates an instance of VectorStoreChunkingStrategyRequest class. + */ + @Generated + public VectorStoreChunkingStrategyRequest() { + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + public VectorStoreChunkingStrategyRequestType getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreChunkingStrategyRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreChunkingStrategyRequest if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the VectorStoreChunkingStrategyRequest. + */ + @Generated + public static VectorStoreChunkingStrategyRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String discriminatorValue = null; + try (JsonReader readerToUse = reader.bufferObject()) { + // Prepare for reading + readerToUse.nextToken(); + while (readerToUse.nextToken() != JsonToken.END_OBJECT) { + String fieldName = readerToUse.getFieldName(); + readerToUse.nextToken(); + if ("type".equals(fieldName)) { + discriminatorValue = readerToUse.getString(); + break; + } else { + readerToUse.skipChildren(); + } + } + // Use the discriminator value to determine which subtype should be deserialized. + if ("auto".equals(discriminatorValue)) { + return VectorStoreAutoChunkingStrategyRequest.fromJson(readerToUse.reset()); + } else if ("static".equals(discriminatorValue)) { + return VectorStoreStaticChunkingStrategyRequest.fromJson(readerToUse.reset()); + } else { + return fromJsonKnownDiscriminator(readerToUse.reset()); + } + } + }); + } + + @Generated + static VectorStoreChunkingStrategyRequest fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreChunkingStrategyRequest deserializedVectorStoreChunkingStrategyRequest + = new VectorStoreChunkingStrategyRequest(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("type".equals(fieldName)) { + deserializedVectorStoreChunkingStrategyRequest.type + = VectorStoreChunkingStrategyRequestType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + return deserializedVectorStoreChunkingStrategyRequest; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequestType.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequestType.java new file mode 100644 index 000000000000..e88ccc2cb1cc --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyRequestType.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Type of chunking strategy. + */ +public final class VectorStoreChunkingStrategyRequestType + extends ExpandableStringEnum { + + /** + * Static value auto for VectorStoreChunkingStrategyRequestType. + */ + @Generated + public static final VectorStoreChunkingStrategyRequestType AUTO = fromString("auto"); + + /** + * Static value static for VectorStoreChunkingStrategyRequestType. + */ + @Generated + public static final VectorStoreChunkingStrategyRequestType STATIC = fromString("static"); + + /** + * Creates a new instance of VectorStoreChunkingStrategyRequestType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public VectorStoreChunkingStrategyRequestType() { + } + + /** + * Creates or finds a VectorStoreChunkingStrategyRequestType from its string representation. + * + * @param name a name to look for. + * @return the corresponding VectorStoreChunkingStrategyRequestType. + */ + @Generated + public static VectorStoreChunkingStrategyRequestType fromString(String name) { + return fromString(name, VectorStoreChunkingStrategyRequestType.class); + } + + /** + * Gets known VectorStoreChunkingStrategyRequestType values. + * + * @return known VectorStoreChunkingStrategyRequestType values. + */ + @Generated + public static Collection values() { + return values(VectorStoreChunkingStrategyRequestType.class); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponse.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponse.java new file mode 100644 index 000000000000..005650ac2275 --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponse.java @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * An abstract representation of a vector store chunking strategy configuration. + */ +@Immutable +public class VectorStoreChunkingStrategyResponse implements JsonSerializable { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyResponseType type + = VectorStoreChunkingStrategyResponseType.fromString("VectorStoreChunkingStrategyResponse"); + + /** + * Creates an instance of VectorStoreChunkingStrategyResponse class. + */ + @Generated + protected VectorStoreChunkingStrategyResponse() { + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + public VectorStoreChunkingStrategyResponseType getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreChunkingStrategyResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreChunkingStrategyResponse if the JsonReader was pointing to an instance of it, + * or null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the VectorStoreChunkingStrategyResponse. + */ + @Generated + public static VectorStoreChunkingStrategyResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String discriminatorValue = null; + try (JsonReader readerToUse = reader.bufferObject()) { + // Prepare for reading + readerToUse.nextToken(); + while (readerToUse.nextToken() != JsonToken.END_OBJECT) { + String fieldName = readerToUse.getFieldName(); + readerToUse.nextToken(); + if ("type".equals(fieldName)) { + discriminatorValue = readerToUse.getString(); + break; + } else { + readerToUse.skipChildren(); + } + } + // Use the discriminator value to determine which subtype should be deserialized. + if ("other".equals(discriminatorValue)) { + return VectorStoreAutoChunkingStrategyResponse.fromJson(readerToUse.reset()); + } else if ("static".equals(discriminatorValue)) { + return VectorStoreStaticChunkingStrategyResponse.fromJson(readerToUse.reset()); + } else { + return fromJsonKnownDiscriminator(readerToUse.reset()); + } + } + }); + } + + @Generated + static VectorStoreChunkingStrategyResponse fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreChunkingStrategyResponse deserializedVectorStoreChunkingStrategyResponse + = new VectorStoreChunkingStrategyResponse(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("type".equals(fieldName)) { + deserializedVectorStoreChunkingStrategyResponse.type + = VectorStoreChunkingStrategyResponseType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + return deserializedVectorStoreChunkingStrategyResponse; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponseType.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponseType.java new file mode 100644 index 000000000000..e3927a360621 --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreChunkingStrategyResponseType.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Type of chunking strategy. + */ +public final class VectorStoreChunkingStrategyResponseType + extends ExpandableStringEnum { + + /** + * Static value other for VectorStoreChunkingStrategyResponseType. + */ + @Generated + public static final VectorStoreChunkingStrategyResponseType OTHER = fromString("other"); + + /** + * Static value static for VectorStoreChunkingStrategyResponseType. + */ + @Generated + public static final VectorStoreChunkingStrategyResponseType STATIC = fromString("static"); + + /** + * Creates a new instance of VectorStoreChunkingStrategyResponseType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public VectorStoreChunkingStrategyResponseType() { + } + + /** + * Creates or finds a VectorStoreChunkingStrategyResponseType from its string representation. + * + * @param name a name to look for. + * @return the corresponding VectorStoreChunkingStrategyResponseType. + */ + @Generated + public static VectorStoreChunkingStrategyResponseType fromString(String name) { + return fromString(name, VectorStoreChunkingStrategyResponseType.class); + } + + /** + * Gets known VectorStoreChunkingStrategyResponseType values. + * + * @return known VectorStoreChunkingStrategyResponseType values. + */ + @Generated + public static Collection values() { + return values(VectorStoreChunkingStrategyResponseType.class); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreFile.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreFile.java index 9c8a971c1010..37e803429edf 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreFile.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreFile.java @@ -64,31 +64,6 @@ public final class VectorStoreFile implements JsonSerializable @Generated private final VectorStoreFileError lastError; - /** - * Creates an instance of VectorStoreFile class. - * - * @param id the id value to set. - * @param usageBytes the usageBytes value to set. - * @param createdAt the createdAt value to set. - * @param vectorStoreId the vectorStoreId value to set. - * @param status the status value to set. - * @param lastError the lastError value to set. - */ - @Generated - private VectorStoreFile(String id, int usageBytes, OffsetDateTime createdAt, String vectorStoreId, - VectorStoreFileStatus status, VectorStoreFileError lastError) { - this.id = id; - this.usageBytes = usageBytes; - if (createdAt == null) { - this.createdAt = 0L; - } else { - this.createdAt = createdAt.toEpochSecond(); - } - this.vectorStoreId = vectorStoreId; - this.status = status; - this.lastError = lastError; - } - /** * Get the id property: The identifier, which can be referenced in API endpoints. * @@ -177,6 +152,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("vector_store_id", this.vectorStoreId); jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString()); jsonWriter.writeJsonField("last_error", this.lastError); + jsonWriter.writeJsonField("chunking_strategy", this.chunkingStrategy); return jsonWriter.writeEndObject(); } @@ -198,6 +174,7 @@ public static VectorStoreFile fromJson(JsonReader jsonReader) throws IOException String vectorStoreId = null; VectorStoreFileStatus status = null; VectorStoreFileError lastError = null; + VectorStoreChunkingStrategyResponse chunkingStrategy = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); @@ -213,11 +190,57 @@ public static VectorStoreFile fromJson(JsonReader jsonReader) throws IOException status = VectorStoreFileStatus.fromString(reader.getString()); } else if ("last_error".equals(fieldName)) { lastError = VectorStoreFileError.fromJson(reader); + } else if ("chunking_strategy".equals(fieldName)) { + chunkingStrategy = VectorStoreChunkingStrategyResponse.fromJson(reader); } else { reader.skipChildren(); } } - return new VectorStoreFile(id, usageBytes, createdAt, vectorStoreId, status, lastError); + return new VectorStoreFile(id, usageBytes, createdAt, vectorStoreId, status, lastError, chunkingStrategy); }); } + + /* + * The strategy used to chunk the file. + */ + @Generated + private final VectorStoreChunkingStrategyResponse chunkingStrategy; + + /** + * Creates an instance of VectorStoreFile class. + * + * @param id the id value to set. + * @param usageBytes the usageBytes value to set. + * @param createdAt the createdAt value to set. + * @param vectorStoreId the vectorStoreId value to set. + * @param status the status value to set. + * @param lastError the lastError value to set. + * @param chunkingStrategy the chunkingStrategy value to set. + */ + @Generated + private VectorStoreFile(String id, int usageBytes, OffsetDateTime createdAt, String vectorStoreId, + VectorStoreFileStatus status, VectorStoreFileError lastError, + VectorStoreChunkingStrategyResponse chunkingStrategy) { + this.id = id; + this.usageBytes = usageBytes; + if (createdAt == null) { + this.createdAt = 0L; + } else { + this.createdAt = createdAt.toEpochSecond(); + } + this.vectorStoreId = vectorStoreId; + this.status = status; + this.lastError = lastError; + this.chunkingStrategy = chunkingStrategy; + } + + /** + * Get the chunkingStrategy property: The strategy used to chunk the file. + * + * @return the chunkingStrategy value. + */ + @Generated + public VectorStoreChunkingStrategyResponse getChunkingStrategy() { + return this.chunkingStrategy; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreOptions.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreOptions.java index e8a4ed8505f4..b0e6cfd133c5 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreOptions.java +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreOptions.java @@ -156,6 +156,7 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeArrayField("file_ids", this.fileIds, (writer, element) -> writer.writeString(element)); jsonWriter.writeStringField("name", this.name); jsonWriter.writeJsonField("expires_after", this.expiresAfter); + jsonWriter.writeJsonField("chunking_strategy", this.chunkingStrategy); jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); } @@ -182,6 +183,9 @@ public static VectorStoreOptions fromJson(JsonReader jsonReader) throws IOExcept deserializedVectorStoreOptions.name = reader.getString(); } else if ("expires_after".equals(fieldName)) { deserializedVectorStoreOptions.expiresAfter = VectorStoreExpirationPolicy.fromJson(reader); + } else if ("chunking_strategy".equals(fieldName)) { + deserializedVectorStoreOptions.chunkingStrategy + = VectorStoreChunkingStrategyRequest.fromJson(reader); } else if ("metadata".equals(fieldName)) { Map metadata = reader.readMap(reader1 -> reader1.getString()); deserializedVectorStoreOptions.metadata = metadata; @@ -192,4 +196,35 @@ public static VectorStoreOptions fromJson(JsonReader jsonReader) throws IOExcept return deserializedVectorStoreOptions; }); } + + /* + * The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if + * file_ids is non-empty. + */ + @Generated + private VectorStoreChunkingStrategyRequest chunkingStrategy; + + /** + * Get the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. Only applicable if file_ids is non-empty. + * + * @return the chunkingStrategy value. + */ + @Generated + public VectorStoreChunkingStrategyRequest getChunkingStrategy() { + return this.chunkingStrategy; + } + + /** + * Set the chunkingStrategy property: The chunking strategy used to chunk the file(s). If not set, will use the auto + * strategy. Only applicable if file_ids is non-empty. + * + * @param chunkingStrategy the chunkingStrategy value to set. + * @return the VectorStoreOptions object itself. + */ + @Generated + public VectorStoreOptions setChunkingStrategy(VectorStoreChunkingStrategyRequest chunkingStrategy) { + this.chunkingStrategy = chunkingStrategy; + return this; + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyOptions.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyOptions.java new file mode 100644 index 000000000000..a222b1243bac --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyOptions.java @@ -0,0 +1,109 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Options to configure a vector store static chunking strategy. + */ +@Immutable +public final class VectorStoreStaticChunkingStrategyOptions + implements JsonSerializable { + + /* + * The maximum number of tokens in each chunk. The default value is 800. The minimum value is 100 and the maximum + * value is 4096. + */ + @Generated + private final int maxChunkSizeTokens; + + /* + * The number of tokens that overlap between chunks. The default value is 400. + * Note that the overlap must not exceed half of max_chunk_size_tokens. * + */ + @Generated + private final int chunkOverlapTokens; + + /** + * Creates an instance of VectorStoreStaticChunkingStrategyOptions class. + * + * @param maxChunkSizeTokens the maxChunkSizeTokens value to set. + * @param chunkOverlapTokens the chunkOverlapTokens value to set. + */ + @Generated + public VectorStoreStaticChunkingStrategyOptions(int maxChunkSizeTokens, int chunkOverlapTokens) { + this.maxChunkSizeTokens = maxChunkSizeTokens; + this.chunkOverlapTokens = chunkOverlapTokens; + } + + /** + * Get the maxChunkSizeTokens property: The maximum number of tokens in each chunk. The default value is 800. The + * minimum value is 100 and the maximum value is 4096. + * + * @return the maxChunkSizeTokens value. + */ + @Generated + public int getMaxChunkSizeTokens() { + return this.maxChunkSizeTokens; + } + + /** + * Get the chunkOverlapTokens property: The number of tokens that overlap between chunks. The default value is 400. + * Note that the overlap must not exceed half of max_chunk_size_tokens. *. + * + * @return the chunkOverlapTokens value. + */ + @Generated + public int getChunkOverlapTokens() { + return this.chunkOverlapTokens; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeIntField("max_chunk_size_tokens", this.maxChunkSizeTokens); + jsonWriter.writeIntField("chunk_overlap_tokens", this.chunkOverlapTokens); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreStaticChunkingStrategyOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreStaticChunkingStrategyOptions if the JsonReader was pointing to an instance of + * it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the VectorStoreStaticChunkingStrategyOptions. + */ + @Generated + public static VectorStoreStaticChunkingStrategyOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + int maxChunkSizeTokens = 0; + int chunkOverlapTokens = 0; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("max_chunk_size_tokens".equals(fieldName)) { + maxChunkSizeTokens = reader.getInt(); + } else if ("chunk_overlap_tokens".equals(fieldName)) { + chunkOverlapTokens = reader.getInt(); + } else { + reader.skipChildren(); + } + } + return new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens); + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyRequest.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyRequest.java new file mode 100644 index 000000000000..7a4e14cc13bc --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyRequest.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * A statically configured chunking strategy. + */ +@Immutable +public final class VectorStoreStaticChunkingStrategyRequest extends VectorStoreChunkingStrategyRequest { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyRequestType type = VectorStoreChunkingStrategyRequestType.STATIC; + + /* + * The options for the static chunking strategy. + */ + @Generated + private final VectorStoreStaticChunkingStrategyOptions staticProperty; + + /** + * Creates an instance of VectorStoreStaticChunkingStrategyRequest class. + * + * @param staticProperty the staticProperty value to set. + */ + @Generated + public VectorStoreStaticChunkingStrategyRequest(VectorStoreStaticChunkingStrategyOptions staticProperty) { + this.staticProperty = staticProperty; + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + @Override + public VectorStoreChunkingStrategyRequestType getType() { + return this.type; + } + + /** + * Get the staticProperty property: The options for the static chunking strategy. + * + * @return the staticProperty value. + */ + @Generated + public VectorStoreStaticChunkingStrategyOptions getStaticProperty() { + return this.staticProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("static", this.staticProperty); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreStaticChunkingStrategyRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreStaticChunkingStrategyRequest if the JsonReader was pointing to an instance of + * it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the VectorStoreStaticChunkingStrategyRequest. + */ + @Generated + public static VectorStoreStaticChunkingStrategyRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreStaticChunkingStrategyOptions staticProperty = null; + VectorStoreChunkingStrategyRequestType type = VectorStoreChunkingStrategyRequestType.STATIC; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("static".equals(fieldName)) { + staticProperty = VectorStoreStaticChunkingStrategyOptions.fromJson(reader); + } else if ("type".equals(fieldName)) { + type = VectorStoreChunkingStrategyRequestType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + VectorStoreStaticChunkingStrategyRequest deserializedVectorStoreStaticChunkingStrategyRequest + = new VectorStoreStaticChunkingStrategyRequest(staticProperty); + deserializedVectorStoreStaticChunkingStrategyRequest.type = type; + return deserializedVectorStoreStaticChunkingStrategyRequest; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyResponse.java b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyResponse.java new file mode 100644 index 000000000000..a1cdffa771cd --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/main/java/com/azure/ai/openai/assistants/models/VectorStoreStaticChunkingStrategyResponse.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. +package com.azure.ai.openai.assistants.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * A statically configured chunking strategy. + */ +@Immutable +public final class VectorStoreStaticChunkingStrategyResponse extends VectorStoreChunkingStrategyResponse { + + /* + * The object type. + */ + @Generated + private VectorStoreChunkingStrategyResponseType type = VectorStoreChunkingStrategyResponseType.STATIC; + + /* + * The options for the static chunking strategy. + */ + @Generated + private final VectorStoreStaticChunkingStrategyOptions staticProperty; + + /** + * Creates an instance of VectorStoreStaticChunkingStrategyResponse class. + * + * @param staticProperty the staticProperty value to set. + */ + @Generated + private VectorStoreStaticChunkingStrategyResponse(VectorStoreStaticChunkingStrategyOptions staticProperty) { + this.staticProperty = staticProperty; + } + + /** + * Get the type property: The object type. + * + * @return the type value. + */ + @Generated + @Override + public VectorStoreChunkingStrategyResponseType getType() { + return this.type; + } + + /** + * Get the staticProperty property: The options for the static chunking strategy. + * + * @return the staticProperty value. + */ + @Generated + public VectorStoreStaticChunkingStrategyOptions getStaticProperty() { + return this.staticProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("static", this.staticProperty); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VectorStoreStaticChunkingStrategyResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VectorStoreStaticChunkingStrategyResponse if the JsonReader was pointing to an instance of + * it, or null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the VectorStoreStaticChunkingStrategyResponse. + */ + @Generated + public static VectorStoreStaticChunkingStrategyResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VectorStoreStaticChunkingStrategyOptions staticProperty = null; + VectorStoreChunkingStrategyResponseType type = VectorStoreChunkingStrategyResponseType.STATIC; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("static".equals(fieldName)) { + staticProperty = VectorStoreStaticChunkingStrategyOptions.fromJson(reader); + } else if ("type".equals(fieldName)) { + type = VectorStoreChunkingStrategyResponseType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + VectorStoreStaticChunkingStrategyResponse deserializedVectorStoreStaticChunkingStrategyResponse + = new VectorStoreStaticChunkingStrategyResponse(staticProperty); + deserializedVectorStoreStaticChunkingStrategyResponse.type = type; + return deserializedVectorStoreStaticChunkingStrategyResponse; + }); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/main/resources/META-INF/azure-ai-openai-assistants_apiview_properties.json b/sdk/openai/azure-ai-openai-assistants/src/main/resources/META-INF/azure-ai-openai-assistants_apiview_properties.json index f6f87d9cbb93..c84db9f9d029 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/main/resources/META-INF/azure-ai-openai-assistants_apiview_properties.json +++ b/sdk/openai/azure-ai-openai-assistants/src/main/resources/META-INF/azure-ai-openai-assistants_apiview_properties.json @@ -202,6 +202,7 @@ "com.azure.ai.openai.assistants.models.FileDetails": "null", "com.azure.ai.openai.assistants.models.FilePurpose": "Azure.AI.OpenAI.Assistants.FilePurpose", "com.azure.ai.openai.assistants.models.FileSearchToolDefinition": "Azure.AI.OpenAI.Assistants.FileSearchToolDefinition", + "com.azure.ai.openai.assistants.models.FileSearchToolDefinitionDetails": "Azure.AI.OpenAI.Assistants.FileSearchToolDefinitionDetails", "com.azure.ai.openai.assistants.models.FileSearchToolResource": "Azure.AI.OpenAI.Assistants.FileSearchToolResource", "com.azure.ai.openai.assistants.models.FileState": "Azure.AI.OpenAI.Assistants.FileState", "com.azure.ai.openai.assistants.models.FunctionDefinition": "Azure.AI.OpenAI.Assistants.FunctionDefinition", @@ -301,6 +302,12 @@ "com.azure.ai.openai.assistants.models.UpdateFileSearchToolResourceOptions": "Azure.AI.OpenAI.Assistants.UpdateFileSearchToolResourceOptions", "com.azure.ai.openai.assistants.models.UpdateToolResourcesOptions": "Azure.AI.OpenAI.Assistants.UpdateToolResourcesOptions", "com.azure.ai.openai.assistants.models.VectorStore": "Azure.AI.OpenAI.Assistants.VectorStore", + "com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyRequest": "Azure.AI.OpenAI.Assistants.VectorStoreAutoChunkingStrategyRequest", + "com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyResponse": "Azure.AI.OpenAI.Assistants.VectorStoreAutoChunkingStrategyResponse", + "com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequest": "Azure.AI.OpenAI.Assistants.VectorStoreChunkingStrategyRequest", + "com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyRequestType": "Azure.AI.OpenAI.Assistants.VectorStoreChunkingStrategyRequestType", + "com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyResponse": "Azure.AI.OpenAI.Assistants.VectorStoreChunkingStrategyResponse", + "com.azure.ai.openai.assistants.models.VectorStoreChunkingStrategyResponseType": "Azure.AI.OpenAI.Assistants.VectorStoreChunkingStrategyResponseType", "com.azure.ai.openai.assistants.models.VectorStoreDeletionStatus": "Azure.AI.OpenAI.Assistants.VectorStoreDeletionStatus", "com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicy": "Azure.AI.OpenAI.Assistants.VectorStoreExpirationPolicy", "com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicyAnchor": "Azure.AI.OpenAI.Assistants.VectorStoreExpirationPolicyAnchor", @@ -314,6 +321,9 @@ "com.azure.ai.openai.assistants.models.VectorStoreFileStatus": "Azure.AI.OpenAI.Assistants.VectorStoreFileStatus", "com.azure.ai.openai.assistants.models.VectorStoreFileStatusFilter": "Azure.AI.OpenAI.Assistants.VectorStoreFileStatusFilter", "com.azure.ai.openai.assistants.models.VectorStoreOptions": "Azure.AI.OpenAI.Assistants.VectorStoreOptions", + "com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions": "Azure.AI.OpenAI.Assistants.VectorStoreStaticChunkingStrategyOptions", + "com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyRequest": "Azure.AI.OpenAI.Assistants.VectorStoreStaticChunkingStrategyRequest", + "com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyResponse": "Azure.AI.OpenAI.Assistants.VectorStoreStaticChunkingStrategyResponse", "com.azure.ai.openai.assistants.models.VectorStoreStatus": "Azure.AI.OpenAI.Assistants.VectorStoreStatus", "com.azure.ai.openai.assistants.models.VectorStoreUpdateOptions": "Azure.AI.OpenAI.Assistants.VectorStoreUpdateOptions" } diff --git a/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/FileSearchToolSample.java b/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/FileSearchToolSample.java index fa327e745afb..8560a9c6679d 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/FileSearchToolSample.java +++ b/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/FileSearchToolSample.java @@ -63,7 +63,8 @@ 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())))))); // Create assistant passing the file ID Assistant assistant = client.createAssistant( diff --git a/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/ReadmeSamples.java b/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/ReadmeSamples.java index 9140b9d01ee1..202e1e26195a 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/ReadmeSamples.java +++ b/sdk/openai/azure-ai-openai-assistants/src/samples/java/com/azure/ai/openai/assistants/ReadmeSamples.java @@ -183,7 +183,8 @@ 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())))))); Assistant assistant = client.createAssistant( new AssistantCreationOptions(deploymentOrModelId) diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AssistantsClientTestBase.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AssistantsClientTestBase.java index 65b6f371b404..99600264e206 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AssistantsClientTestBase.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AssistantsClientTestBase.java @@ -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; @@ -214,18 +213,6 @@ void createRunRunner(Consumer testRunner, String assistantId) testRunner.accept(new CreateRunOptions(assistantId)); } - void createRetrievalRunner(BiConsumer 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 testRunner) { FunctionsToolCallHelper functionsToolCallHelper = new FunctionsToolCallHelper(); List toolDefinition = Arrays.asList( diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchAsyncTest.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchAsyncTest.java index dc5ca7c7223c..7e516b15b089 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchAsyncTest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchAsyncTest.java @@ -3,6 +3,7 @@ package com.azure.ai.openai.assistants; +import com.azure.ai.openai.assistants.implementation.AsyncUtils; import com.azure.ai.openai.assistants.models.Assistant; import com.azure.ai.openai.assistants.models.AssistantThread; import com.azure.ai.openai.assistants.models.AssistantThreadCreationOptions; @@ -18,9 +19,8 @@ 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.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; import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; @@ -32,20 +32,104 @@ 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; - @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 basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { client = getAssistantsAsyncClient(httpClient, serviceVersion); - createRetrievalRunner((fileDetails, assistantCreationOptions) -> { + fileSearchRunner((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())))))); + assistantCreationOptions.setToolResources(createToolResourcesOptions); + cleanUp.setFile(openAIFile); + return client.createAssistant(assistantCreationOptions).zipWith(Mono.just(cleanUp)); + }).flatMap(tuple -> { + Assistant assistant = tuple.getT1(); + AsyncUtils cleanUp = tuple.getT2(); + cleanUp.setAssistant(assistant); + + return client.createThread(new AssistantThreadCreationOptions()) + .zipWith(Mono.just(cleanUp)); + }).flatMap(tuple -> { + AssistantThread thread = tuple.getT1(); + AsyncUtils cleanUp = tuple.getT2(); + cleanUp.setThread(thread); + + return client.createMessage( + thread.getId(), + new ThreadMessageOptions( + MessageRole.USER, + "Can you give me the documented codes for 'banana' and 'orange'?" + )).flatMap(_message -> + client.createRun(cleanUp.getThread(), cleanUp.getAssistant()) + .flatMap(createdRun -> + client.getRun(cleanUp.getThread().getId(), createdRun.getId()).zipWith(Mono.just(cleanUp)) + .repeatWhen(completed -> completed.delayElements(Duration.ofMillis(1000))) + .takeUntil(tuple2 -> { + ThreadRun run = tuple2.getT1(); + + return run.getStatus() != RunStatus.IN_PROGRESS + && run.getStatus() != RunStatus.QUEUED; + }) + .last() + ) + ); + }).flatMap(tuple -> { + ThreadRun run = tuple.getT1(); + AsyncUtils cleanUp = tuple.getT2(); + + assertEquals(RunStatus.COMPLETED, run.getStatus()); + assertEquals(cleanUp.getAssistant().getId(), run.getAssistantId()); + + return client.listMessages(cleanUp.getThread().getId()).zipWith(Mono.just(cleanUp)); + }).map(tuple -> { + PageableList messageList = tuple.getT1(); + AsyncUtils cleanUp = tuple.getT2(); + + assertEquals(2, messageList.getData().size()); + ThreadMessage firstMessage = messageList.getData().get(0); + + assertEquals(MessageRole.ASSISTANT, firstMessage.getRole()); + assertFalse(firstMessage.getContent().isEmpty()); + + MessageTextContent firstMessageContent = (MessageTextContent) firstMessage.getContent().get(0); + assertNotNull(firstMessageContent); + assertTrue(firstMessageContent.getText().getValue().contains("232323")); + + return cleanUp; + }) + .flatMap(cleanUp -> client.deleteAssistant(cleanUp.getAssistant().getId()) + .flatMap(_unused -> client.deleteFile(cleanUp.getFile().getId())) + .flatMap(_unused -> client.deleteThread(cleanUp.getThread().getId())))) + // last deletion asserted + .assertNext(threadDeletionStatus -> assertTrue(threadDeletionStatus.isDeleted())) + .verifyComplete(); + }); + } + + @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 -> { @@ -55,71 +139,15 @@ 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())))))); assistantCreationOptions.setToolResources(createToolResourcesOptions); - cleanUp.setFile(openAIFile); - return client.createAssistant(assistantCreationOptions).zipWith(Mono.just(cleanUp)); - }).flatMap(tuple -> { - Assistant assistant = tuple.getT1(); - AsyncUtils cleanUp = tuple.getT2(); - cleanUp.setAssistant(assistant); - return client.createThread(new AssistantThreadCreationOptions()) + cleanUp.setFile(openAIFile); + return client.createAssistant(assistantCreationOptions) .zipWith(Mono.just(cleanUp)); - }).flatMap(tuple -> { - AssistantThread thread = tuple.getT1(); - AsyncUtils cleanUp = tuple.getT2(); - cleanUp.setThread(thread); - - return client.createMessage( - thread.getId(), - new ThreadMessageOptions( - MessageRole.USER, - "Can you give me the documented codes for 'banana' and 'orange'?" - )).flatMap(_message -> - client.createRun(cleanUp.getThread(), cleanUp.getAssistant()) - .flatMap(createdRun -> - client.getRun(cleanUp.getThread().getId(), createdRun.getId()).zipWith(Mono.just(cleanUp)) - .repeatWhen(completed -> completed.delayElements(Duration.ofMillis(1000))) - .takeUntil(tuple2 -> { - ThreadRun run = tuple2.getT1(); - - return run.getStatus() != RunStatus.IN_PROGRESS - && run.getStatus() != RunStatus.QUEUED; - }) - .last() - ) - ); - }).flatMap(tuple -> { - ThreadRun run = tuple.getT1(); - AsyncUtils cleanUp = tuple.getT2(); - - assertEquals(RunStatus.COMPLETED, run.getStatus()); - assertEquals(cleanUp.getAssistant().getId(), run.getAssistantId()); - - return client.listMessages(cleanUp.getThread().getId()).zipWith(Mono.just(cleanUp)); - }).map(tuple -> { - PageableList messageList = tuple.getT1(); - AsyncUtils cleanUp = tuple.getT2(); - - assertEquals(2, messageList.getData().size()); - ThreadMessage firstMessage = messageList.getData().get(0); - - assertEquals(MessageRole.ASSISTANT, firstMessage.getRole()); - assertFalse(firstMessage.getContent().isEmpty()); - - MessageTextContent firstMessageContent = (MessageTextContent) firstMessage.getContent().get(0); - assertNotNull(firstMessageContent); - assertTrue(firstMessageContent.getText().getValue().contains("232323")); - - return cleanUp; }) - .flatMap(cleanUp -> client.deleteAssistant(cleanUp.getAssistant().getId()) - .flatMap(_unused -> client.deleteFile(cleanUp.getFile().getId())) - .flatMap(_unused -> client.deleteThread(cleanUp.getThread().getId())))) - // last deletion asserted - .assertNext(threadDeletionStatus -> assertTrue(threadDeletionStatus.isDeleted())) - .verifyComplete(); + ).verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); }); } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchSyncTest.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchSyncTest.java index 3b3d10e4a0ee..ca08129690c4 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchSyncTest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureFileSearchSyncTest.java @@ -19,8 +19,8 @@ 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; import org.junit.jupiter.params.provider.MethodSource; @@ -30,19 +30,19 @@ 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) -> { + fileSearchRunner((fileDetails, assistantCreationOptions) -> { // Upload file for assistant OpenAIFile openAIFile = client.uploadFile(fileDetails, FilePurpose.ASSISTANTS); @@ -51,7 +51,8 @@ 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())))))); assistantCreationOptions.setToolResources(createToolResourcesOptions); Assistant assistant = client.createAssistant(assistantCreationOptions); @@ -97,5 +98,32 @@ public void basicRetrieval(HttpClient httpClient, AssistantsServiceVersion servi }); } + @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())))))); + assistantCreationOptions.setToolResources(createToolResourcesOptions); + + assertThrows(HttpResponseException.class, () -> { + Assistant assistant = client.createAssistant(assistantCreationOptions); + client.deleteAssistant(assistant.getId()); + }); + // cleanup + client.deleteFile(openAIFile.getId()); + }); + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureStreamingSyncTest.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureStreamingSyncTest.java index e6d6e2b2d0a1..40d9cc30cb3e 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureStreamingSyncTest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureStreamingSyncTest.java @@ -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) { diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreAsyncTests.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreAsyncTests.java index c886ea4cc1a6..3c4cad887fbf 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreAsyncTests.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreAsyncTests.java @@ -4,10 +4,15 @@ package com.azure.ai.openai.assistants; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyRequest; +import com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicy; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; import com.azure.ai.openai.assistants.models.VectorStoreFileBatchStatus; import com.azure.ai.openai.assistants.models.VectorStoreOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyRequest; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; import com.azure.core.util.logging.ClientLogger; import org.junit.jupiter.api.Disabled; @@ -21,31 +26,37 @@ import static com.azure.ai.openai.assistants.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS; import static com.azure.ai.openai.assistants.models.FilePurpose.ASSISTANTS; +import static com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicyAnchor.LAST_ACTIVE_AT; 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 AzureVectorStoreAsyncTests extends AssistantsClientTestBase { +public class AzureVectorStoreAsyncTests extends VectorStoreTestBase { private static final ClientLogger LOGGER = new ClientLogger(AzureVectorStoreAsyncTests.class); private AssistantsAsyncClient client; private VectorStore vectorStore; private List fileIds = new ArrayList<>(); + protected void beforeTest(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { client = getAssistantsAsyncClient(httpClient, serviceVersion); - fileIds.add(uploadFileAsync(client, "20210203_alphabet_10K.pdf", ASSISTANTS)); + addFile(ALPHABET_FINANCIAL_STATEMENT); VectorStoreOptions vectorStoreOptions = new VectorStoreOptions() - .setName("Financial Statements") - .setFileIds(fileIds); - + .setName("Financial Statements") + .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)); StepVerifier.create(client.createVectorStore(vectorStoreOptions)) - .assertNext(vectorStore -> { - this.vectorStore = vectorStore; - assertNotNull(vectorStore); - assertNotNull(vectorStore.getId()); - }) - .verifyComplete(); + .assertNext(vectorStore -> { + this.vectorStore = vectorStore; + assertNotNull(vectorStore); + assertNotNull(vectorStore.getId()); + }) + .verifyComplete(); + } + + private void addFile(String fileId) { + fileIds.add(uploadFileAsync(client, fileId, ASSISTANTS)); } @Override @@ -110,13 +121,52 @@ public void listVectorStore(HttpClient httpClient, AssistantsServiceVersion serv @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient, serviceVersion); - String storeId = vectorStore.getId(); - StepVerifier.create(client.createVectorStoreFile(storeId, fileIds.get(0))) - .assertNext(vectorStoreFile -> { - assertNotNull(vectorStoreFile); - assertNotNull(vectorStoreFile.getId()); - }) - .verifyComplete(); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0))) + .assertNext(this::assertVectorStoreFile) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(vectorStoreFile -> { + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, 800, 400); + }) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + int maxChunkSizeTokens = 101; + int chunkOverlapTokens = 50; + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens)))) + .assertNext(vectorStoreFile -> { + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, maxChunkSizeTokens, chunkOverlapTokens); + }) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(this::assertVectorStoreFile) + .verifyComplete(); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @@ -169,13 +219,17 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio beforeTest(httpClient, serviceVersion); String storeId = vectorStore.getId(); String fileId = fileIds.get(0); + // Create Vector Store File + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0))) + .assertNext(this::assertVectorStoreFile) + .verifyComplete(); // Delete Vector Store File StepVerifier.create(client.deleteVectorStoreFile(storeId, fileId)) - .assertNext(deletionStatus -> { - assertTrue(deletionStatus.isDeleted()); - assertEquals(fileId, deletionStatus.getId()); - }) - .verifyComplete(); + .assertNext(deletionStatus -> { + assertTrue(deletionStatus.isDeleted()); + assertEquals(fileId, deletionStatus.getId()); + }) + .verifyComplete(); } // Vector Store File Batch @@ -183,18 +237,55 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient, serviceVersion); - String storeId = vectorStore.getId(); - String fileId = fileIds.get(0); - String fileId2 = uploadFileAsync(client, "20220924_aapl_10k.pdf", ASSISTANTS); - fileIds.add(fileId2); + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + } - StepVerifier.create(client.createVectorStoreFileBatch(storeId, Arrays.asList(fileId, fileId2))) - .assertNext(vectorStoreFileBatch -> { - assertNotNull(vectorStoreFileBatch); - assertNotNull(vectorStoreFileBatch.getId()); - assertEquals(2, vectorStoreFileBatch.getFileCounts().getTotal()); - }) - .verifyComplete(); + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategyInBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest())) + .verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreSyncTests.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreSyncTests.java index b104b3b3f9f5..f370b1a88049 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreSyncTests.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/AzureVectorStoreSyncTests.java @@ -5,12 +5,17 @@ import com.azure.ai.openai.assistants.models.PageableList; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyRequest; +import com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicy; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; import com.azure.ai.openai.assistants.models.VectorStoreFileBatchStatus; import com.azure.ai.openai.assistants.models.VectorStoreFileDeletionStatus; import com.azure.ai.openai.assistants.models.VectorStoreFileStatus; import com.azure.ai.openai.assistants.models.VectorStoreOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyRequest; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; import com.azure.core.util.logging.ClientLogger; import org.junit.jupiter.api.Disabled; @@ -23,12 +28,14 @@ import static com.azure.ai.openai.assistants.TestUtils.DISPLAY_NAME_WITH_ARGUMENTS; import static com.azure.ai.openai.assistants.models.FilePurpose.ASSISTANTS; +import static com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicyAnchor.LAST_ACTIVE_AT; 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 AzureVectorStoreSyncTests extends AssistantsClientTestBase { +public class AzureVectorStoreSyncTests extends VectorStoreTestBase { private static final ClientLogger LOGGER = new ClientLogger(AzureVectorStoreSyncTests.class); private AssistantsClient client; @@ -37,16 +44,19 @@ public class AzureVectorStoreSyncTests extends AssistantsClientTestBase { protected void beforeTest(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { client = getAssistantsClient(httpClient, serviceVersion); - fileIds.add(uploadFile(client, "20210203_alphabet_10K.pdf", ASSISTANTS)); + addFile(ALPHABET_FINANCIAL_STATEMENT); VectorStoreOptions vectorStoreOptions = new VectorStoreOptions() - .setName("Financial Statements") - .setFileIds(fileIds); + .setName("Financial Statements") + .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)); vectorStore = client.createVectorStore(vectorStoreOptions); - assertNotNull(vectorStore); assertNotNull(vectorStore.getId()); } + private void addFile(String fileId) { + fileIds.add(uploadFile(client, fileId, ASSISTANTS)); + } + @Override protected void afterTest() { LOGGER.info("Cleaning up created resources."); @@ -102,11 +112,48 @@ public void listVectorStore(HttpClient httpClient, AssistantsServiceVersion serv @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient, serviceVersion); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0)); + assertVectorStoreFile(vectorStoreFile); + } - String storeId = vectorStore.getId(); - VectorStoreFile vectorStoreFile = client.createVectorStoreFile(storeId, fileIds.get(0)); - assertNotNull(vectorStoreFile); - assertNotNull(vectorStoreFile.getId()); + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest()); + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, 800, 400); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + int maxChunkSizeTokens = 101; + int chunkOverlapTokens = 50; + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens)) + ); + + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, maxChunkSizeTokens, chunkOverlapTokens); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest()); + + assertVectorStoreFile(vectorStoreFile); + + assertThrows(HttpResponseException.class, () -> client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)) + )); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @@ -156,10 +203,11 @@ public void listVectorStoreFiles(HttpClient httpClient, AssistantsServiceVersion @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient, serviceVersion); - String storeId = vectorStore.getId(); String fileId = fileIds.get(0); - + // Create Vector Store File + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(storeId, fileId); + assertVectorStoreFile(vectorStoreFile); // Delete Vector Store File VectorStoreFileDeletionStatus deletionStatus = client.deleteVectorStoreFile(storeId, fileId); assertTrue(deletionStatus.isDeleted()); @@ -171,15 +219,52 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1))); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest()); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50))); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategyInBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient, serviceVersion); + addFile(APPLE_FINANCIAL_STATEMENT); + + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50))); - String storeId = vectorStore.getId(); - String fileId = fileIds.get(0); - String fileId2 = uploadFile(client, "20220924_aapl_10k.pdf", ASSISTANTS); - fileIds.add(fileId2); - VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(storeId, Arrays.asList(fileId, fileId2)); assertNotNull(vectorStoreFileBatch); - assertNotNull(vectorStoreFileBatch.getId()); - assertEquals(2, vectorStoreFileBatch.getFileCounts().getTotal()); + + assertThrows(HttpResponseException.class, () -> client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest() + )); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchAsyncTest.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchAsyncTest.java index 176961001b62..82a46bc01a80 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchAsyncTest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchAsyncTest.java @@ -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.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -31,10 +32,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 FileSearchAsyncTest extends AssistantsClientTestBase { +public class FileSearchAsyncTest extends FileSearchTestBase { AssistantsAsyncClient client; @@ -43,7 +45,7 @@ public class FileSearchAsyncTest extends AssistantsClientTestBase { public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { client = getAssistantsAsyncClient(httpClient); - createRetrievalRunner((fileDetails, assistantCreationOptions) -> { + fileSearchRunner((fileDetails, assistantCreationOptions) -> { // Upload file StepVerifier.create(client.uploadFile(fileDetails, FilePurpose.ASSISTANTS) .flatMap(openAIFile -> { @@ -53,7 +55,8 @@ 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())))))); assistantCreationOptions.setToolResources(createToolResourcesOptions); cleanUp.setFile(openAIFile); return client.createAssistant(assistantCreationOptions).zipWith(Mono.just(cleanUp)); @@ -120,4 +123,31 @@ public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serv .verifyComplete(); }); } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void fileSearchWithMaxNumberResult(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + client = getAssistantsAsyncClient(httpClient); + + 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())))))); + assistantCreationOptions.setToolResources(createToolResourcesOptions); + + cleanUp.setFile(openAIFile); + return client.createAssistant(assistantCreationOptions) + .zipWith(Mono.just(cleanUp)); + }) + ).verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); + }); + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchSyncTest.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchSyncTest.java index 3af04468b770..7d9acc1cb310 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchSyncTest.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchSyncTest.java @@ -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.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -29,9 +30,10 @@ 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 FileSearchSyncTest extends AssistantsClientTestBase { +public class FileSearchSyncTest extends FileSearchTestBase { AssistantsClient client; @@ -40,7 +42,7 @@ public class FileSearchSyncTest extends AssistantsClientTestBase { public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { client = getAssistantsClient(httpClient); - createRetrievalRunner((fileDetails, assistantCreationOptions) -> { + fileSearchRunner((fileDetails, assistantCreationOptions) -> { // Upload file for assistant OpenAIFile openAIFile = client.uploadFile(fileDetails, FilePurpose.ASSISTANTS); @@ -49,7 +51,8 @@ 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())))))); assistantCreationOptions.setToolResources(createToolResourcesOptions); Assistant assistant = client.createAssistant(assistantCreationOptions); @@ -95,5 +98,32 @@ public void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serv }); } + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void fileSearchWithMaxNumberResult(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + client = getAssistantsClient(httpClient); + + 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())))))); + assistantCreationOptions.setToolResources(createToolResourcesOptions); + + assertThrows(HttpResponseException.class, () -> { + Assistant assistant = client.createAssistant(assistantCreationOptions); + client.deleteAssistant(assistant.getId()); + }); + // cleanup + client.deleteFile(openAIFile.getId()); + }); + } } diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchTestBase.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchTestBase.java new file mode 100644 index 000000000000..effa720358bc --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/FileSearchTestBase.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.openai.assistants; + +import com.azure.ai.openai.assistants.models.AssistantCreationOptions; +import com.azure.ai.openai.assistants.models.FileDetails; +import com.azure.ai.openai.assistants.models.FileSearchToolDefinition; +import com.azure.ai.openai.assistants.models.FileSearchToolDefinitionDetails; +import com.azure.core.http.HttpClient; +import com.azure.core.util.BinaryData; + +import java.util.Arrays; +import java.util.function.BiConsumer; + +public abstract class FileSearchTestBase extends AssistantsClientTestBase { + private static final String JAVA_SDK_TESTS_ASSISTANTS_TXT = "java_sdk_tests_assistants.txt"; + private static final String GPT_4_TURBO = "gpt-4-turbo"; + + public abstract void basicFileSearch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void fileSearchWithMaxNumberResult(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + + void fileSearchRunner(BiConsumer testRunner) { + FileDetails fileDetails = new FileDetails( + BinaryData.fromFile(openResourceFile(JAVA_SDK_TESTS_ASSISTANTS_TXT)), + JAVA_SDK_TESTS_ASSISTANTS_TXT); + + AssistantCreationOptions assistantOptions = new AssistantCreationOptions(GPT_4_TURBO) + .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 fileSearchWithMaxNumberResultRunner(BiConsumer 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().setFileSearch( + new FileSearchToolDefinitionDetails().setMaxNumResults(0) + ))); + + testRunner.accept(fileDetails, assistantOptions); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreAsyncTests.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreAsyncTests.java index 24b5e2db774d..da30cb00ee24 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreAsyncTests.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreAsyncTests.java @@ -4,10 +4,14 @@ package com.azure.ai.openai.assistants; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyRequest; import com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicy; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; import com.azure.ai.openai.assistants.models.VectorStoreOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyRequest; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; import com.azure.core.util.logging.ClientLogger; import org.junit.jupiter.params.ParameterizedTest; @@ -23,10 +27,11 @@ import static com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicyAnchor.LAST_ACTIVE_AT; 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 VectorStoreAsyncTests extends AssistantsClientTestBase { +public class VectorStoreAsyncTests extends VectorStoreTestBase { private static final ClientLogger LOGGER = new ClientLogger(VectorStoreSyncTests.class); private AssistantsAsyncClient client; @@ -34,12 +39,10 @@ public class VectorStoreAsyncTests extends AssistantsClientTestBase { private List fileIds = new ArrayList<>(); protected void beforeTest(HttpClient httpClient) { client = getAssistantsAsyncClient(httpClient); - fileIds.add(uploadFileAsync(client, "20210203_alphabet_10K.pdf", ASSISTANTS)); + addFile(ALPHABET_FINANCIAL_STATEMENT); VectorStoreOptions vectorStoreOptions = new VectorStoreOptions() .setName("Financial Statements") - .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)) - .setFileIds(fileIds); - + .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)); StepVerifier.create(client.createVectorStore(vectorStoreOptions)) .assertNext(vectorStore -> { this.vectorStore = vectorStore; @@ -49,6 +52,10 @@ protected void beforeTest(HttpClient httpClient) { .verifyComplete(); } + private void addFile(String fileId) { + fileIds.add(uploadFileAsync(client, fileId, ASSISTANTS)); + } + @Override protected void afterTest() { LOGGER.info("Cleaning up created resources."); @@ -111,15 +118,54 @@ public void listVectorStore(HttpClient httpClient, AssistantsServiceVersion serv @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient); - String storeId = vectorStore.getId(); - StepVerifier.create(client.createVectorStoreFile(storeId, fileIds.get(0))) - .assertNext(vectorStoreFile -> { - assertNotNull(vectorStoreFile); - assertNotNull(vectorStoreFile.getId()); - }) + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0))) + .assertNext(this::assertVectorStoreFile) .verifyComplete(); } + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(vectorStoreFile -> { + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, 800, 400); + }) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + int maxChunkSizeTokens = 101; + int chunkOverlapTokens = 50; + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens)))) + .assertNext(vectorStoreFile -> { + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, maxChunkSizeTokens, chunkOverlapTokens); + }) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(this::assertVectorStoreFile) + .verifyComplete(); + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); + } + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void getVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { @@ -170,6 +216,10 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio beforeTest(httpClient); String storeId = vectorStore.getId(); String fileId = fileIds.get(0); + // Create Vector Store File + StepVerifier.create(client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0))) + .assertNext(this::assertVectorStoreFile) + .verifyComplete(); // Delete Vector Store File StepVerifier.create(client.deleteVectorStoreFile(storeId, fileId)) .assertNext(deletionStatus -> { @@ -184,20 +234,57 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient); - String storeId = vectorStore.getId(); - String fileId = fileIds.get(0); - String fileId2 = uploadFileAsync(client, "20220924_aapl_10k.pdf", ASSISTANTS); - fileIds.add(fileId2); - - StepVerifier.create(client.createVectorStoreFileBatch(storeId, Arrays.asList(fileId, fileId2))) - .assertNext(vectorStoreFileBatch -> { - assertNotNull(vectorStoreFileBatch); - assertNotNull(vectorStoreFileBatch.getId()); - assertEquals(2, vectorStoreFileBatch.getFileCounts().getTotal()); - }) + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) .verifyComplete(); } + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest())) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategyInBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)))) + .assertNext(vectorStoreFileBatch -> assertVectorStoreFileBatch(vectorStoreFileBatch, 2)) + .verifyComplete(); + + StepVerifier.create(client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest())) + .verifyErrorSatisfies(error -> assertInstanceOf(HttpResponseException.class, error)); + } + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void getVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreSyncTests.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreSyncTests.java index 53509a3e1b66..2cc3792b8956 100644 --- a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreSyncTests.java +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreSyncTests.java @@ -5,6 +5,7 @@ import com.azure.ai.openai.assistants.models.PageableList; import com.azure.ai.openai.assistants.models.VectorStore; +import com.azure.ai.openai.assistants.models.VectorStoreAutoChunkingStrategyRequest; import com.azure.ai.openai.assistants.models.VectorStoreExpirationPolicy; import com.azure.ai.openai.assistants.models.VectorStoreFile; import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; @@ -12,6 +13,9 @@ import com.azure.ai.openai.assistants.models.VectorStoreFileDeletionStatus; import com.azure.ai.openai.assistants.models.VectorStoreFileStatus; import com.azure.ai.openai.assistants.models.VectorStoreOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyRequest; +import com.azure.core.exception.HttpResponseException; import com.azure.core.http.HttpClient; import com.azure.core.util.logging.ClientLogger; import org.junit.jupiter.params.ParameterizedTest; @@ -27,9 +31,10 @@ 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 VectorStoreSyncTests extends AssistantsClientTestBase { +public class VectorStoreSyncTests extends VectorStoreTestBase { private static final ClientLogger LOGGER = new ClientLogger(VectorStoreSyncTests.class); private AssistantsClient client; @@ -38,17 +43,19 @@ public class VectorStoreSyncTests extends AssistantsClientTestBase { protected void beforeTest(HttpClient httpClient) { client = getAssistantsClient(httpClient); - fileIds.add(uploadFile(client, "20210203_alphabet_10K.pdf", ASSISTANTS)); + addFile(ALPHABET_FINANCIAL_STATEMENT); VectorStoreOptions vectorStoreOptions = new VectorStoreOptions() .setName("Financial Statements") - .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)) - .setFileIds(fileIds); + .setExpiresAfter(new VectorStoreExpirationPolicy(LAST_ACTIVE_AT, 1)); vectorStore = client.createVectorStore(vectorStoreOptions); - assertNotNull(vectorStore); assertNotNull(vectorStore.getId()); } + private void addFile(String fileId) { + fileIds.add(uploadFile(client, fileId, ASSISTANTS)); + } + @Override protected void afterTest() { LOGGER.info("Cleaning up created resources."); @@ -102,10 +109,48 @@ public void listVectorStore(HttpClient httpClient, AssistantsServiceVersion serv @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient); - String storeId = vectorStore.getId(); - VectorStoreFile vectorStoreFile = client.createVectorStoreFile(storeId, fileIds.get(0)); - assertNotNull(vectorStoreFile); - assertNotNull(vectorStoreFile.getId()); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0)); + assertVectorStoreFile(vectorStoreFile); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest()); + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, 800, 400); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + int maxChunkSizeTokens = 101; + int chunkOverlapTokens = 50; + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(maxChunkSizeTokens, chunkOverlapTokens)) + ); + + assertVectorStoreFile(vectorStoreFile); + assertStaticChunkingStrategy(vectorStoreFile, maxChunkSizeTokens, chunkOverlapTokens); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreAutoChunkingStrategyRequest()); + + assertVectorStoreFile(vectorStoreFile); + + assertThrows(HttpResponseException.class, () -> client.createVectorStoreFile(vectorStore.getId(), fileIds.get(0), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50)) + )); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) @@ -156,7 +201,9 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio beforeTest(httpClient); String storeId = vectorStore.getId(); String fileId = fileIds.get(0); - + // Create Vector Store File + VectorStoreFile vectorStoreFile = client.createVectorStoreFile(storeId, fileId); + assertVectorStoreFile(vectorStoreFile); // Delete Vector Store File VectorStoreFileDeletionStatus deletionStatus = client.deleteVectorStoreFile(storeId, fileId); assertTrue(deletionStatus.isDeleted()); @@ -168,14 +215,52 @@ public void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersio @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") public void createVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { beforeTest(httpClient); - String storeId = vectorStore.getId(); - String fileId = fileIds.get(0); - String fileId2 = uploadFile(client, "20220924_aapl_10k.pdf", ASSISTANTS); - fileIds.add(fileId2); - VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(storeId, Arrays.asList(fileId, fileId2)); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1))); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest()); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void createVectorStoreFileBatchWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50))); + assertVectorStoreFileBatch(vectorStoreFileBatch, 2); + } + + @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) + @MethodSource("com.azure.ai.openai.assistants.TestUtils#getTestParameters") + public void throwExceptionWhenOverrideExistChunkStrategyInBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion) { + beforeTest(httpClient); + addFile(APPLE_FINANCIAL_STATEMENT); + + VectorStoreFileBatch vectorStoreFileBatch = client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreStaticChunkingStrategyRequest( + new VectorStoreStaticChunkingStrategyOptions(101, 50))); + assertNotNull(vectorStoreFileBatch); - assertNotNull(vectorStoreFileBatch.getId()); - assertEquals(2, vectorStoreFileBatch.getFileCounts().getTotal()); + + assertThrows(HttpResponseException.class, () -> client.createVectorStoreFileBatch(vectorStore.getId(), + Arrays.asList(fileIds.get(0), fileIds.get(1)), + new VectorStoreAutoChunkingStrategyRequest() + )); } @ParameterizedTest(name = DISPLAY_NAME_WITH_ARGUMENTS) diff --git a/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreTestBase.java b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreTestBase.java new file mode 100644 index 000000000000..85a8e953f2f1 --- /dev/null +++ b/sdk/openai/azure-ai-openai-assistants/src/test/java/com/azure/ai/openai/assistants/VectorStoreTestBase.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.ai.openai.assistants; + +import com.azure.ai.openai.assistants.models.VectorStoreFile; +import com.azure.ai.openai.assistants.models.VectorStoreFileBatch; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyOptions; +import com.azure.ai.openai.assistants.models.VectorStoreStaticChunkingStrategyResponse; +import com.azure.core.http.HttpClient; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public abstract class VectorStoreTestBase extends AssistantsClientTestBase { + static final String APPLE_FINANCIAL_STATEMENT = "20220924_aapl_10k.pdf"; + static final String ALPHABET_FINANCIAL_STATEMENT = "20210203_alphabet_10K.pdf"; + + public abstract void updateVectorStoreName(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void getVectorStore(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void listVectorStore(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFileWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFileWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void throwExceptionWhenOverrideExistChunkStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void getVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void listVectorStoreFiles(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void deleteVectorStoreFile(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFileBatchWithAutoChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void createVectorStoreFileBatchWithStaticChunkingStrategy(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void throwExceptionWhenOverrideExistChunkStrategyInBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void getVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void listVectorStoreFilesBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + public abstract void cancelVectorStoreFileBatch(HttpClient httpClient, AssistantsServiceVersion serviceVersion); + + + void assertVectorStoreFile(VectorStoreFile vectorStoreFile) { + assertNotNull(vectorStoreFile); + assertNotNull(vectorStoreFile.getId()); + } + + void assertVectorStoreFileBatch(VectorStoreFileBatch vectorStoreFileBatch, int fileCounts) { + assertNotNull(vectorStoreFileBatch); + assertNotNull(vectorStoreFileBatch.getId()); + assertEquals(fileCounts, vectorStoreFileBatch.getFileCounts().getTotal()); + } + + void assertStaticChunkingStrategy(VectorStoreFile vectorStoreFile, int maxChunkSizeTokens, int chunkOverlapTokens) { + VectorStoreStaticChunkingStrategyResponse chunkingStrategy = (VectorStoreStaticChunkingStrategyResponse) + vectorStoreFile.getChunkingStrategy(); + VectorStoreStaticChunkingStrategyOptions staticProperty = chunkingStrategy.getStaticProperty(); + assertNotNull(staticProperty); + assertEquals(maxChunkSizeTokens, staticProperty.getMaxChunkSizeTokens()); + assertEquals(chunkOverlapTokens, staticProperty.getChunkOverlapTokens()); + } +} diff --git a/sdk/openai/azure-ai-openai-assistants/tsp-location.yaml b/sdk/openai/azure-ai-openai-assistants/tsp-location.yaml index 1bd9d1e99302..c6f8abad0641 100644 --- a/sdk/openai/azure-ai-openai-assistants/tsp-location.yaml +++ b/sdk/openai/azure-ai-openai-assistants/tsp-location.yaml @@ -1,3 +1,3 @@ directory: specification/ai/OpenAI.Assistants -commit: 46de0ae3b0fef1f322b5a14b2fa5b6a65da435a2 +commit: cd41ba31a6af51dae34b0a5930eeb2e77a04b481 repo: Azure/azure-rest-api-specs