Skip to content

Commit 53268ef

Browse files
authored
[OpenAI] Support Service API version 2024-08-01-preview (#41900)
Support Service API version 2024-08-01-preview for Structured Output
1 parent 199d7f8 commit 53268ef

File tree

70 files changed

+5669
-659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5669
-659
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@
432432
"undelete",
433433
"unmanaged",
434434
"unmutated",
435+
"vectorizer",
435436
"versionid",
436437
"vertx",
437438
"Vertx",

sdk/openai/azure-ai-openai/CHANGELOG.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
# Release History
22

3-
## 1.0.0-beta.12 (Unreleased)
3+
## 1.0.0-beta.12 (2024-10-22)
44

55
### Features Added
6+
- Added support for service API version `2024-08-01-preview`.
7+
- Structured Outputs can be enabled by setting the parameter `strict: true` in an API call with either a defined response format or function definitions.
8+
- Added `refusal` property in `ChatChoiceLogProbabilityInfo`, `ChatMessageContentItem`, `ChatResponseMessage` classes,
9+
and a new type of content item class `ChatMessageRefusalContentItem` to support refusal. `refusal` only works with structured output.
10+
- Added `json_schema` property in `ChatCompletionsResponseFormat` class to support JSON schema.
11+
New classes `ChatCompletionsJsonSchemaResponseFormat` and `ChatCompletionsJsonSchemaResponseFormatJsonSchema` are added to support JSON schema response format.
12+
- Added support for uploading large files in multiple parts. New client methods `createUpload`, `addUploadPart`,
13+
`completeUpload` and `cancelUpload` introduced in `OpenAIClient` and `OpenAIAsyncClient` classes.
14+
- Updated `ChatRequestMessages` derived classes,
15+
- `ChatRequestSystemMessage` content: `String` or `ChatMessageTextContentItem[]`.
16+
- `ChatRequestAssistantMessage` content: `String`, `ChatMessageTextContentItem[]`, `ChatMessageRefusalContentItem[]` or `null`.
17+
- `ChatRequestToolMessage` content: `String` or `ChatMessageTextContentItem[]`.
18+
- Added `rerank_score` property in `AzureChatExtensionDataSourceResponseCitation` class to support re-rank score.
19+
- Added support for MongoDB chat extension. New classes `MongoDBChatExtensionConfiguration`, `MongoDBChatExtensionParameters`,
20+
and `MongoDBChatExtensionParametersFieldsMapping` are added to support MongoDB chat extension.
21+
- Added `username_and_password` in `OnYourDataAuthenticationOptions` class and an input option class`OnYourDataUsernameAndPasswordAuthenticationOptions` to support username and password authentication.
22+
- Added `intergrated` property in `OnYourDataVectorizationSource` class and `OnYourDataVectorizationSourceType` to support integrated vectorization source.
623

724
### Breaking Changes
825

9-
### Bugs Fixed
26+
- Replaced `FunctionDefintion` by `ChatCompletionsFunctionToolDefinitionFunction` in `ChatCompletionsFunctionToolDefinition` class.
27+
`FunctionDefintion` only works for `functions` but not `tools`, The `functions` is deprecated.
28+
- Removed `azure_ml_index` from `AzureChatExtensionConfiguration` class, and its response models `AzureMachineLearningIndexConfiguration` and `AzureMachineLearningIndexChatExtensionParameters`.
29+
- Removed `role_information` from `AzureSearchChatExtensionParameters`, `ElasticsearchChatExtensionParameters` and `PineconeChatExtensionParameters` classes.
1030

1131
### Other Changes
1232

33+
- Upgraded `azure-core` to version `1.53.0`.
34+
- Upgraded `azure-core-http-netty` to version `1.15.5`.
35+
1336
## 1.0.0-beta.11 (2024-08-29)
1437

1538
### Features Added

sdk/openai/azure-ai-openai/README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ For concrete examples you can have a look at the following links. Some of the mo
2424
* [Text To Speech sample](#text-to-speech "Text To Speech")
2525
* [File operations sample](#file-operations "File Operations")
2626
* [Batch operations sample](#batch-operations "Batch Operations")
27+
* [Structured Outputs](#structured-outputs "Structured Outputs")
28+
* [Upload large files in multiple parts](#upload-large-files-in-multiple-parts "Upload large files in multiple parts")
2729

2830
If you want to see the full code for these snippets check out our [samples folder][samples_folder].
2931

@@ -45,7 +47,7 @@ If you want to see the full code for these snippets check out our [samples folde
4547
<dependency>
4648
<groupId>com.azure</groupId>
4749
<artifactId>azure-ai-openai</artifactId>
48-
<version>1.0.0-beta.11</version>
50+
<version>1.0.0-beta.12</version>
4951
</dependency>
5052
```
5153
[//]: # ({x-version-update-end})
@@ -162,6 +164,8 @@ The following sections provide several code snippets covering some of the most c
162164
* [Text To Speech sample](#text-to-speech "Text To Speech")
163165
* [File operations sample](#file-operations "File Operations")
164166
* [Batch operations sample](#batch-operations "Batch Operations")
167+
* [Structured Outputs](#structured-outputs "Structured Outputs")
168+
* [Upload large files in multiple parts](#upload-large-files-in-multiple-parts "Upload large files in multiple parts")
165169

166170
### Legacy completions
167171

@@ -362,7 +366,7 @@ List<ChatRequestMessage> chatMessages = Arrays.asList(
362366
new ChatRequestUserMessage("What sort of clothing should I wear today in Berlin?")
363367
);
364368
ChatCompletionsToolDefinition toolDefinition = new ChatCompletionsFunctionToolDefinition(
365-
new FunctionDefinition("MyFunctionName"));
369+
new ChatCompletionsFunctionToolDefinitionFunction("MyFunctionName"));
366370

367371
ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions(chatMessages);
368372
chatCompletionsOptions.setTools(Arrays.asList(toolDefinition));
@@ -460,6 +464,51 @@ Batch cancelledBatch = client.cancelBatch(batch.getId());
460464
```
461465
For a complete sample example, see sample [Batch Operations][sample_batch_operations].
462466

467+
### Structured Outputs
468+
469+
Structured Outputs can be enabled by setting the parameter `strict: true` in an API call with either a defined
470+
`response format` or `function definitions`.
471+
```java readme-sample-structuredOutputsResponseFormat
472+
ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions(Arrays.asList(new ChatRequestUserMessage("What is the weather in Seattle?")))
473+
// Previously, the response_format parameter was only available to specify that the model should return a valid JSON.
474+
// In addition to this, we are introducing a new way of specifying which JSON schema to follow.
475+
.setResponseFormat(new ChatCompletionsJsonSchemaResponseFormat(
476+
new ChatCompletionsJsonSchemaResponseFormatJsonSchema("get_weather")
477+
.setStrict(true)
478+
.setDescription("Fetches the weather in the given location")
479+
.setSchema(BinaryData.fromObject(new Parameters()))));
480+
```
481+
482+
For a full sample, see [Structured Output: Response Format][sample_chat_completions_json_schema].
483+
For more details see the [OpenAI structured output documentation](https://platform.openai.com/docs/guides/structured-output).
484+
485+
### Upload large files in multiple parts
486+
487+
`uploads` allows you to upload large files in multiple parts.
488+
489+
```java readme-sample-uploadsLargeFilesMultipleParts
490+
CreateUploadRequest createUploadRequest = new CreateUploadRequest("{fileNameToCreate}", CreateUploadRequestPurpose.ASSISTANTS,
491+
totalFilesSize, "text/plain");
492+
Upload upload = client.createUpload(createUploadRequest);
493+
String uploadId = upload.getId();
494+
495+
UploadPart uploadPartAdded = client.addUploadPart(uploadId,
496+
new AddUploadPartRequest(new DataFileDetails(BinaryData.fromFile(path)).setFilename("{fileName}")));
497+
String uploadPartAddedId = uploadPartAdded.getId();
498+
System.out.println("Upload part added, upload part ID = " + uploadPartAddedId);
499+
500+
UploadPart uploadPartAdded2 = client.addUploadPart(uploadId,
501+
new AddUploadPartRequest(new DataFileDetails(BinaryData.fromFile(path2)).setFilename("{fileName2}")));
502+
String uploadPartAddedId2 = uploadPartAdded2.getId();
503+
System.out.println("Upload part 2 added, upload part ID = " + uploadPartAddedId2);
504+
505+
CompleteUploadRequest completeUploadRequest = new CompleteUploadRequest(Arrays.asList(uploadPartAddedId, uploadPartAddedId2));
506+
Upload completeUpload = client.completeUpload(uploadId, completeUploadRequest);
507+
System.out.println("Upload completed, upload ID = " + completeUpload.getId());
508+
```
509+
For a full sample, see [Upload large files in multiple parts][sample_uploads_in_multi_parts].
510+
For more details see the [OpenAI uploads documentation](https://platform.openai.com/docs/api-reference/uploads).
511+
463512
## Troubleshooting
464513
### Enable client logging
465514
You can set the `AZURE_LOG_LEVEL` environment variable to view logging statements made in the client library. For
@@ -516,6 +565,7 @@ For details on contributing to this repository, see the [contributing guide](htt
516565
[sample_batch_operations]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/BatchOperationsSample.java
517566
[sample_chat_completion_function_call]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/ChatCompletionsFunctionCall.java
518567
[sample_chat_completion_BYOD]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/ChatCompletionsWithYourData.java
568+
[sample_chat_completions_json_schema]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/StructuredOutputsResponseFormat.java
519569
[sample_file_operations]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/FileOperationsSample.java
520570
[sample_get_chat_completions]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/usage/GetChatCompletionsSample.java
521571
[sample_get_chat_completions_streaming]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/usage/GetChatCompletionsStreamSample.java
@@ -528,6 +578,7 @@ For details on contributing to this repository, see the [contributing guide](htt
528578
[sample_chat_with_images]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/usage/GetChatCompletionsVisionSample.java
529579
[sample_tool_calls]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/usage/GetChatCompletionsToolCallSample.java
530580
[sample_text_to_speech]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/usage/TextToSpeechSample.java
581+
[sample_uploads_in_multi_parts]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/samples/java/com/azure/ai/openai/UploadLargeFileInPartsSample.java
531582
[openai_client_async]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIAsyncClient.java
532583
[openai_client_builder]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIClientBuilder.java
533584
[openai_client_sync]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/OpenAIClient.java

sdk/openai/azure-ai-openai/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/openai/azure-ai-openai",
5-
"Tag": "java/openai/azure-ai-openai_d06764f648"
5+
"Tag": "java/openai/azure-ai-openai_6e15ecd77a"
66
}

0 commit comments

Comments
 (0)