Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ public OpenAIClient buildOpenAIClient() {
* @return an instance of OpenAIClient
* @throws IllegalArgumentException if agentName is null or empty.
*/
public OpenAIClient buildOpenAIClient(String agentName) {
Objects.requireNonNull(agentName, "'agentName' cannot be null.");
if (agentName.isEmpty()) {
public OpenAIClient buildAgentScopedOpenAIClient(String agentName) {
if (CoreUtils.isNullOrEmpty(agentName)) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'agentName' cannot be empty."));
}
return getOpenAIClientBuilder(agentName).build()
Expand Down Expand Up @@ -397,30 +396,30 @@ public OpenAIClientAsync buildOpenAIAsyncClient() {
* @return an instance of OpenAIAsyncClient
* @throws IllegalArgumentException if agentName is null or empty.
*/
public OpenAIClientAsync buildOpenAIAsyncClient(String agentName) {
Objects.requireNonNull(agentName, "'agentName' cannot be null.");
if (agentName.isEmpty()) {
public OpenAIClientAsync buildAgentScopedOpenAIAsyncClient(String agentName) {
if (CoreUtils.isNullOrEmpty(agentName)) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'agentName' cannot be empty."));
}
return getOpenAIAsyncClientBuilder(agentName).build()
.withOptions(optionBuilder -> optionBuilder
.httpClient(HttpClientHelper.mapToOpenAIHttpClient(createHttpPipeline())));
}

private String getOpenAIBaseUrl(String agentName) {
private String getDefaultBaseUrl() {
return this.endpoint + (this.endpoint.endsWith("/") ? "openai/v1" : "/openai/v1");
}

private String getAgentEndpointBaseUrl(String agentName) {
String base
= this.endpoint.endsWith("/") ? this.endpoint.substring(0, this.endpoint.length() - 1) : this.endpoint;
if (agentName != null) {
return base + "/agents/" + agentName + "/endpoint/protocols/openai";
}
return base + "/openai/v1";
return base + "/agents/" + agentName + "/endpoint/protocols/openai";
}

private OpenAIOkHttpClient.Builder getOpenAIClientBuilder(String agentName) {
OpenAIOkHttpClient.Builder builder = OpenAIOkHttpClient.builder()
.credential(
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
builder.baseUrl(getOpenAIBaseUrl(agentName));
builder.baseUrl(CoreUtils.isNullOrEmpty(agentName) ? getDefaultBaseUrl() : getAgentEndpointBaseUrl(agentName));
// We set the builder retries to 0 to avoid conflicts with the retry policy added through the HttpPipeline.
builder.maxRetries(0);
return builder;
Expand All @@ -430,7 +429,7 @@ private OpenAIOkHttpClientAsync.Builder getOpenAIAsyncClientBuilder(String agent
OpenAIOkHttpClientAsync.Builder builder = OpenAIOkHttpClientAsync.builder()
.credential(
BearerTokenCredential.create(TokenUtils.getBearerTokenSupplier(this.tokenCredential, DEFAULT_SCOPES)));
builder.baseUrl(getOpenAIBaseUrl(agentName));
builder.baseUrl(CoreUtils.isNullOrEmpty(agentName) ? getDefaultBaseUrl() : getAgentEndpointBaseUrl(agentName));
// We set the builder retries to 0 to avoid conflicts with the retry policy added through the HttpPipeline.
builder.maxRetries(0);
return builder;
Expand Down