Skip to content

Commit

Permalink
[OpenAI][Assistants] Introducing changes for v2025-01-01-preview (#44231
Browse files Browse the repository at this point in the history
)

* Code gen for newest service release

* Removed tests for removed variant of API format

* Tests are re-recorded

* Updated changelog for release

* Added tests for JSON_SCHEMA

* Added changelog and overloads for methods

* reran regen

* Reformat

* Commit hash from main
  • Loading branch information
jpalvarezl authored Feb 20, 2025
1 parent ddcc0a7 commit 2186a4c
Show file tree
Hide file tree
Showing 26 changed files with 1,439 additions and 215 deletions.
8 changes: 8 additions & 0 deletions sdk/openai/azure-ai-openai-assistants/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

### Features Added

- Added `include[]` query parameter for `getRunStep` methods to specify additional fields for the request. Currently only files are supported.
- Results added to run step details file search tool calls instances
- Added more `VectorStoreFileErrorCode`s. Specifically, `server_error`, `unsupported_file` and `invalid_file`.
- Added `AssistantsApiResponseFormatJsonSchema` as a possible value (previously, `text` and `json_object` where the only supported ones).
- Added Azure OpenAI services labels: `V2024_09_01_PREVIEW`, `V2024_10_01_PREVIEW`, `V2025_01_01_PREVIEW`.

### Breaking Changes

- Removed `AssistantsApiResponseFormatMode.NONE`.

### Bugs Fixed

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/openai/azure-ai-openai-assistants/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo" : "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath" : "java",
"TagPrefix" : "java/assistants/azure-ai-openai-assistants",
"Tag" : "java/assistants/azure-ai-openai-assistants_19cb2164a3"
"Tag" : "java/assistants/azure-ai-openai-assistants_f834cc9de4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.azure.ai.openai.assistants.models.ListSortOrder;
import com.azure.ai.openai.assistants.models.OpenAIFile;
import com.azure.ai.openai.assistants.models.PageableList;
import com.azure.ai.openai.assistants.models.RunIncludes;
import com.azure.ai.openai.assistants.models.RunStep;
import com.azure.ai.openai.assistants.models.StreamUpdate;
import com.azure.ai.openai.assistants.models.ThreadDeletionStatus;
Expand Down Expand Up @@ -70,6 +71,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -1893,6 +1895,33 @@ public Mono<PageableList<RunStep>> listRunSteps(String threadId, String runId, I
assistantList.getLastId(), assistantList.isHasMore()));
}

