Skip to content

Commit 867d0d6

Browse files
committed
Always using default httpPipeline
1 parent 7c95643 commit 867d0d6

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/AgentsClientBuilder.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,10 @@ private OpenAIOkHttpClient.Builder getOpenAIClientBuilder() {
387387
.credential(
388388
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
389389
builder.baseUrl(this.endpoint + (this.endpoint.endsWith("/") ? "openai" : "/openai"));
390-
builder.replaceHeaders("User-Agent", getUserAgent());
391390
if (this.serviceVersion != null) {
392391
builder.azureServiceVersion(AzureOpenAIServiceVersion.fromString(this.serviceVersion.getVersion()));
393392
builder.azureUrlPathMode(AzureUrlPathMode.UNIFIED);
394393
}
395-
builder.timeout(Duration.ofSeconds(30));
396394
return builder;
397395
}
398396

@@ -401,37 +399,15 @@ private OpenAIOkHttpClientAsync.Builder getOpenAIAsyncClientBuilder() {
401399
.credential(
402400
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
403401
builder.baseUrl(this.endpoint + (this.endpoint.endsWith("/") ? "openai" : "/openai"));
404-
builder.replaceHeaders("User-Agent", getUserAgent());
405402
if (this.serviceVersion != null) {
406403
builder.azureServiceVersion(AzureOpenAIServiceVersion.fromString(this.serviceVersion.getVersion()));
407404
builder.azureUrlPath(AzureUrlPathMode.UNIFIED);
408405
}
409-
builder.timeout(Duration.ofSeconds(30));
410406
return builder;
411407
}
412408

413-
private String getUserAgent() {
414-
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions;
415-
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions;
416-
String sdkName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName");
417-
String sdkVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
418-
String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions);
419-
return UserAgentUtil.toUserAgentString(applicationId, sdkName, sdkVersion, configuration);
420-
}
421-
422409
private HttpClient getOpenAIHttpClient() {
423-
if (this.httpClient == null) {
424-
return null;
425-
}
426-
return new PolicyDecoratingHttpClient(this.httpClient, getOrderedCustomPolicies());
427-
}
428-
429-
private List<HttpPipelinePolicy> getOrderedCustomPolicies() {
430-
return this.pipelinePolicies.stream()
431-
.sorted(Comparator.comparing(policy -> HttpPipelinePosition.PER_CALL == policy.getPipelinePosition()
432-
? HttpPipelinePosition.PER_CALL
433-
: HttpPipelinePosition.PER_CALL))
434-
.collect(Collectors.toList());
410+
return new PolicyDecoratingHttpClient(createHttpPipeline());
435411
}
436412

437413
private static final ClientLogger LOGGER = new ClientLogger(AgentsClientBuilder.class);

sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/implementation/http/HttpClientHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static BinaryData toBinaryData(HttpRequestBody requestBody) {
154154
if (requestBody == null) {
155155
return null;
156156
}
157-
157+
158158
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
159159
requestBody.writeTo(outputStream);
160160
return BinaryData.fromBytes(outputStream.toByteArray());

sdk/ai/azure-ai-agents/src/main/java/com/azure/ai/agents/implementation/http/PolicyDecoratingHttpClient.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
public final class PolicyDecoratingHttpClient implements HttpClient {
2424

25-
private final HttpClient delegate;
25+
// private final HttpClient delegate;
2626
private final HttpPipeline pipeline;
2727

2828
/**
@@ -31,17 +31,21 @@ public final class PolicyDecoratingHttpClient implements HttpClient {
3131
* @param delegate Underlying HTTP client that performs the actual network I/O.
3232
* @param policies Policies that should run before the request reaches the delegate.
3333
*/
34+
@Deprecated(forRemoval = true)
3435
public PolicyDecoratingHttpClient(HttpClient delegate, List<HttpPipelinePolicy> policies) {
35-
this.delegate = Objects.requireNonNull(delegate, "delegate cannot be null");
36-
Objects.requireNonNull(policies, "policies cannot be null");
36+
Objects.requireNonNull(delegate, "delegate cannot be null");
3737

38-
HttpPipelineBuilder builder = new HttpPipelineBuilder().httpClient(this.delegate);
39-
if (!policies.isEmpty()) {
38+
HttpPipelineBuilder builder = new HttpPipelineBuilder().httpClient(delegate);
39+
if (policies == null || !policies.isEmpty()) {
4040
builder.policies(policies.toArray(new HttpPipelinePolicy[0]));
4141
}
4242
this.pipeline = builder.build();
4343
}
4444

45+
public PolicyDecoratingHttpClient(HttpPipeline httpPipeline) {
46+
this.pipeline = httpPipeline;
47+
}
48+
4549
/**
4650
* Sends the request using the decorated pipeline without a custom {@link Context}.
4751
*/

0 commit comments

Comments
 (0)