From 9e404466a3ffbd0df2ec9f73c291091538f32c75 Mon Sep 17 00:00:00 2001 From: Bruno Borges Date: Mon, 12 Jun 2023 02:07:17 -0700 Subject: [PATCH] Delete unused project OpenAI Client from the Java folder (#1392) This is a follow up on the PR #1197 --- java/semantickernel-openai-client/pom.xml | 29 --- .../openai/client/AzureOpenAIClient.java | 36 ---- .../openai/client/OpenAIAsyncClient.java | 16 -- .../openai/client/OpenAIAsyncClientImpl.java | 182 ------------------ .../openai/client/OpenAIClientBuilder.java | 22 --- 5 files changed, 285 deletions(-) delete mode 100644 java/semantickernel-openai-client/pom.xml delete mode 100644 java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/AzureOpenAIClient.java delete mode 100644 java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClient.java delete mode 100644 java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClientImpl.java delete mode 100644 java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIClientBuilder.java diff --git a/java/semantickernel-openai-client/pom.xml b/java/semantickernel-openai-client/pom.xml deleted file mode 100644 index 1d615fad80..0000000000 --- a/java/semantickernel-openai-client/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - 4.0.0 - - - com.microsoft.semantickernel - semantickernel-parent - 0.2.0-SNAPSHOT - ../pom.xml - - - semantickernel-openai-client - jar - - - - com.azure - azure-ai-openai - - - io.projectreactor - reactor-core - - - - \ No newline at end of file diff --git a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/AzureOpenAIClient.java b/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/AzureOpenAIClient.java deleted file mode 100644 index 7cc2bb3005..0000000000 --- a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/AzureOpenAIClient.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.openai.client; - -import com.azure.ai.openai.models.*; - -import reactor.core.publisher.Mono; - -/** - * Create an OpenAIAsyncClient that delegates to an com.azure.ai.openai.OpenAIAsyncClient provided - * by com.azure:azure-ai-openai - */ -public class AzureOpenAIClient implements OpenAIAsyncClient { - private final com.azure.ai.openai.OpenAIAsyncClient delegate; - - public AzureOpenAIClient(com.azure.ai.openai.OpenAIAsyncClient delegate) { - this.delegate = delegate; - } - - @Override - public Mono getEmbeddings( - String deploymentId, EmbeddingsOptions embeddingsOptions) { - return delegate.getEmbeddings(deploymentId, embeddingsOptions); - } - - @Override - public Mono getCompletions( - String deploymentId, CompletionsOptions completionsOptions) { - return delegate.getCompletions(deploymentId, completionsOptions); - } - - @Override - public Mono getChatCompletions( - String deploymentId, ChatCompletionsOptions chatCompletionsOptions) { - return delegate.getChatCompletions(deploymentId, chatCompletionsOptions); - } -} diff --git a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClient.java b/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClient.java deleted file mode 100644 index e0a4386973..0000000000 --- a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClient.java +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.openai.client; - -import com.azure.ai.openai.models.*; - -import reactor.core.publisher.Mono; - -/** Interface for an OpenAI client */ -public interface OpenAIAsyncClient { - Mono getEmbeddings(String deploymentId, EmbeddingsOptions embeddingsOptions); - - Mono getCompletions(String deploymentId, CompletionsOptions completionsOptions); - - Mono getChatCompletions( - String deploymentId, ChatCompletionsOptions chatCompletionsOptions); -} diff --git a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClientImpl.java b/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClientImpl.java deleted file mode 100644 index e93c89bba0..0000000000 --- a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIAsyncClientImpl.java +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.openai.client; - -import com.azure.ai.openai.models.*; -import com.azure.core.annotation.*; -import com.azure.core.exception.ClientAuthenticationException; -import com.azure.core.exception.HttpResponseException; -import com.azure.core.exception.ResourceModifiedException; -import com.azure.core.exception.ResourceNotFoundException; -import com.azure.core.http.HttpHeaderName; -import com.azure.core.http.HttpPipeline; -import com.azure.core.http.HttpPipelineBuilder; -import com.azure.core.http.policy.CookiePolicy; -import com.azure.core.http.policy.RetryPolicy; -import com.azure.core.http.policy.UserAgentPolicy; -import com.azure.core.http.rest.RequestOptions; -import com.azure.core.http.rest.Response; -import com.azure.core.http.rest.RestProxy; -import com.azure.core.util.*; -import com.azure.core.util.serializer.JacksonAdapter; -import com.azure.core.util.serializer.SerializerAdapter; - -import reactor.core.publisher.Mono; - -class OpenAIAsyncClientImpl implements OpenAIAsyncClient { - private final OpenAIClientService service; - private final String endpoint; - - public String getEndpoint() { - return this.endpoint; - } - - private final SerializerAdapter serializerAdapter; - - public SerializerAdapter getSerializerAdapter() { - return this.serializerAdapter; - } - - private String apiKey; - - public OpenAIAsyncClientImpl(String endpoint, String apiKey) { - this( - new HttpPipelineBuilder() - .policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy()) - .build(), - JacksonAdapter.createDefaultSerializerAdapter(), - endpoint); - this.apiKey = apiKey; - } - - public OpenAIAsyncClientImpl( - HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) { - this.serializerAdapter = serializerAdapter; - this.endpoint = endpoint; - this.service = - RestProxy.create( - OpenAIClientService.class, httpPipeline, this.getSerializerAdapter()); - } - - @Override - public Mono getEmbeddings( - String deploymentId, EmbeddingsOptions embeddingsOptions) { - final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.getEmbeddings( - this.getEndpoint(), - accept, - BinaryData.fromObject(embeddingsOptions), - new RequestOptions() - .addHeader( - HttpHeaderName.AUTHORIZATION, - "Bearer " + this.apiKey), - context)) - .flatMap(FluxUtil::toMono) - .map(protocolMethodData -> protocolMethodData.toObject(Embeddings.class)); - } - - @Override - public Mono getCompletions( - String deploymentId, CompletionsOptions completionsOptions) { - final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.getCompletions( - this.getEndpoint(), - accept, - BinaryData.fromObject(completionsOptions), - new RequestOptions() - .addHeader( - HttpHeaderName.AUTHORIZATION, - "Bearer " + this.apiKey), - context)) - .flatMap(FluxUtil::toMono) - .map(protocolMethodData -> protocolMethodData.toObject(Completions.class)); - } - - @Override - public Mono getChatCompletions( - String deploymentId, ChatCompletionsOptions chatCompletionsOptions) { - final String accept = "application/json"; - return FluxUtil.withContext( - context -> - service.getChatCompletions( - this.getEndpoint(), - accept, - BinaryData.fromObject(chatCompletionsOptions), - new RequestOptions() - .addHeader( - HttpHeaderName.AUTHORIZATION, - "Bearer " + this.apiKey), - context)) - .flatMap(FluxUtil::toMono) - .map(protocolMethodData -> protocolMethodData.toObject(ChatCompletions.class)); - } - - /** - * The interface defining all the services for OpenAIAPI to be used by the proxy service to - * perform REST calls. - */ - @Host("{endpoint}") - @ServiceInterface(name = "OpenAIClient") - public interface OpenAIClientService { - - @Post("/embeddings") - @ExpectedResponses({200}) - @UnexpectedResponseExceptionType( - value = ClientAuthenticationException.class, - code = {401}) - @UnexpectedResponseExceptionType( - value = ResourceNotFoundException.class, - code = {404}) - @UnexpectedResponseExceptionType( - value = ResourceModifiedException.class, - code = {409}) - @UnexpectedResponseExceptionType(HttpResponseException.class) - Mono> getEmbeddings( - @HostParam("endpoint") String endpoint, - @HeaderParam("accept") String accept, - @BodyParam("application/json") BinaryData embeddingsOptions, - RequestOptions requestOptions, - Context context); - - @Post("/completions") - @ExpectedResponses({200}) - @UnexpectedResponseExceptionType( - value = ClientAuthenticationException.class, - code = {401}) - @UnexpectedResponseExceptionType( - value = ResourceNotFoundException.class, - code = {404}) - @UnexpectedResponseExceptionType( - value = ResourceModifiedException.class, - code = {409}) - @UnexpectedResponseExceptionType(HttpResponseException.class) - Mono> getCompletions( - @HostParam("endpoint") String endpoint, - @HeaderParam("accept") String accept, - @BodyParam("application/json") BinaryData completionsOptions, - RequestOptions requestOptions, - Context context); - - @Post("/chat/completions") - @ExpectedResponses({200}) - @UnexpectedResponseExceptionType( - value = ClientAuthenticationException.class, - code = {401}) - @UnexpectedResponseExceptionType( - value = ResourceNotFoundException.class, - code = {404}) - @UnexpectedResponseExceptionType( - value = ResourceModifiedException.class, - code = {409}) - @UnexpectedResponseExceptionType(HttpResponseException.class) - Mono> getChatCompletions( - @HostParam("endpoint") String endpoint, - @HeaderParam("accept") String accept, - @BodyParam("application/json") BinaryData chatCompletionsOptions, - RequestOptions requestOptions, - Context context); - } -} diff --git a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIClientBuilder.java b/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIClientBuilder.java deleted file mode 100644 index d31e3830e5..0000000000 --- a/java/semantickernel-openai-client/src/main/java/com/microsoft/semantickernel/openai/client/OpenAIClientBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.openai.client; - -/** Builds an OpenAIClient for use with api.openai.com/v1 */ -public final class OpenAIClientBuilder { - private String endpoint = "https://api.openai.com/v1"; - private String apiKey; - - public OpenAIClientBuilder setApiKey(String apiKey) { - this.apiKey = apiKey; - return this; - } - - public OpenAIClientBuilder setEndpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public OpenAIAsyncClient build() { - return new OpenAIAsyncClientImpl(endpoint, apiKey); - } -}