/**
* Gets a list of run steps from a thread run with additional included fields.
*
* @param threadId The ID of the thread that was run.
* @param runId The ID of the run to list steps from.
* @param runInclude A list of additional fields to include in the response.
* @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 list of run steps from a thread run on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<PageableList<RunStep>> listRunSteps(String threadId, String runId, List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(item -> Objects.toString(item, "")).collect(Collectors.joining(",")), false);
}
return listRunStepsWithResponse(threadId, runId, requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(OpenAIPageableListOfRunStep.class))
.map(assistantList -> PageableListAccessHelper.create(assistantList.getData(), assistantList.getFirstId(),
assistantList.getLastId(), assistantList.isHasMore()));
}

/**
* Gets a list of run steps from a thread run.
*
Expand Down Expand Up @@ -2475,6 +2504,63 @@ public Flux<StreamUpdate> createRunStream(String threadId, CreateRunOptions crea
return openAIServerSentEvents.getEvents();
}

/**
* Creates a new run for an assistant thread with additional included fields.
*
* @param threadId The ID of the thread to run.
* @param createRunOptions The details used when creating a new run of an assistant thread.
* @param runInclude A list of additional fields to include in the response.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by the server.
* @throws ClientAuthenticationException thrown if the request is rejected by the server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by the server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by the server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return data representing a single evaluation run of an assistant thread on successful completion of
* {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<ThreadRun> createRun(String threadId, CreateRunOptions createRunOptions, List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(Object::toString).collect(Collectors.joining(",")), false);
}
return createRunWithResponse(threadId, BinaryData.fromObject(createRunOptions), requestOptions)
.flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(ThreadRun.class));
}

/**
* Creates a new run for an assistant thread returning a stream of updates with additional included fields.
*
* @param threadId The ID of the thread to run.
* @param createRunOptions The details for the run to create.
* @param runInclude A list of additional fields to include in the response.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by the server.
* @throws ClientAuthenticationException thrown if the request is rejected by the server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by the server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by the server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return a stream of updates from the assistant thread run on successful completion of {@link Flux}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public Flux<StreamUpdate> createRunStream(String threadId, CreateRunOptions createRunOptions,
List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(Object::toString).collect(Collectors.joining(",")), false);
}
BinaryData inputJson = BinaryData.fromObject(createRunOptions);
BinaryData adjustedJson = OpenAIUtils.injectStreamJsonField(inputJson, true);
Flux<ByteBuffer> responseStream = createRunWithResponse(threadId, adjustedJson, requestOptions)
.flatMapMany(response -> response.getValue().toFluxByteBuffer());
OpenAIServerSentEvents openAIServerSentEvents = new OpenAIServerSentEvents(responseStream);
return openAIServerSentEvents.getEvents();
}

/**
* Modifies an existing thread run.
*
Expand Down Expand Up @@ -3919,4 +4005,35 @@ public Mono<VectorStoreFileBatch> createVectorStoreFileBatch(String vectorStoreI
.flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(VectorStoreFileBatch.class));
}

/**
* Gets a single run step from a thread run.
*
* @param threadId The ID of the thread that was run.
* @param runId The ID of the specific run to retrieve the step from.
* @param stepId The ID of the step to retrieve information about.
* @param runInclude A list of additional fields to include in the response.
* @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 single run step from a thread run on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<RunStep> getRunStep(String threadId, String runId, String stepId, List<RunIncludes> runInclude) {
// Generated convenience method for getRunStepWithResponse
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null) {
requestOptions.addQueryParam("include[]",
runInclude.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(",")),
false);
}
return getRunStepWithResponse(threadId, runId, stepId, requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(RunStep.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.azure.ai.openai.assistants.models.ListSortOrder;
import com.azure.ai.openai.assistants.models.OpenAIFile;
import com.azure.ai.openai.assistants.models.PageableList;
import com.azure.ai.openai.assistants.models.RunIncludes;
import com.azure.ai.openai.assistants.models.RunStep;
import com.azure.ai.openai.assistants.models.StreamUpdate;
import com.azure.ai.openai.assistants.models.ThreadDeletionStatus;
Expand Down Expand Up @@ -70,6 +71,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import reactor.core.publisher.Flux;

/**
Expand Down Expand Up @@ -1940,6 +1942,32 @@ public PageableList<RunStep> listRunSteps(String threadId, String runId) {
runStepList.isHasMore());
}

/**
* Gets a list of run steps from a thread run with additional run include parameters.
*
* @param threadId The ID of the thread that was run.
* @param runId The ID of the run from which to list steps.
* @param runInclude A list of extra fields to include in the response.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by the server.
* @throws ClientAuthenticationException thrown if the request is rejected by the server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by the server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by the server on status code 409.
* @return a {@link PageableList} of {@link RunStep} from the thread run.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PageableList<RunStep> listRunSteps(String threadId, String runId, List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(Object::toString).collect(Collectors.joining(",")), false);
}
OpenAIPageableListOfRunStep runStepList = listRunStepsWithResponse(threadId, runId, requestOptions).getValue()
.toObject(OpenAIPageableListOfRunStep.class);
return PageableListAccessHelper.create(runStepList.getData(), runStepList.getFirstId(), runStepList.getLastId(),
runStepList.isHasMore());
}

/**
* Gets a list of previously uploaded files.
*
Expand Down Expand Up @@ -2485,6 +2513,59 @@ public IterableStream<StreamUpdate> createRunStream(String threadId, String assi
return new IterableStream<>(eventStream.getEvents());
}

/**
* Creates a new run for an assistant thread with additional run include parameters.
*
* @param threadId The ID of the thread to run.
* @param createRunOptions The details for creating a new run.
* @param runInclude A list of extra fields to include in the response.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by the server.
* @throws ClientAuthenticationException thrown if the request is rejected by the server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by the server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by the server on status code 409.
* @return a {@link ThreadRun} representing the created run.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ThreadRun createRun(String threadId, CreateRunOptions createRunOptions, List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(Object::toString).collect(Collectors.joining(",")), false);
}
return createRunWithResponse(threadId, BinaryData.fromObject(createRunOptions), requestOptions).getValue()
.toObject(ThreadRun.class);
}

/**
* Creates a new run for an assistant thread returning a stream of updates with additional run include parameters.
*
* @param threadId The ID of the thread to run.
* @param createRunOptions The details for creating the run.
* @param runInclude A list of extra fields to include in the response.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by the server.
* @throws ClientAuthenticationException thrown if the request is rejected by the server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by the server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by the server on status code 409.
* @return an {@link IterableStream} of {@link StreamUpdate} representing the response stream.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public IterableStream<StreamUpdate> createRunStream(String threadId, CreateRunOptions createRunOptions,
List<RunIncludes> runInclude) {
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null && !runInclude.isEmpty()) {
requestOptions.addQueryParam("include[]",
runInclude.stream().map(Object::toString).collect(Collectors.joining(",")), false);
}
BinaryData inputJson = BinaryData.fromObject(createRunOptions);
BinaryData adjustedJson = OpenAIUtils.injectStreamJsonField(inputJson, true);
Flux<ByteBuffer> responseStream
= createRunWithResponse(threadId, adjustedJson, requestOptions).getValue().toFluxByteBuffer();
OpenAIServerSentEvents eventStream = new OpenAIServerSentEvents(responseStream);
return new IterableStream<>(eventStream.getEvents());
}

/**
* Modifies an existing thread run.
*
Expand Down Expand Up @@ -3932,4 +4013,34 @@ public VectorStoreFileBatch createVectorStoreFileBatch(String vectorStoreId, Lis
.getValue()
.toObject(VectorStoreFileBatch.class);
}

/**
* Gets a single run step from a thread run.
*
* @param threadId The ID of the thread that was run.
* @param runId The ID of the specific run to retrieve the step from.
* @param stepId The ID of the step to retrieve information about.
* @param runInclude A list of additional fields to include in the response.
* @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 single run step from a thread run.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public RunStep getRunStep(String threadId, String runId, String stepId, List<RunIncludes> runInclude) {
// Generated convenience method for getRunStepWithResponse
RequestOptions requestOptions = new RequestOptions();
if (runInclude != null) {
requestOptions.addQueryParam("include[]",
runInclude.stream()
.map(paramItemValue -> Objects.toString(paramItemValue, ""))
.collect(Collectors.joining(",")),
false);
}
return getRunStepWithResponse(threadId, runId, stepId, requestOptions).getValue().toObject(RunStep.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,22 @@ public enum AssistantsServiceVersion implements ServiceVersion {
/**
* Enum value 2024-07-01-preview.
*/
V2024_07_01_PREVIEW("2024-07-01-preview");
V2024_07_01_PREVIEW("2024-07-01-preview"),

/**
* Enum value 2024-09-01-preview.
*/
V2024_09_01_PREVIEW("2024-09-01-preview"),

/**
* Enum value 2024-10-01-preview.
*/
V2024_10_01_PREVIEW("2024-10-01-preview"),

/**
* Enum value 2025-01-01-preview.
*/
V2025_01_01_PREVIEW("2025-01-01-preview");

private final String version;

Expand All @@ -45,6 +60,6 @@ public String getVersion() {
* @return The latest {@link AssistantsServiceVersion}.
*/
public static AssistantsServiceVersion getLatest() {
return V2024_07_01_PREVIEW;
return V2025_01_01_PREVIEW;
}
}
Loading

0 comments on commit 2186a4c

Please sign in to comment.