io.github.sashirestela.openai.BaseSimpleOpenAI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-openai Show documentation
Show all versions of simple-openai Show documentation
A Java library to use the OpenAI API in the simplest possible way.
package io.github.sashirestela.openai;
import io.github.sashirestela.cleverclient.CleverClient;
import io.github.sashirestela.slimvalidator.Validator;
import io.github.sashirestela.slimvalidator.exception.ConstraintViolationException;
import lombok.NonNull;
import lombok.Setter;
import java.net.http.HttpClient;
import java.util.Optional;
import java.util.function.Consumer;
/**
* The base abstract class that all providers extend. The implementation of services implemented by
* two or more providers goes here and if a provider does not implement a service implemented by
* others, it must override it to thrown an Unsuported exception.
*/
public abstract class BaseSimpleOpenAI {
private static final String END_OF_STREAM = "[DONE]";
protected static final String NOT_IMPLEMENTED = "Not implemented.";
@Setter
protected CleverClient cleverClient;
protected OpenAI.Audios audioService;
protected OpenAI.Batches batchService;
protected OpenAI.ChatCompletions chatCompletionService;
protected OpenAI.Completions completionService;
protected OpenAI.Embeddings embeddingService;
protected OpenAI.Files fileService;
protected OpenAI.FineTunings fineTuningService;
protected OpenAI.Images imageService;
protected OpenAI.Models modelService;
protected OpenAI.Moderations moderationService;
protected OpenAI.Uploads uploadService;
protected OpenAIBeta2.Assistants assistantService;
protected OpenAIBeta2.Threads threadService;
protected OpenAIBeta2.ThreadMessages threadMessageService;
protected OpenAIBeta2.ThreadRuns threadRunService;
protected OpenAIBeta2.ThreadRunSteps threadRunStepService;
protected OpenAIBeta2.VectorStores vectorStoreService;
protected OpenAIBeta2.VectorStoreFiles vectorStoreFileService;
protected OpenAIBeta2.VectorStoreFileBatches vectorStoreFileBatchService;
BaseSimpleOpenAI(@NonNull BaseSimpleOpenAIArgs args) {
var httpClient = Optional.ofNullable(args.getHttpClient()).orElse(HttpClient.newHttpClient());
Consumer