Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AI] [Inference] - beta 3 changes #43994

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-inference/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/ai/azure-ai-inference",
"Tag" : "java/ai/azure-ai-inference_47913ffcfa"
"Tag" : "java/ai/azure-ai-inference_52ef84b599"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class InferenceCustomizations extends Customization {
@Override
public void customize(LibraryCustomization customization, Logger logger) {
// remove unused class (no reference to them, after partial-update)
customization.getRawEditor().removeFile("src/main/java/com/azure/ai/inference/implementation/models/CompleteOptions.java");
customization.getRawEditor().removeFile("src/main/java/com/azure/ai/inference/implementation/models/ChatCompletionsOptions.java");
PackageCustomization implModels = customization.getPackage("com.azure.ai.inference.implementation.models");
ClassCustomization embedRequest1 = implModels.getClass("EmbedRequest1");
embedRequest1.rename("ImageEmbedRequest");
customizeChatCompletionsBaseClasses(customization, logger);
}

private void customizeChatCompletionsBaseClasses(LibraryCustomization customization, Logger logger) {
List<String> classList = Arrays.asList("ChatCompletionsNamedToolSelection", "ChatCompletionsToolCall", "ChatCompletionsToolDefinition");
List<String> classList = Arrays.asList("ChatCompletionsNamedToolChoice", "ChatCompletionsToolCall", "ChatCompletionsToolDefinition");
for (String className : classList) {
logger.info("Customizing the {} class", className);
ClassCustomization namedToolSelectionClass = customization.getPackage("com.azure.ai.inference.models").getClass(className);
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-inference/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<Match>
<Bug pattern="SS_SHOULD_BE_STATIC" />
<Or>
<Class name="com.azure.ai.inference.models.ChatCompletionsNamedToolSelection" />
<Class name="com.azure.ai.inference.models.ChatCompletionsNamedToolChoice" />
<Class name="com.azure.ai.inference.models.ChatCompletionsToolCall" />
<Class name="com.azure.ai.inference.models.ChatCompletionsToolDefinition" />
</Or>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Mono<Response<BinaryData>> completeWithResponse(BinaryData completeReque
* {@code
* {
* model_name: String (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat) (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat_completion) (Required)
* model_provider_name: String (Required)
* }
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Response<BinaryData> completeWithResponse(BinaryData completeRequest, Req
* {@code
* {
* model_name: String (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat) (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat_completion) (Required)
* model_provider_name: String (Required)
* }
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public final class EmbeddingsAsyncClient {
* <pre>
* {@code
* {
* id: String (Required)
* data (Required): [
* (Required){
* embedding: BinaryData (Required)
Expand All @@ -98,7 +99,7 @@ public final class EmbeddingsAsyncClient {
* }
* </pre>
*
* @param embedRequest The embedRequest parameter.
* @param body request options to pass to the endpoint using embeddings path.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
Expand All @@ -111,8 +112,8 @@ public final class EmbeddingsAsyncClient {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<Response<BinaryData>> embedWithResponse(BinaryData embedRequest, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponseAsync(embedRequest, requestOptions);
Mono<Response<BinaryData>> embedWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponseAsync(body, requestOptions);
}

/**
Expand All @@ -124,7 +125,7 @@ Mono<Response<BinaryData>> embedWithResponse(BinaryData embedRequest, RequestOpt
* {@code
* {
* model_name: String (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat) (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat_completion) (Required)
* model_provider_name: String (Required)
* }
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public final class EmbeddingsClient {
* <pre>
* {@code
* {
* id: String (Required)
* data (Required): [
* (Required){
* embedding: BinaryData (Required)
Expand All @@ -96,7 +97,7 @@ public final class EmbeddingsClient {
* }
* </pre>
*
* @param embedRequest The embedRequest parameter.
* @param body request options to pass to the endpoint using embeddings path.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
Expand All @@ -108,8 +109,8 @@ public final class EmbeddingsClient {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Response<BinaryData> embedWithResponse(BinaryData embedRequest, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponse(embedRequest, requestOptions);
Response<BinaryData> embedWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponse(body, requestOptions);
}

/**
Expand All @@ -121,7 +122,7 @@ Response<BinaryData> embedWithResponse(BinaryData embedRequest, RequestOptions r
* {@code
* {
* model_name: String (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat) (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat_completion) (Required)
* model_provider_name: String (Required)
* }
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public EmbeddingsClientBuilder credential(TokenCredential tokenCredential) {
* Sets auth domain scopes for client authentication.
*
* @param scopes domain scope to authenticate against.
* @return the ChatCompletionsClientBuilder.
* @return the EmbeddingsClientBuilder.
*/
public EmbeddingsClientBuilder scopes(String[] scopes) {
this.scopes = scopes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package com.azure.ai.inference;

import com.azure.ai.inference.implementation.ImageEmbeddingsClientImpl;
import com.azure.ai.inference.implementation.models.EmbedRequest;
import com.azure.ai.inference.implementation.models.ImageEmbedRequest;
import com.azure.ai.inference.models.EmbeddingEncodingFormat;
import com.azure.ai.inference.models.EmbeddingInput;
import com.azure.ai.inference.models.EmbeddingInputType;
import com.azure.ai.inference.models.EmbeddingsResult;
import com.azure.ai.inference.models.ExtraParameters;
import com.azure.ai.inference.models.ImageEmbeddingInput;
import com.azure.ai.inference.models.ModelInfo;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
Expand All @@ -24,9 +23,10 @@
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.core.util.FluxUtil;
import java.util.List;
import reactor.core.publisher.Mono;

import java.util.List;

/**
* Initializes a new instance of the asynchronous ImageEmbeddingsClient type.
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ public final class ImageEmbeddingsAsyncClient {
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
*
* <pre>
* {@code
* {
Expand All @@ -80,12 +80,13 @@ public final class ImageEmbeddingsAsyncClient {
* }
* }
* </pre>
*
*
* <p><strong>Response Body Schema</strong></p>
*
*
* <pre>
* {@code
* {
* id: String (Required)
* data (Required): [
* (Required){
* embedding: BinaryData (Required)
Expand All @@ -101,7 +102,7 @@ public final class ImageEmbeddingsAsyncClient {
* }
* </pre>
*
* @param embedRequest1 The embedRequest1 parameter.
* @param body request options to pass to the endpoint using images embeddings path.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
Expand All @@ -114,20 +115,20 @@ public final class ImageEmbeddingsAsyncClient {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<Response<BinaryData>> embedWithResponse(BinaryData embedRequest1, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponseAsync(embedRequest1, requestOptions);
Mono<Response<BinaryData>> embedWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.embedWithResponseAsync(body, requestOptions);
}

/**
* Returns information about the AI model.
* The method makes a REST API call to the `/info` route on the given endpoint.
* <p><strong>Response Body Schema</strong></p>
*
*
* <pre>
* {@code
* {
* model_name: String (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat) (Required)
* model_type: String(embeddings/image_generation/text_generation/image_embeddings/audio_generation/chat_completion) (Required)
* model_provider_name: String (Required)
* }
* }
Expand All @@ -148,32 +149,34 @@ Mono<Response<BinaryData>> getModelInfoWithResponse(RequestOptions requestOption
}

/**
* Return the embedding vectors for given images.
* The method makes a REST API call to the `/images/embeddings` route on the given endpoint.
* Return the embedding vectors for given text prompts.
* The method makes a REST API call to the `/embeddings` route on the given endpoint.
*
* @param input Input image to embed. To embed multiple inputs in a single request, pass an array.
* The input must not exceed the max input tokens for the model.
* @param input Inputs, instances of ImageEmbeddingsInput.
* To embed multiple inputs in a single request, pass an array
* of strings or array of token arrays.
* @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 representation of the response data from an embeddings request.
* Embeddings measure the relatedness of text strings and are commonly used for search, clustering,
* Image embeddings measure the relatedness of images and are commonly used for search, clustering,
* recommendations, and other similar scenarios on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<EmbeddingsResult> embed(List<EmbeddingInput> input) {
public Mono<EmbeddingsResult> embed(List<ImageEmbeddingInput> input) {
// Generated convenience method for embedWithResponse
RequestOptions requestOptions = new RequestOptions();
ImageEmbedRequest embedRequest1Obj = new ImageEmbedRequest(input);
BinaryData embedRequest1 = BinaryData.fromObject(embedRequest1Obj);
return embedWithResponse(embedRequest1, requestOptions).flatMap(FluxUtil::toMono)
ImageEmbedRequest embedRequestObj = new ImageEmbedRequest(input);
BinaryData embedRequest = BinaryData.fromObject(embedRequestObj);
return embedWithResponse(embedRequest, requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(EmbeddingsResult.class));
}

/**

/**
* Returns information about the AI model.
* The method makes a REST API call to the `/info` route on the given endpoint.
Expand All @@ -198,20 +201,10 @@ Mono<ModelInfo> getModelInfo() {
* Return the embedding vectors for given images.
* The method makes a REST API call to the `/images/embeddings` route on the given endpoint.
*
* @param input Input image to embed. To embed multiple inputs in a single request, pass an array.
* The input must not exceed the max input tokens for the model.
* @param body request options to pass to the endpoint using images embeddings path.
* @param extraParams Controls what happens if extra parameters, undefined by the REST API,
* are passed in the JSON request payload.
* This sets the HTTP request header `extra-parameters`.
* @param dimensions Optional. The number of dimensions the resulting output embeddings should have.
* Passing null causes the model to use its default value.
* Returns a 422 error if the model doesn't support the value or parameter.
* @param encodingFormat Optional. The number of dimensions the resulting output embeddings should have.
* Passing null causes the model to use its default value.
* Returns a 422 error if the model doesn't support the value or parameter.
* @param inputType Optional. The type of the input.
* Returns a 422 error if the model doesn't support the value or parameter.
* @param model ID of the specific AI model to use, if more than one model is available on the endpoint.
* @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.
Expand All @@ -224,19 +217,37 @@ Mono<ModelInfo> getModelInfo() {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<EmbeddingsResult> embed(List<EmbeddingInput> input, ExtraParameters extraParams, Integer dimensions,
EmbeddingEncodingFormat encodingFormat, EmbeddingInputType inputType, String model) {
Mono<EmbeddingsResult> embed(ImageEmbedRequest body, ExtraParameters extraParams) {
// Generated convenience method for embedWithResponse
RequestOptions requestOptions = new RequestOptions();
ImageEmbedRequest embedRequest1Obj = new ImageEmbedRequest(input).setDimensions(dimensions)
.setEncodingFormat(encodingFormat)
.setInputType(inputType)
.setModel(model);
BinaryData embedRequest1 = BinaryData.fromObject(embedRequest1Obj);
if (extraParams != null) {
requestOptions.setHeader(HttpHeaderName.fromString("extra-parameters"), extraParams.toString());
}
return embedWithResponse(embedRequest1, requestOptions).flatMap(FluxUtil::toMono)
return embedWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(EmbeddingsResult.class));
}

/**
* Return the embedding vectors for given images.
* The method makes a REST API call to the `/images/embeddings` route on the given endpoint.
*
* @param body request options to pass to the endpoint using images embeddings path.
* @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 representation of the response data from an embeddings request.
* Embeddings measure the relatedness of text strings and are commonly used for search, clustering,
* recommendations, and other similar scenarios on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
Mono<EmbeddingsResult> embed(ImageEmbedRequest body) {
// Generated convenience method for embedWithResponse
RequestOptions requestOptions = new RequestOptions();
return embedWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(EmbeddingsResult.class));
}
}
Loading
Loading