public class OpenAiService
extends java.lang.Object
| Constructor and Description |
|---|
OpenAiService(com.theokanning.openai.OpenAiApi api)
Creates a new OpenAiService that wraps OpenAiApi.
|
OpenAiService(com.theokanning.openai.OpenAiApi api,
java.util.concurrent.ExecutorService executorService)
Creates a new OpenAiService that wraps OpenAiApi.
|
OpenAiService(java.lang.String token)
Creates a new OpenAiService that wraps OpenAiApi
|
OpenAiService(java.lang.String token,
java.time.Duration timeout)
Creates a new OpenAiService that wraps OpenAiApi
|
| Modifier and Type | Method and Description |
|---|---|
static com.theokanning.openai.OpenAiApi |
buildApi(java.lang.String token,
java.time.Duration timeout) |
com.theokanning.openai.finetune.FineTuneResult |
cancelFineTune(java.lang.String fineTuneId) |
com.theokanning.openai.completion.chat.ChatCompletionResult |
createChatCompletion(com.theokanning.openai.completion.chat.ChatCompletionRequest request) |
com.theokanning.openai.completion.CompletionResult |
createCompletion(com.theokanning.openai.completion.CompletionRequest request) |
com.theokanning.openai.edit.EditResult |
createEdit(com.theokanning.openai.edit.EditRequest request) |
com.theokanning.openai.embedding.EmbeddingResult |
createEmbeddings(com.theokanning.openai.embedding.EmbeddingRequest request) |
com.theokanning.openai.finetune.FineTuneResult |
createFineTune(com.theokanning.openai.finetune.FineTuneRequest request) |
com.theokanning.openai.completion.CompletionResult |
createFineTuneCompletion(com.theokanning.openai.completion.CompletionRequest request) |
com.theokanning.openai.image.ImageResult |
createImage(com.theokanning.openai.image.CreateImageRequest request) |
com.theokanning.openai.image.ImageResult |
createImageEdit(com.theokanning.openai.image.CreateImageEditRequest request,
java.io.File image,
java.io.File mask) |
com.theokanning.openai.image.ImageResult |
createImageEdit(com.theokanning.openai.image.CreateImageEditRequest request,
java.lang.String imagePath,
java.lang.String maskPath) |
com.theokanning.openai.image.ImageResult |
createImageVariation(com.theokanning.openai.image.CreateImageVariationRequest request,
java.io.File image) |
com.theokanning.openai.image.ImageResult |
createImageVariation(com.theokanning.openai.image.CreateImageVariationRequest request,
java.lang.String imagePath) |
com.theokanning.openai.moderation.ModerationResult |
createModeration(com.theokanning.openai.moderation.ModerationRequest request) |
static okhttp3.OkHttpClient |
defaultClient(java.lang.String token,
java.time.Duration timeout) |
static com.fasterxml.jackson.databind.ObjectMapper |
defaultObjectMapper() |
static retrofit2.Retrofit |
defaultRetrofit(okhttp3.OkHttpClient client,
com.fasterxml.jackson.databind.ObjectMapper mapper) |
com.theokanning.openai.DeleteResult |
deleteFile(java.lang.String fileId) |
com.theokanning.openai.DeleteResult |
deleteFineTune(java.lang.String fineTuneId) |
static <T> T |
execute(io.reactivex.Single<T> apiCall)
Calls the Open AI api, returns the response, and parses error messages if the request fails
|
com.theokanning.openai.model.Model |
getModel(java.lang.String modelId) |
java.util.List<com.theokanning.openai.file.File> |
listFiles() |
java.util.List<com.theokanning.openai.finetune.FineTuneEvent> |
listFineTuneEvents(java.lang.String fineTuneId) |
java.util.List<com.theokanning.openai.finetune.FineTuneResult> |
listFineTunes() |
java.util.List<com.theokanning.openai.model.Model> |
listModels() |
com.theokanning.openai.file.File |
retrieveFile(java.lang.String fileId) |
com.theokanning.openai.finetune.FineTuneResult |
retrieveFineTune(java.lang.String fineTuneId) |
void |
shutdownExecutor()
Shuts down the OkHttp ExecutorService.
|
static io.reactivex.Flowable<SSE> |
stream(retrofit2.Call<okhttp3.ResponseBody> apiCall)
Calls the Open AI api and returns a Flowable of SSE for streaming
omitting the last message.
|
static io.reactivex.Flowable<SSE> |
stream(retrofit2.Call<okhttp3.ResponseBody> apiCall,
boolean emitDone)
Calls the Open AI api and returns a Flowable of SSE for streaming.
|
static <T> io.reactivex.Flowable<T> |
stream(retrofit2.Call<okhttp3.ResponseBody> apiCall,
java.lang.Class<T> cl)
Calls the Open AI api and returns a Flowable of type T for streaming
omitting the last message.
|
io.reactivex.Flowable<com.theokanning.openai.completion.chat.ChatCompletionChunk> |
streamChatCompletion(com.theokanning.openai.completion.chat.ChatCompletionRequest request) |
io.reactivex.Flowable<com.theokanning.openai.completion.CompletionChunk> |
streamCompletion(com.theokanning.openai.completion.CompletionRequest request) |
com.theokanning.openai.file.File |
uploadFile(java.lang.String purpose,
java.lang.String filepath) |
public OpenAiService(java.lang.String token)
token - OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"public OpenAiService(java.lang.String token,
java.time.Duration timeout)
token - OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"timeout - http read timeout, Duration.ZERO means no timeoutpublic OpenAiService(com.theokanning.openai.OpenAiApi api)
api - OpenAiApi instance to use for all methodspublic OpenAiService(com.theokanning.openai.OpenAiApi api,
java.util.concurrent.ExecutorService executorService)
Use this if you need more customization.
api - OpenAiApi instance to use for all methodsexecutorService - the ExecutorService from client.dispatcher().executorService()public java.util.List<com.theokanning.openai.model.Model> listModels()
public com.theokanning.openai.model.Model getModel(java.lang.String modelId)
public com.theokanning.openai.completion.CompletionResult createCompletion(com.theokanning.openai.completion.CompletionRequest request)
public io.reactivex.Flowable<com.theokanning.openai.completion.CompletionChunk> streamCompletion(com.theokanning.openai.completion.CompletionRequest request)
public com.theokanning.openai.completion.chat.ChatCompletionResult createChatCompletion(com.theokanning.openai.completion.chat.ChatCompletionRequest request)
public io.reactivex.Flowable<com.theokanning.openai.completion.chat.ChatCompletionChunk> streamChatCompletion(com.theokanning.openai.completion.chat.ChatCompletionRequest request)
public com.theokanning.openai.edit.EditResult createEdit(com.theokanning.openai.edit.EditRequest request)
public com.theokanning.openai.embedding.EmbeddingResult createEmbeddings(com.theokanning.openai.embedding.EmbeddingRequest request)
public java.util.List<com.theokanning.openai.file.File> listFiles()
public com.theokanning.openai.file.File uploadFile(java.lang.String purpose,
java.lang.String filepath)
public com.theokanning.openai.DeleteResult deleteFile(java.lang.String fileId)
public com.theokanning.openai.file.File retrieveFile(java.lang.String fileId)
public com.theokanning.openai.finetune.FineTuneResult createFineTune(com.theokanning.openai.finetune.FineTuneRequest request)
public com.theokanning.openai.completion.CompletionResult createFineTuneCompletion(com.theokanning.openai.completion.CompletionRequest request)
public java.util.List<com.theokanning.openai.finetune.FineTuneResult> listFineTunes()
public com.theokanning.openai.finetune.FineTuneResult retrieveFineTune(java.lang.String fineTuneId)
public com.theokanning.openai.finetune.FineTuneResult cancelFineTune(java.lang.String fineTuneId)
public java.util.List<com.theokanning.openai.finetune.FineTuneEvent> listFineTuneEvents(java.lang.String fineTuneId)
public com.theokanning.openai.DeleteResult deleteFineTune(java.lang.String fineTuneId)
public com.theokanning.openai.image.ImageResult createImage(com.theokanning.openai.image.CreateImageRequest request)
public com.theokanning.openai.image.ImageResult createImageEdit(com.theokanning.openai.image.CreateImageEditRequest request,
java.lang.String imagePath,
java.lang.String maskPath)
public com.theokanning.openai.image.ImageResult createImageEdit(com.theokanning.openai.image.CreateImageEditRequest request,
java.io.File image,
java.io.File mask)
public com.theokanning.openai.image.ImageResult createImageVariation(com.theokanning.openai.image.CreateImageVariationRequest request,
java.lang.String imagePath)
public com.theokanning.openai.image.ImageResult createImageVariation(com.theokanning.openai.image.CreateImageVariationRequest request,
java.io.File image)
public com.theokanning.openai.moderation.ModerationResult createModeration(com.theokanning.openai.moderation.ModerationRequest request)
public static <T> T execute(io.reactivex.Single<T> apiCall)
public static io.reactivex.Flowable<SSE> stream(retrofit2.Call<okhttp3.ResponseBody> apiCall)
apiCall - The api callpublic static io.reactivex.Flowable<SSE> stream(retrofit2.Call<okhttp3.ResponseBody> apiCall, boolean emitDone)
apiCall - The api callemitDone - If true the last message ([DONE]) is emittedpublic static <T> io.reactivex.Flowable<T> stream(retrofit2.Call<okhttp3.ResponseBody> apiCall,
java.lang.Class<T> cl)
apiCall - The api callcl - Class of type T to returnpublic void shutdownExecutor()
public static com.theokanning.openai.OpenAiApi buildApi(java.lang.String token,
java.time.Duration timeout)
public static com.fasterxml.jackson.databind.ObjectMapper defaultObjectMapper()
public static okhttp3.OkHttpClient defaultClient(java.lang.String token,
java.time.Duration timeout)
public static retrofit2.Retrofit defaultRetrofit(okhttp3.OkHttpClient client,
com.fasterxml.jackson.databind.ObjectMapper mapper)