Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.aiservices.openai;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.microsoft.semantickernel.services.AIService;
import javax.annotation.Nullable;

/**
* Provides OpenAI service.
*/
public abstract class OpenAiService implements AIService {
public abstract class OpenAiService<Client> implements AIService {

private final OpenAIAsyncClient client;
private final Client client;
@Nullable
private final String serviceId;
private final String modelId;
private final String deploymentName;

protected OpenAiService(
OpenAIAsyncClient client,
Client client,
@Nullable String serviceId,
String modelId,
String deploymentName) {
Expand All @@ -39,7 +38,7 @@ public String getServiceId() {
return serviceId;
}

protected OpenAIAsyncClient getClient() {
protected Client getClient() {
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Provides OpenAi implementation of audio to text service.
*/
public class OpenAiAudioToTextService extends OpenAiService implements AudioToTextService {
public class OpenAiAudioToTextService extends OpenAiService<OpenAIAsyncClient> implements AudioToTextService {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenAiAudioToTextService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Provides OpenAi implementation of text to audio service.
*/
public class OpenAiTextToAudioService extends OpenAiService implements TextToAudioService {
public class OpenAiTextToAudioService extends OpenAiService<OpenAIAsyncClient> implements TextToAudioService {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenAiTextToAudioService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
/**
* OpenAI chat completion service.
*/
public class OpenAIChatCompletion extends OpenAiService implements ChatCompletionService {
public class OpenAIChatCompletion extends OpenAiService<OpenAIAsyncClient> implements ChatCompletionService {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenAIChatCompletion.class);

Expand Down Expand Up @@ -1044,7 +1044,7 @@ static ChatRequestMessage getChatRequestMessage(
/**
* Builder for creating a new instance of {@link OpenAIChatCompletion}.
*/
public static class Builder extends OpenAiServiceBuilder<OpenAIChatCompletion, Builder> {
public static class Builder extends OpenAiServiceBuilder<OpenAIAsyncClient, OpenAIChatCompletion, Builder> {

@Override
public OpenAIChatCompletion build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* An OpenAI implementation of a {@link TextGenerationService}.
*/
public class OpenAITextGenerationService extends OpenAiService implements TextGenerationService {
public class OpenAITextGenerationService extends OpenAiService<OpenAIAsyncClient> implements TextGenerationService {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenAITextGenerationService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* An OpenAI implementation of a {@link TextEmbeddingGenerationService}.
*
*/
public class OpenAITextEmbeddingGenerationService extends OpenAiService
public class OpenAITextEmbeddingGenerationService extends OpenAiService<OpenAIAsyncClient>
implements TextEmbeddingGenerationService {
private static final Logger LOGGER = LoggerFactory
.getLogger(OpenAITextEmbeddingGenerationService.class);
Expand Down Expand Up @@ -87,7 +87,7 @@ protected Mono<List<Embedding>> internalGenerateTextEmbeddingsAsync(List<String>
* A builder for creating a {@link OpenAITextEmbeddingGenerationService}.
*/
public static class Builder extends
OpenAiServiceBuilder<OpenAITextEmbeddingGenerationService, OpenAITextEmbeddingGenerationService.Builder> {
OpenAiServiceBuilder<OpenAIAsyncClient, OpenAITextEmbeddingGenerationService, OpenAITextEmbeddingGenerationService.Builder> {
private int dimensions = DEFAULT_DIMENSIONS;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services.audio;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.microsoft.semantickernel.implementation.ServiceLoadUtil;
import com.microsoft.semantickernel.services.AIService;
import com.microsoft.semantickernel.services.openai.OpenAiServiceBuilder;
Expand Down Expand Up @@ -32,7 +33,7 @@ static Builder builder() {
/**
* Builder for the AudioToTextService.
*/
abstract class Builder extends OpenAiServiceBuilder<AudioToTextService, Builder> {
abstract class Builder extends OpenAiServiceBuilder<OpenAIAsyncClient, AudioToTextService, Builder> {

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services.audio;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.microsoft.semantickernel.implementation.ServiceLoadUtil;
import com.microsoft.semantickernel.services.AIService;
import com.microsoft.semantickernel.services.openai.OpenAiServiceBuilder;
Expand Down Expand Up @@ -36,7 +37,7 @@ static Builder builder() {
* Builder for the TextToAudioService.
*/
abstract class Builder extends
OpenAiServiceBuilder<TextToAudioService, Builder> {
OpenAiServiceBuilder<OpenAIAsyncClient, TextToAudioService, Builder> {

}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services.openai;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.microsoft.semantickernel.services.AIService;
import com.microsoft.semantickernel.builders.SemanticKernelBuilder;
import javax.annotation.Nullable;

/**
* Builder for an OpenAI service.
*/
public abstract class OpenAiServiceBuilder<T, U extends OpenAiServiceBuilder<T, U>> implements
* @param <C> The client type
* @param <T> The service type
* @param <U> The builder type
*/
public abstract class OpenAiServiceBuilder<C, T extends AIService, U extends OpenAiServiceBuilder<C, T, U>> implements

SemanticKernelBuilder<T> {

@Nullable
protected String modelId;
@Nullable
protected OpenAIAsyncClient client;
protected C client;
@Nullable
protected String serviceId;
@Nullable
Expand Down Expand Up @@ -51,7 +55,7 @@ public U withDeploymentName(String deploymentName) {
* @param client The OpenAI client
* @return The builder
*/
public U withOpenAIAsyncClient(OpenAIAsyncClient client) {
public U withOpenAIAsyncClient(C client) {
this.client = client;
return (U) this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services.textcompletion;

import com.azure.ai.openai.OpenAIAsyncClient;
import com.microsoft.semantickernel.Kernel;
import com.microsoft.semantickernel.implementation.ServiceLoadUtil;
import com.microsoft.semantickernel.orchestration.PromptExecutionSettings;
Expand Down Expand Up @@ -60,6 +61,6 @@ Flux<StreamingTextContent> getStreamingTextContentsAsync(
/**
* Builder for a TextGenerationService
*/
abstract class Builder extends OpenAiServiceBuilder<TextGenerationService, Builder> {
abstract class Builder extends OpenAiServiceBuilder<OpenAIAsyncClient, TextGenerationService, Builder> {
}
}