Delete unused project OpenAI Client from the Java folder (#1392)

This is a follow up on the PR #1197
This commit is contained in:
Bruno Borges
2023-06-12 10:07:17 +01:00
committed by GitHub
parent 91e093757d
commit 9e404466a3
5 changed files with 0 additions and 285 deletions
-29
View File
@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.microsoft.semantickernel</groupId>
<artifactId>semantickernel-parent</artifactId>
<version>0.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>semantickernel-openai-client</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-openai</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
</dependencies>
</project>
@@ -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<Embeddings> getEmbeddings(
String deploymentId, EmbeddingsOptions embeddingsOptions) {
return delegate.getEmbeddings(deploymentId, embeddingsOptions);
}
@Override
public Mono<Completions> getCompletions(
String deploymentId, CompletionsOptions completionsOptions) {
return delegate.getCompletions(deploymentId, completionsOptions);
}
@Override
public Mono<ChatCompletions> getChatCompletions(
String deploymentId, ChatCompletionsOptions chatCompletionsOptions) {
return delegate.getChatCompletions(deploymentId, chatCompletionsOptions);
}
}
@@ -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<Embeddings> getEmbeddings(String deploymentId, EmbeddingsOptions embeddingsOptions);
Mono<Completions> getCompletions(String deploymentId, CompletionsOptions completionsOptions);
Mono<ChatCompletions> getChatCompletions(
String deploymentId, ChatCompletionsOptions chatCompletionsOptions);
}
@@ -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<Embeddings> 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<Completions> 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<ChatCompletions> 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<Response<BinaryData>> 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<Response<BinaryData>> 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<Response<BinaryData>> getChatCompletions(
@HostParam("endpoint") String endpoint,
@HeaderParam("accept") String accept,
@BodyParam("application/json") BinaryData chatCompletionsOptions,
RequestOptions requestOptions,
Context context);
}
}
@@ -1,22 +0,0 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.openai.client;
/** Builds an OpenAIClient for use with <a href="https://api.openai.com/v1">api.openai.com/v1</a> */
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);
}
}