Skip to content
Closed
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 eng/emitter-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"main": "dist/src/index.js",
"dependencies": {
"@azure-tools/typespec-java": "0.10.0"
"@azure-tools/typespec-java": "0.11.1"
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,32 @@
import java.util.Map;
import java.util.Objects;

/** A builder for creating a new instance of the OpenAIClient type. */
@ServiceClientBuilder(serviceClients = {OpenAIClient.class, OpenAIAsyncClient.class})
public final class OpenAIClientBuilder
implements HttpTrait<OpenAIClientBuilder>,
ConfigurationTrait<OpenAIClientBuilder>,
TokenCredentialTrait<OpenAIClientBuilder>,
KeyCredentialTrait<OpenAIClientBuilder>,
EndpointTrait<OpenAIClientBuilder> {
/**
* A builder for creating a new instance of the OpenAIClient type.
*/
@ServiceClientBuilder(serviceClients = { OpenAIClient.class, OpenAIAsyncClient.class })
public final class OpenAIClientBuilder implements HttpTrait<OpenAIClientBuilder>,
ConfigurationTrait<OpenAIClientBuilder>, TokenCredentialTrait<OpenAIClientBuilder>,
KeyCredentialTrait<OpenAIClientBuilder>, EndpointTrait<OpenAIClientBuilder> {

@Generated private static final String SDK_NAME = "name";
@Generated
private static final String SDK_NAME = "name";

@Generated private static final String SDK_VERSION = "version";
@Generated
private static final String SDK_VERSION = "version";

@Generated
private static final String[] DEFAULT_SCOPES = new String[] {"https://cognitiveservices.azure.com/.default"};
private static final String[] DEFAULT_SCOPES = new String[] { "https://cognitiveservices.azure.com/.default" };

@Generated
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-ai-openai.properties");

@Generated private final List<HttpPipelinePolicy> pipelinePolicies;
@Generated
private final List<HttpPipelinePolicy> pipelinePolicies;

/** Create an instance of the OpenAIClientBuilder. */
/**
* Create an instance of the OpenAIClientBuilder.
*/
@Generated
public OpenAIClientBuilder() {
this.pipelinePolicies = new ArrayList<>();
Expand All @@ -76,9 +80,12 @@ public OpenAIClientBuilder() {
/*
* The HTTP pipeline to send requests through.
*/
@Generated private HttpPipeline pipeline;
@Generated
private HttpPipeline pipeline;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder pipeline(HttpPipeline pipeline) {
Expand All @@ -92,9 +99,12 @@ public OpenAIClientBuilder pipeline(HttpPipeline pipeline) {
/*
* The HTTP client used to send the request.
*/
@Generated private HttpClient httpClient;
@Generated
private HttpClient httpClient;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder httpClient(HttpClient httpClient) {
Expand All @@ -105,9 +115,12 @@ public OpenAIClientBuilder httpClient(HttpClient httpClient) {
/*
* The logging configuration for HTTP requests and responses.
*/
@Generated private HttpLogOptions httpLogOptions;
@Generated
private HttpLogOptions httpLogOptions;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
Expand All @@ -118,9 +131,12 @@ public OpenAIClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
/*
* The client options such as application ID and custom headers to set on a request.
*/
@Generated private ClientOptions clientOptions;
@Generated
private ClientOptions clientOptions;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder clientOptions(ClientOptions clientOptions) {
Expand All @@ -131,17 +147,22 @@ public OpenAIClientBuilder clientOptions(ClientOptions clientOptions) {
/*
* The retry options to configure retry policy for failed requests.
*/
@Generated private RetryOptions retryOptions;
@Generated
private RetryOptions retryOptions;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder retryOptions(RetryOptions retryOptions) {
this.retryOptions = retryOptions;
return this;
}

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
Expand All @@ -153,9 +174,12 @@ public OpenAIClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
/*
* The configuration store that is used during construction of the service client.
*/
@Generated private Configuration configuration;
@Generated
private Configuration configuration;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder configuration(Configuration configuration) {
Expand All @@ -166,20 +190,27 @@ public OpenAIClientBuilder configuration(Configuration configuration) {
/*
* The TokenCredential used for authentication.
*/
@Generated private TokenCredential tokenCredential;
@Generated
private TokenCredential tokenCredential;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder credential(TokenCredential tokenCredential) {
this.tokenCredential = tokenCredential;
return this;
}

/** The KeyCredential used for OpenAi authentication. It could be either of Azure or Non-Azure OpenAI API key. */
/**
* The KeyCredential used for OpenAi authentication. It could be either of Azure or Non-Azure OpenAI API key.
*/
private KeyCredential keyCredential;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder credential(KeyCredential keyCredential) {
Expand All @@ -190,9 +221,12 @@ public OpenAIClientBuilder credential(KeyCredential keyCredential) {
/*
* The service endpoint
*/
@Generated private String endpoint;
@Generated
private String endpoint;

/** {@inheritDoc}. */
/**
* {@inheritDoc}.
*/
@Generated
@Override
public OpenAIClientBuilder endpoint(String endpoint) {
Expand All @@ -203,7 +237,8 @@ public OpenAIClientBuilder endpoint(String endpoint) {
/*
* Service version
*/
@Generated private OpenAIServiceVersion serviceVersion;
@Generated
private OpenAIServiceVersion serviceVersion;

/**
* Sets Service version.
Expand All @@ -220,7 +255,8 @@ public OpenAIClientBuilder serviceVersion(OpenAIServiceVersion serviceVersion) {
/*
* The retry policy that will attempt to retry failed requests, if applicable.
*/
@Generated private RetryPolicy retryPolicy;
@Generated
private RetryPolicy retryPolicy;

/**
* Sets The retry policy that will attempt to retry failed requests, if applicable.
Expand All @@ -242,20 +278,16 @@ public OpenAIClientBuilder retryPolicy(RetryPolicy retryPolicy) {
@Generated
private OpenAIClientImpl buildInnerClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
OpenAIServiceVersion localServiceVersion =
(serviceVersion != null) ? serviceVersion : OpenAIServiceVersion.getLatest();
OpenAIClientImpl client =
new OpenAIClientImpl(
localPipeline,
JacksonAdapter.createDefaultSerializerAdapter(),
this.endpoint,
localServiceVersion);
OpenAIServiceVersion localServiceVersion
= (serviceVersion != null) ? serviceVersion : OpenAIServiceVersion.getLatest();
OpenAIClientImpl client = new OpenAIClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(),
this.endpoint, localServiceVersion);
return client;
}

private HttpPipeline createHttpPipeline() {
Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
Configuration buildConfiguration
= (configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
List<HttpPipelinePolicy> policies = new ArrayList<>();
Expand All @@ -270,40 +302,32 @@ private HttpPipeline createHttpPipeline() {
if (headers.getSize() > 0) {
policies.add(new AddHeadersPolicy(headers));
}
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
.forEach(p -> policies.add(p));
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
policies.add(new AddDatePolicy());
policies.add(new CookiePolicy());
if (keyCredential != null) {
policies.add(
useNonAzureOpenAIService()
? new KeyCredentialPolicy("Authorization", keyCredential, "Bearer")
: new KeyCredentialPolicy("api-key", keyCredential));
policies.add(useNonAzureOpenAIService() ? new KeyCredentialPolicy("Authorization", keyCredential, "Bearer")
: new KeyCredentialPolicy("api-key", keyCredential));
}
if (tokenCredential != null) {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
}
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.forEach(p -> policies.add(p));
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline =
new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.clientOptions(localClientOptions)
.build();
HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient).clientOptions(localClientOptions).build();
return httpPipeline;
}

private NonAzureOpenAIClientImpl buildInnerNonAzureOpenAIClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
NonAzureOpenAIClientImpl client =
new NonAzureOpenAIClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter());
NonAzureOpenAIClientImpl client
= new NonAzureOpenAIClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter());
return client;
}

Expand All @@ -313,9 +337,8 @@ private NonAzureOpenAIClientImpl buildInnerNonAzureOpenAIClient() {
* @return an instance of OpenAIAsyncClient.
*/
public OpenAIAsyncClient buildAsyncClient() {
return useNonAzureOpenAIService()
? new OpenAIAsyncClient(buildInnerNonAzureOpenAIClient())
: new OpenAIAsyncClient(buildInnerClient());
return useNonAzureOpenAIService() ? new OpenAIAsyncClient(buildInnerNonAzureOpenAIClient())
: new OpenAIAsyncClient(buildInnerClient());
}

/**
Expand All @@ -324,9 +347,8 @@ public OpenAIAsyncClient buildAsyncClient() {
* @return an instance of OpenAIClient.
*/
public OpenAIClient buildClient() {
return useNonAzureOpenAIService()
? new OpenAIClient(buildInnerNonAzureOpenAIClient())
: new OpenAIClient(buildInnerClient());
return useNonAzureOpenAIService() ? new OpenAIClient(buildInnerNonAzureOpenAIClient())
: new OpenAIClient(buildInnerClient());
}

private static final ClientLogger LOGGER = new ClientLogger(OpenAIClientBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,38 @@

import com.azure.core.util.ServiceVersion;

/** Service version of OpenAIClient. */
/**
* Service version of OpenAIClient.
*/
public enum OpenAIServiceVersion implements ServiceVersion {
/** Enum value 2022-12-01. */
/**
* Enum value 2022-12-01.
*/
V2022_12_01("2022-12-01"),

/** Enum value 2023-05-15. */
/**
* Enum value 2023-05-15.
*/
V2023_05_15("2023-05-15"),

/** Enum value 2023-06-01-preview. */
/**
* Enum value 2023-06-01-preview.
*/
V2023_06_01_PREVIEW("2023-06-01-preview"),

/** Enum value 2023-07-01-preview. */
/**
* Enum value 2023-07-01-preview.
*/
V2023_07_01_PREVIEW("2023-07-01-preview"),

/** Enum value 2023-08-01-preview. */
/**
* Enum value 2023-08-01-preview.
*/
V2023_08_01_PREVIEW("2023-08-01-preview"),

/** Enum value 2023-09-01-preview. */
/**
* Enum value 2023-09-01-preview.
*/
V2023_09_01_PREVIEW("2023-09-01-preview");

private final String version;
Expand All @@ -32,15 +46,17 @@ public enum OpenAIServiceVersion implements ServiceVersion {
this.version = version;
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*/
@Override
public String getVersion() {
return this.version;
}

/**
* Gets the latest service version supported by this client library.
*
*
* @return The latest {@link OpenAIServiceVersion}.
*/
public static OpenAIServiceVersion getLatest() {
Expand Down
Loading