Skip to content

Commit

Permalink
[OpenAI] [Assistants] Assistant V2 support v2024-05-01-preview rele…
Browse files Browse the repository at this point in the history
…ase (#40389)

* Updated commit hash to latest assistantv2 commit

* Using commit without the openAPI v3 annotations

* Project compiles

* Code regen after tooling update and commit cherry picking

* Corrections to the readme from codegen

* Code regen

* Code regen

* Modified return types for paginated endpoints

* Migrated paged endpoints to use PageableList<> async

* Added test skeleton class for vectorStore

* Updated commit hash

* WIP: introduced intermediate type for custom serialization logic

* WIP: trying to add tests, running into issues

* Removed AssistantFile related class

* Fixed (de)serialization for assistantCreation response_format

* Added docs for getters

* Added customization for createRunOptions

* Added tests for CreateAndRunThreadOptions

* Added tests for updateAssistantOption

* Added tests for getter methods

* Added assertion for getters too

* Removed some left over @generated

* Code regen

* Added missing responseFormat handling for ThreadRun

* Added tests for tool_choice

* Addd tests for createAndRunThreadOptions

* Added tests createRunOptions

* Removed imports

* Added tests for null input JSON

* code regen

* Adjusted header value to use v2 for openAI

* Updated test recordings

* Removing recordings for removed tests

* using a commit hash from main

* Ajusted method

* Re-recorded as much as possible. Adjusted some assertions. Marked tests that need more work

* WIP: sanitizers behaivour

* Renamed/removed retrieval related classes to file_search

* WIP: deserialization is failing

* Fle search test passing

* Updated tests for file_search

* Addressed 404

* renamed sample

* Code regen

* Various test improvements

* WIP: style checks

* Style checks

* More style checks

* [OpenAI-Assistant] Added vector store feature (#40467)

* use the main repo's SHA

* fixed the typo

* Trying to make the CI happy

* Second try

* Reverting changes

* WIP: sorting added features and breaking changes

* Last details in the CHANGELOG

* Typos and casing issues

* CHANGELOG feedback

* fixed the sanitizer CI failures

* Added a few more notes in CHANGELOG.md

---------

Co-authored-by: Shawn Fang <45607042+mssfang@users.noreply.github.com>
Co-authored-by: Shawn Fang <shafang@microsoft.com>
  • Loading branch information
3 people authored Jun 6, 2024
1 parent d674de5 commit 85c1836
Show file tree
Hide file tree
Showing 133 changed files with 14,712 additions and 5,540 deletions.
120 changes: 115 additions & 5 deletions sdk/openai/azure-ai-openai-assistants/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,130 @@
# Release History

## 1.0.0-beta.3 (Unreleased)
## 1.0.0-beta.3 (2024-06-07)

### Features Added

- Added `createRunStream` and `createThreadAndRunStream` methods to `AssistantsClient` and `AssistantsAsyncClient` classes. A suite of classes extending from `StreamUpdate` were added for users to be able to consume the incremental updates from the service
#### Streaming

- Operation updates:
- Added `createRunStream`, `createThreadAndRunStream` and `submitToolOutputsToRunStream` methods to `AssistantsClient` and `AssistantsAsyncClient` classes.
A suite of classes extending from `StreamUpdate` were added for users to be able to consume the incremental updates from the service.

#### Assistants

- Model updates:
- `Assistant`, `AssistantCreationOptions` and `UpdateAssistantOptions` models:
- Added new fields: `toolResources` , `temperature`, `topP` and `responseFormat`.

#### Files

- Model updates:
- `OpenAIFile` model changes:
- Added new fields: `status` of `FileState` type and `status_details` of `String` type.
- Added new enum `FileState` representing the type of the `status` field mentioned in the previous point.
- Added new possible values for `FilePurpose`: `batch`, `batch_output` and `vision`.

#### Messages

- Operation updates:
- Updated `listMessages` to accept the filter `runId`.

- Model updates:
- Added new model `MessageAttachment`.
- Updated docs renaming mentions of `retrieval` tool to `file_search`.
- Added new field, `startIndex` and `endIndex` to `MessageTextFileCitationAnnotation`, `MessageTextFilePathAnnotation` model.
#### Run Step

- Model updates:
- `ThreadRun` model updates:
- Added fields: `temperature`, `topP`, `maxPromptTokens`, `maxCompletionTokens`, `truncationStrategy`, `toolChoice` and `responseFormat`.
- Updated documentation for `RunCompletionUsage`.
- `CreateRunOptions` model updates:
- Added fields: `additionalMessages`, `temperature`, `topP`, `maxPromptTokens`, `maxCompletionTokens`, `truncationStrategy`, `toolChoice` and `responseFormat`.
- `CreateAndRunThreadOptions` model updates:
- Added fields: `toolResources`, `temperature`, `topP`, `maxPromptTokens`, `maxCompletionTokens`, `truncationStrategy`, `toolChoice` and `responseFormat`.
- Added new model for all the `truncationStrategy` fields called `TruncationObject`.

#### Threads

- Model updates:
- `AssistantThread` model now includes `toolResources` field as nullable.
- `AssistantThreadCreationOptions` updates include: `messages` type using renamed type `ThreadInitializationMessage` -> `ThreadMessageOptions`, `toolResources`.

#### Tool Resources (new)

- Model updates:
- There are 3 new models that were added: `ToolResources`, `CreateToolResourcesOptions` and `UpdateToolResourcesOptions`. As the name implies, wherever there is
a field `toolResource` we use the appropriate type, depending on the model declaring it is meant to be a response object, create request object or update request object, respectively.

#### Vector Stores (new)

There are 3 main areas for vector stores into which its models and operations can be divided. That is vector stores themselves, vector store files and vector store file batches.

- Model updates:
- new models (I will just list the top level response and request objects, but there are several subtypes describing more complex JSON object fields): `VectorStore` and `VectorStoreOptions`, `VectorStoreFile` and there is no request object, `VectorStoreFileBatch` and there is no request object.

- Operation Updates:
- new operations `listVectorStores` , `createVectorStore`, `getVectorStore`, `modifyVectorStore` and `deleteVectorStore`.
- new vector store file operations: `listVectorStoreFiles`, `createVectorStoreFile`, `getVectorStoreFile` and `deleteVectorStoreFile`.
- new vector store file batch operations: `createVectorStoreFileBatch`, `getVectorStoreFileBatch`, `cancelVectorStoreFileBatch` and `listVectorStoreFileBatchFiles`.

### Breaking Changes

- Removed method `uploadFile(FileDetails file, FilePurpose purpose)`. Use `uploadFile(FileDetails file, FilePurpose purpose, String fileName)` instead.
#### Assistants

- Model updates:
- Removed `AssistantFile` model.
- `Assistant`, `AssistantCreateOptions` and `UpdateAssistantOptions` models:
- removed fields: `fileIds`.
- Operation updates:
- Removed operations: `createAssistantFile` , `listAssistantFiles`, `getAssistantFile` and `deleteAssistantFile`.

#### Files

- Removed method `uploadFile(FileDetails file, FilePurpose purpose)`. Use `uploadFile(FileDetails file, FilePurpose purpose, String fileName)` instead

#### Messages

- Model updates:
- Renamed `ThreadInitializationMessage` to `ThreadMessageOptions`.
- Removed `MessageFile` model.
- Updated `ThreadMessage` model:
- The field `incomplete_details` was of the wrong type. Corrected from `MessageIncompleteDetailsReason` -> `MessageIncompleteDetails`.
- `assistantId` was marked as optional, but it was in fact nullable
- `runId` was marked as optional, but it was in fact nullable
- Removed field `fileIds`
- Added new field `attachments` a nullable array of `MessageAttachment`

- Operation updates:
- Removed `MessageFile` related operations: `listMessageFiles` and `getMessageFile`
- Updated `createMessage` to accept the `ThreadMessageOptions` model (also used in `AssistantThreadCreationOptions`)

#### Run Step

- Model updates:
- `ThreadRun` model updates:
- Removed field `fileIds`

#### Threads

- Model updates:
- Extracted fields used in `updateThread` operation into model `UpdateAssistantThreadOptions` which now includes the new fields `toolResources`.

- Operation updates:
- `updateThread` using extracted model `UpdatedAssistantThreadOptions` instead of parameters using the spread operator.

#### Tools

- Model updates: (mostly about renaming tool `retrieval` to `file_search`)
- Renamed model `RetrievalToolDefinition` to `FileSearchToolDefinition` and the associated discriminator value.
- Renamed model `RunStepDeltaRetrievalToolCall` to `RunStepDeltaFileSearchToolCall`.
- `RunStepToolCall` variant `RunStepRetrievalToolCall` renamed to `RunStepFileSearchToolCall` and the associated discriminator value.

### Bugs Fixed

- A combination of inputs for `uploadFile` would allow users to not send `String filename` to the service resulting always in an error, as this is actually mandatory.

### Other Changes

## 1.0.0-beta.2 (2024-02-13)

Expand All @@ -40,7 +150,7 @@ client.listFilesWithResponse(requestOptions)

### Other Changes

- On `uploadFile` method in `AssistantsClient` and `AssistantsAsyncClient`, it is required to set the "filename" of the file, via `setFilename` method in `FileDetails` class. The double quote character `"`, the newline charactor `0x0A`, the return charactor `0x0D` in "filename" would be escaped by the client library.
- On `uploadFile` method in `AssistantsClient` and `AssistantsAsyncClient`, it is required to set the "filename" of the file, via `setFilename` method in `FileDetails` class. The double quote character `"`, the newline character `0x0A`, the return character `0x0D` in "filename" would be escaped by the client library.


## 1.0.0-beta.1 (2024-02-07)
Expand Down
17 changes: 12 additions & 5 deletions sdk/openai/azure-ai-openai-assistants/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ String threadId = thread.getId();
With a thread created, a message can be created on it:
```java readme-sample-createMessage
String userMessage = "I need to solve the equation `3x + 11 = 14`. Can you help me?";
ThreadMessage threadMessage = client.createMessage(threadId, MessageRole.USER, userMessage);
ThreadMessage threadMessage = client.createMessage(threadId, new ThreadMessageOptions(MessageRole.USER, userMessage));
```

As we have a thread and message, we can create a run:
Expand All @@ -115,7 +115,7 @@ There is also a convenience method to create a thread and message, and then run
```java readme-sample-createThreadAndRun
CreateAndRunThreadOptions createAndRunThreadOptions = new CreateAndRunThreadOptions(assistantId)
.setThread(new AssistantThreadCreationOptions()
.setMessages(Arrays.asList(new ThreadInitializationMessage(MessageRole.USER,
.setMessages(Arrays.asList(new ThreadMessageOptions(MessageRole.USER,
"I need to solve the equation `3x + 11 = 14`. Can you help me?"))));
run = client.createThreadAndRun(createAndRunThreadOptions);
```
Expand Down Expand Up @@ -163,12 +163,19 @@ Once uploaded, the file ID can then be provided to an assistant upon creation. N
an appropriate tool like Code Interpreter or Retrieval is enabled.

```java readme-sample-createRetrievalAssistant
// Create Tool Resources. This is how we pass files to the Assistant.
CreateToolResourcesOptions createToolResourcesOptions = new CreateToolResourcesOptions();
createToolResourcesOptions.setFileSearch(
new CreateFileSearchToolResourceOptions(
new CreateFileSearchToolResourceVectorStoreOptionsList(
Arrays.asList(new CreateFileSearchToolResourceVectorStoreOptions(Arrays.asList(openAIFile.getId()))))));

Assistant assistant = client.createAssistant(
new AssistantCreationOptions(deploymentOrModelId)
.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 RetrievalToolDefinition()))
.setFileIds(Arrays.asList(openAIFile.getId()))
.setTools(Arrays.asList(new FileSearchToolDefinition()))
.setToolResources(createToolResourcesOptions)
);
```

Expand Down Expand Up @@ -283,7 +290,7 @@ run via the `SubmitRunToolOutputs` method so that the run can continue:

```java readme-sample-functionHandlingRunPolling
do {
Thread.sleep(500);
Thread.sleep(1000);
run = client.getRun(thread.getId(), run.getId());

if (run.getStatus() == RunStatus.REQUIRES_ACTION
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_ceb2cd5662"
"Tag" : "java/assistants/azure-ai-openai-assistants_868e5c86d0"
}
Loading

0 comments on commit 85c1836

Please sign in to comment.