Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
15e0873
initial auto-genned code
glharper Jul 30, 2024
8aeeaa0
use camel case for Json in class name
glharper Jul 31, 2024
64c6fbe
initial work on setting up a test
glharper Aug 1, 2024
bc4f8ba
Fix some compile errors
glharper Aug 2, 2024
f2ef2a6
test actually compiles (and fails)
glharper Aug 2, 2024
5e37b21
add to azure-sdks-all
glharper Aug 5, 2024
bbceade
fix json typo causing defaultCompleteOptions to throw
glharper Aug 6, 2024
96d5517
add completeStreaming convenience method and InferenceSSE class
glharper Aug 7, 2024
1482e53
add chat samples (sync), streaming convenience fields
glharper Aug 8, 2024
21a93a7
simplify convenience method for defaultCompleteOptions
glharper Aug 8, 2024
db2adaf
got test working in intellij
glharper Aug 9, 2024
182283d
add streaming chat test
glharper Aug 9, 2024
fa77eb6
add streaming chat async sample and support code to async client
glharper Aug 9, 2024
e38cf9b
add convenience method for async complete, basic async chat sample
glharper Aug 9, 2024
60ecc44
change options class name
glharper Aug 13, 2024
76752b9
Merge branch 'main' into glharper/ai-inference-typespec-gen
glharper Aug 13, 2024
c4c17f3
merge deletes
glharper Aug 13, 2024
704a932
add async tests for complete and completeStreaming
glharper Aug 13, 2024
c40edc2
remove refs to jackson package
glharper Aug 14, 2024
eb66988
add chat completions code to README (links needed)
glharper Aug 14, 2024
6db0a20
add troubleshooting file, links in README
glharper Aug 15, 2024
87fe50b
add readmeSamples class for readme code sample auto gen
glharper Aug 15, 2024
b5f7dd0
update genned code with embeddingsClient, imageEmbeddingsClient
glharper Aug 16, 2024
2c591f7
revert parameters to Object type
glharper Aug 19, 2024
8d57e38
add embedding sample
glharper Aug 19, 2024
92c7940
add Embeddings test classes
glharper Aug 20, 2024
41ac88c
add async embeddings test
glharper Aug 21, 2024
bcd81e7
add text embeddings async sample
glharper Aug 21, 2024
75cbd93
make embed method public
glharper Aug 21, 2024
0edc3dc
cleaner embeddings sample output
glharper Aug 22, 2024
5ec93fe
fix javadoc gen
glharper Aug 22, 2024
56877a6
fix dep versions
glharper Aug 22, 2024
824af35
Merge branch 'main' into glharper/ai-inference-typespec-gen
glharper Aug 22, 2024
28ed275
phrasing
glharper Aug 23, 2024
c28cb88
add AAD sample with scope
glharper Aug 23, 2024
569a7ba
better explanation of auth scope setting in sample
glharper Aug 26, 2024
0159de4
allow mvn compile
glharper Aug 27, 2024
5f7e9e4
create and allow playback for test recordings
glharper Aug 27, 2024
9778717
Merge branch 'main' into glharper/ai-inference-typespec-gen
glharper Aug 27, 2024
724c6cd
change display name in ci.yml
glharper Aug 27, 2024
7b5fd75
add codeowners
glharper Aug 27, 2024
0addf5c
kick off new build
glharper Aug 27, 2024
2014db0
add tests.yml
glharper Aug 27, 2024
aa0b20b
remove EnableBatchRelease field
glharper Aug 27, 2024
169ef29
update to pass codegen test
glharper Aug 27, 2024
0b94392
use existing label
glharper Aug 27, 2024
4d36050
add ubinary to ignored words
glharper Aug 27, 2024
af336a3
use proper streaming types, remove delta from ChatChoice
glharper Aug 27, 2024
c766694
rename getEmbedding to getEmbeddingList, add auto-genned method
glharper Aug 27, 2024
ba30dfe
make getModelInfo public for java
glharper Aug 28, 2024
3c80a48
use Json instead of JSON in class/file name
glharper Aug 28, 2024
7d67873
sync ChatChoice with TS output
glharper Aug 28, 2024
00e5ff5
set partial-update to true
glharper Aug 28, 2024
c41b376
codegen more closely synced
glharper Aug 28, 2024
f282c7f
use latest typespec
glharper Aug 28, 2024
9207907
add customization code
glharper Aug 28, 2024
91315db
updated typespec
glharper Aug 28, 2024
31c668b
App Config Correlation Context update + yaml hint fix (#41607)
mrm9084 Aug 27, 2024
f331c06
Use code customizations to map internal Storage error in generated co…
alzimmermsft Aug 27, 2024
8af7351
Add namespaces (packages) to packageInfo (#41639)
JimSuplizio Aug 27, 2024
c8a40ef
Publish code coverage results from 1 to2 (#41656)
JimSuplizio Aug 27, 2024
de56545
Fix typo (#41658)
JimSuplizio Aug 27, 2024
be350a0
prepare for 1.2.27 bom release (#41659)
mssfang Aug 27, 2024
f1fe13d
Move logging token acquisition to VERBOSE (#41648)
billwert Aug 27, 2024
b66f356
Sync eng/common directory with azure-sdk-tools for PR 8875 (#41660)
azure-sdk Aug 27, 2024
ded2a4c
[App Configuration] Add test case for feature management lib (#41498)
ivywei0125 Aug 28, 2024
f1cd2ea
Retrieve TokenCredential from ConfigurableBootstrapContext for env po…
saragluna Aug 28, 2024
74c418d
[Automation] Generate SDK based on TypeSpec 0.20.0 (#41666)
azure-sdk Aug 28, 2024
f04726d
add customization to unfinalize base classes
glharper Aug 28, 2024
dc8e8cd
more typespec syncs
glharper Aug 28, 2024
dfd2b0a
correct doc comment
glharper Aug 28, 2024
4e43f2c
make extra parameters public
glharper Aug 28, 2024
0e2de44
fix bad gen
glharper Aug 28, 2024
eabceb9
remove dupe imports
glharper Aug 28, 2024
096afa2
sync with typespec
glharper Aug 28, 2024
2d2c8b1
add lint exception for PagedFlux
glharper Aug 28, 2024
2badf01
lint fixes
glharper Aug 28, 2024
9eb9291
App Config Correlation Context update + yaml hint fix (#41607)
mrm9084 Aug 27, 2024
0879248
[OpenAI-Assistant] Added support for 2024-07-01 (#41464)
mssfang Aug 28, 2024
099ab20
Default to sub config file paths/svc connection for public + sovereig…
benbp Aug 28, 2024
efc709d
Merge branch 'main' into glharper/ai-inference-typespec-gen
glharper Aug 29, 2024
ed57d25
remove azure.xml dependency
glharper Sep 3, 2024
889af92
make completeWithResponse public
glharper Sep 4, 2024
c642285
make complete with options public
glharper Sep 4, 2024
579db68
add string constructor for ChatRequestUserMessage
glharper Sep 4, 2024
16173db
add scopes to ClientBuilders, change parameters in FunctionDefinition…
glharper Sep 6, 2024
68c21cf
update comment
glharper Sep 9, 2024
6277444
correct string constructor for ChatRequestUserMessage
glharper Sep 9, 2024
9f3a3c3
formatting
glharper Sep 9, 2024
b47d611
add streaming tool call sample
glharper Sep 9, 2024
37271cc
add Mono<Response<>> completeWithResponse API to AsyncClient
glharper Sep 9, 2024
f0904b3
better implementation of completeWithResponse
glharper Sep 10, 2024
68a60da
remove unused import
glharper Sep 10, 2024
4da0b99
add embedWithResponse API to embeddings clients
glharper Sep 10, 2024
e19add0
add tests for complete(options) and completeWithResponse APIs
glharper Sep 11, 2024
a117bcb
more sync tests
glharper Sep 11, 2024
4f40215
add stream response test
glharper Sep 11, 2024
6d9f94c
add completeStreamWithResponse test, change completeStreaming to comp…
glharper Sep 11, 2024
6687aff
new test recordings
glharper Sep 11, 2024
870f73a
changes for TypeSpec sync
glharper Sep 12, 2024
be46f17
fix pom error
glharper Sep 12, 2024
67e2a8b
add deleted file
glharper Sep 12, 2024
3b45281
restore deleted files
glharper Sep 12, 2024
ca4e813
restore more deleted files
glharper Sep 12, 2024
5333b4f
even more deleted files
glharper Sep 12, 2024
300047d
pull in openai changes from main
glharper Sep 12, 2024
dd39426
more deleted files
glharper Sep 12, 2024
37bd871
unmod openai file
glharper Sep 12, 2024
015dba2
update HTTP client link
glharper Sep 12, 2024
d16a4d6
spacing for typespec gen
glharper Sep 13, 2024
6b6300a
update dependencies
glharper Sep 13, 2024
cd42ab1
spacing
glharper Sep 13, 2024
784b348
spacing
glharper Sep 13, 2024
a2cb50e
spacing
glharper Sep 13, 2024
33e8045
update min jacoco settings
glharper Sep 13, 2024
71ae8dc
trigger CI build
glharper Sep 13, 2024
1c3a19f
Naive implementations of new APIs fromContentItems and file construct…
glharper Sep 16, 2024
c58eeae
spacing
glharper Sep 16, 2024
589af5d
add image read sample and correct API implementations
glharper Sep 16, 2024
cc4bd44
sanity check, cleaner syntax, and samples style fixes
glharper Sep 17, 2024
89f375e
Add ImageUrlChatSample
glharper Sep 17, 2024
a299d5d
update dependency version
glharper Sep 17, 2024
48316e3
typespec sync
glharper Sep 17, 2024
e16676f
review feedback
glharper Sep 17, 2024
3177d59
Update sdk/ai/azure-ai-inference/README.md
glharper Sep 17, 2024
9049cc2
Update sdk/ai/azure-ai-inference/README.md
glharper Sep 17, 2024
4c7e0b1
fix TypeSpec crash
glharper Sep 17, 2024
bcc6cef
remove unneeded paragraph
glharper Sep 17, 2024
75b1bc6
make TypeSpec sync happy
glharper Sep 17, 2024
7defa2a
add access helper to ChatCompletionsOptions
glharper Sep 17, 2024
171931a
typespec sync
glharper Sep 17, 2024
17a9704
review feedback
glharper Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
# ServiceLabel: %Advisor
# ServiceOwners: @mojayara @Prasanna-Padmanabhan

# PRLabel: %AI Model Inference
/sdk/ai/azure-ai-inference/ @dargilco @jhakulin @glharper

# ServiceLabel: %AKS
# ServiceOwners: @Azure/aks-pm

Expand Down
7 changes: 7 additions & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@
"NDVI"
]
},
{
"filename": "/sdk/ai/**",
"words": [
"ubinary",
"UBINARY"
]
},
{
"filename": "/sdk/datalakeanalytics/**",
"words": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ the main ServiceBusClientBuilder. -->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files="com.azure.ai.openai.(OpenAIClient|OpenAIAsyncClient).java"/>
<!-- Checkstyle suppression for OpenAI Assistants client APIs that use Flux instead of PagedFlux for methods that return a collection -->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files="com.azure.ai.openai.assistants.(AssistantsClient|AssistantsAsyncClient).java"/>
<!-- Checkstyle suppression for Inference client APIs that use Flux instead of PagedFlux for methods that return a collection -->
<suppress checks="com.azure.tools.checkstyle.checks.ServiceClientCheck" files="com.azure.ai.inference.(ChatCompletionsClient|ChatCompletionsAsyncClient).java"/>

<!-- jdbc sdk suppression -->
<suppress checks="com.azure.tools.checkstyle.checks.ExternalDependencyExposedCheck"
Expand Down
1 change: 1 addition & 0 deletions eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ com.azure:azure-ai-documentintelligence;1.0.0-beta.4;1.0.0-beta.5
com.azure:azure-ai-documenttranslator;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-ai-formrecognizer;4.1.10;4.1.10
com.azure:azure-ai-formrecognizer-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-ai-inference;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-ai-metricsadvisor;1.2.1;1.3.0-beta.1
com.azure:azure-ai-metricsadvisor-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-ai-openai;1.0.0-beta.10;1.0.0-beta.11
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<module>eng/code-quality-reports</module>
<module>sdk/advisor</module>
<module>sdk/agrifood</module>
<module>sdk/ai</module>
<module>sdk/alertsmanagement</module>
<module>sdk/anomalydetector</module>
<module>sdk/aot</module>
Expand Down
13 changes: 13 additions & 0 deletions sdk/ai/azure-ai-inference/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Release History

## 1.0.0-beta.1 (Unreleased)

- Azure AI Inference client library for Java. This package contains Microsoft Azure AI Inference client library.

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
225 changes: 225 additions & 0 deletions sdk/ai/azure-ai-inference/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# Azure AI Inference client library for Java

Azure AI Inference client library for Java.

This package contains the Azure AI Inference client library.

## Documentation

Various documentation is available to help you get started

- [API reference documentation][docs]
- [Product documentation][product_documentation]

## Getting started

### Prerequisites

- [Java Development Kit (JDK)][jdk] with version 8 or above
- [Azure Subscription][azure_subscription]

### Adding the package to your product

[//]: # ({x-version-update-start;com.azure:azure-ai-inference;current})
```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-inference</artifactId>
<version>1.0.0-beta.1</version>
</dependency>
```
[//]: # ({x-version-update-end})

### Authentication

In order to interact with the Azure AI Inference Service you'll need to create an instance of client class,
[ChatCompletionsAsyncClient][chat_completions_client_async] or [ChatCompletionsClient][chat_completions_client_sync] by using
[ChatCompletionsClientBuilder][chat_completions_client_builder]. To configure a client for use with
Azure Inference, provide a valid endpoint URI to an Azure Model resource along with a corresponding key credential,
token credential, or [Azure Identity][azure_identity] credential that's authorized to use the Azure Model resource.

#### Create a Chat Completions client with key credential
Get Azure Model `key` credential from the Azure Portal.

```java readme-sample-createSyncClientKeyCredential
ChatCompletionsClient client = new ChatCompletionsClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
```
or
```java readme-sample-createAsyncClientKeyCredential
ChatCompletionsAsyncClient client = new ChatCompletionsClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildAsyncClient();
```

#### Create a client with Azure Active Directory credential
Azure SDK for Java supports an Azure Identity package, making it easy to get credentials from Microsoft identity
platform.

Authentication with AAD requires some initial setup:
* Add the Azure Identity package

[//]: # ({x-version-update-start;com.azure:azure-identity;dependency})
```xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.13.1</version>
</dependency>
```
[//]: # ({x-version-update-end})

Authorization is easiest using [DefaultAzureCredential][wiki_identity]. It finds the best credential to use in its
running environment. For more information about using Azure Active Directory authorization with OpenAI service, please
refer to [the associated documentation][aad_authorization].

```java readme-sample-createChatCompletionsClientWithAAD
TokenCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
ChatCompletionsClient client = new ChatCompletionsClientBuilder()
.credential(defaultCredential)
.endpoint("{endpoint}")
.buildClient();
```

## Key concepts

## Examples
The following sections provide several code snippets covering some of the most common OpenAI service tasks, including:

* [Chat completions sample](#chat-completions "Chat completions")
* [Streaming chat completions sample](#streaming-chat-completions "Streaming chat completions")
<!--
* [Embeddings sample](#text-embeddings "Text Embeddings")
-->

## Examples

### Chat completions

```java readme-sample-getChatCompletions
List<ChatRequestMessage> chatMessages = new ArrayList<>();
chatMessages.add(new ChatRequestSystemMessage("You are a helpful assistant. You will talk like a pirate."));
chatMessages.add(new ChatRequestUserMessage("Can you help me?"));
chatMessages.add(new ChatRequestAssistantMessage("Of course, me hearty! What can I do for ye?"));
chatMessages.add(new ChatRequestUserMessage("What's the best way to train a parrot?"));

ChatCompletions chatCompletions = client.complete(new ChatCompletionsOptions(chatMessages));

System.out.printf("Model ID=%s is created at %s.%n", chatCompletions.getId(), chatCompletions.getCreated());
for (ChatChoice choice : chatCompletions.getChoices()) {
ChatResponseMessage message = choice.getMessage();
System.out.printf("Index: %d, Chat Role: %s.%n", choice.getIndex(), message.getRole());
System.out.println("Message:");
System.out.println(message.getContent());
}
```
For a complete sample example, see sample [Chat Completions][sample_get_chat_completions].

Please refer to the service documentation for a conceptual discussion of [text completion][microsoft_docs_openai_completion].

### Streaming chat completions

```java readme-sample-getChatCompletionsStream
List<ChatRequestMessage> chatMessages = new ArrayList<>();
chatMessages.add(new ChatRequestSystemMessage("You are a helpful assistant. You will talk like a pirate."));
chatMessages.add(new ChatRequestUserMessage("Can you help me?"));
chatMessages.add(new ChatRequestAssistantMessage("Of course, me hearty! What can I do for ye?"));
chatMessages.add(new ChatRequestUserMessage("What's the best way to train a parrot?"));

client.completeStream(new ChatCompletionsOptions(chatMessages))
.forEach(chatCompletions -> {
if (CoreUtils.isNullOrEmpty(chatCompletions.getChoices())) {
return;
}
StreamingChatResponseMessageUpdate delta = chatCompletions.getChoices().get(0).getDelta();
if (delta.getRole() != null) {
System.out.println("Role = " + delta.getRole());
}
if (delta.getContent() != null) {
String content = delta.getContent();
System.out.print(content);
}
});
```

To compute tokens in streaming chat completions, see sample [Streaming Chat Completions][sample_get_chat_completions_streaming].

<!--
### Text embeddings

```java readme-sample-getEmbedding
```
For a complete sample example, see sample [Embedding][sample_get_embedding].

Please refer to the service documentation for a conceptual discussion of [openAI embedding][microsoft_docs_openai_embedding].
-->

### Service API versions

The client library targets the latest service API version by default.
The service client builder accepts an optional service API version parameter to specify which API version to communicate.

#### Select a service API version

You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder.
This ensures that the client can communicate with services using the specified API version.

When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version.
If there are significant differences, API calls may fail due to incompatibility.

Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy.

## Troubleshooting
### Enable client logging
You can set the `AZURE_LOG_LEVEL` environment variable to view logging statements made in the client library. For
example, setting `AZURE_LOG_LEVEL=2` would show all informational, warning, and error log messages. The log levels can
be found here: [log levels][logLevels].

### Default HTTP Client
All client libraries by default use the Netty HTTP client. Adding the above dependency will automatically configure
the client library to use the Netty HTTP client. Configuring or changing the HTTP client is detailed in the
[HTTP clients wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Configure-HTTP-Clients).

### Default SSL library
All client libraries, by default, use the Tomcat-native Boring SSL library to enable native-level performance for SSL
operations. The Boring SSL library is an uber jar containing native libraries for Linux / macOS / Windows, and provides
better performance compared to the default SSL implementation within the JDK. For more information, including how to
reduce the dependency size, refer to the [performance tuning][performance_tuning] section of the wiki.

For more details, see [TROUBLESHOOTING][troubleshooting] guideline.

## Next steps

## Contributing

For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md).

1. Fork it
1. Create your feature branch (`git checkout -b my-new-feature`)
1. Commit your changes (`git commit -am 'Add some feature'`)
1. Push to the branch (`git push origin my-new-feature`)
1. Create new Pull Request

<!-- LINKS -->
[product_documentation]: https://azure.microsoft.com/services/
[docs]: https://azure.github.io/azure-sdk-for-java/
[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/
[aad_authorization]: https://docs.microsoft.com/azure/cognitive-services/authentication#authenticate-with-azure-active-directory
[azure_subscription]: https://azure.microsoft.com/free/
[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity
[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
[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
[microsoft_docs_openai_completion]: https://learn.microsoft.com/azure/cognitive-services/openai/how-to/completions
[microsoft_docs_openai_embedding]: https://learn.microsoft.com/azure/cognitive-services/openai/concepts/understand-embeddings
[chat_completions_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
[chat_completions_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
[chat_completions_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
[logLevels]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/core/azure-core/src/main/java/com/azure/core/util/logging/ClientLogger.java
[performance_tuning]: https://github.com/Azure/azure-sdk-for-java/wiki/Performance-Tuning
[troubleshooting]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/openai/azure-ai-openai/TROUBLESHOOTING.md
[wiki_identity]: https://learn.microsoft.com/azure/developer/java/sdk/identity

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fai%2Fazure-ai-inference%2FREADME.png)
Loading