public class OpenAiService
extends java.lang.Object
| Constructor and Description |
|---|
OpenAiService(com.theokanning.openai.client.OpenAiApi api)
Creates a new OpenAiService that wraps OpenAiApi.
|
OpenAiService(com.theokanning.openai.client.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 |
|---|---|
com.theokanning.openai.billing.BillingUsage |
billingUsage(@NotNull java.time.LocalDate starDate,
@NotNull java.time.LocalDate endDate)
Account API consumption amount information inquiry.
|
static com.theokanning.openai.client.OpenAiApi |
buildApi(java.lang.String token,
java.time.Duration timeout) |
com.theokanning.openai.finetune.FineTuneResult |
cancelFineTune(java.lang.String fineTuneId)
Deprecated.
|
com.theokanning.openai.fine_tuning.FineTuningJob |
cancelFineTuningJob(java.lang.String fineTuningJobId) |
com.theokanning.openai.runs.Run |
cancelRun(java.lang.String threadId,
java.lang.String runId) |
com.theokanning.openai.assistants.Assistant |
createAssistant(com.theokanning.openai.assistants.AssistantRequest request) |
com.theokanning.openai.assistants.AssistantFile |
createAssistantFile(java.lang.String assistantId,
com.theokanning.openai.assistants.AssistantFileRequest fileRequest) |
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)
Deprecated.
|
com.theokanning.openai.completion.CompletionResult |
createFineTuneCompletion(com.theokanning.openai.completion.CompletionRequest request) |
com.theokanning.openai.fine_tuning.FineTuningJob |
createFineTuningJob(com.theokanning.openai.fine_tuning.FineTuningJobRequest 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.messages.Message |
createMessage(java.lang.String threadId,
com.theokanning.openai.messages.MessageRequest request) |
com.theokanning.openai.moderation.ModerationResult |
createModeration(com.theokanning.openai.moderation.ModerationRequest request) |
com.theokanning.openai.runs.Run |
createRun(java.lang.String threadId,
com.theokanning.openai.runs.RunCreateRequest runCreateRequest) |
okhttp3.ResponseBody |
createSpeech(com.theokanning.openai.audio.CreateSpeechRequest request) |
com.theokanning.openai.threads.Thread |
createThread(com.theokanning.openai.threads.ThreadRequest request) |
com.theokanning.openai.runs.Run |
createThreadAndRun(com.theokanning.openai.runs.CreateThreadAndRunRequest createThreadAndRunRequest) |
com.theokanning.openai.audio.TranscriptionResult |
createTranscription(com.theokanning.openai.audio.CreateTranscriptionRequest request,
java.io.File audio) |
com.theokanning.openai.audio.TranscriptionResult |
createTranscription(com.theokanning.openai.audio.CreateTranscriptionRequest request,
java.lang.String audioPath) |
com.theokanning.openai.audio.TranslationResult |
createTranslation(com.theokanning.openai.audio.CreateTranslationRequest request,
java.io.File audio) |
com.theokanning.openai.audio.TranslationResult |
createTranslation(com.theokanning.openai.audio.CreateTranslationRequest request,
java.lang.String audioPath) |
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 |
deleteAssistant(java.lang.String assistantId) |
com.theokanning.openai.DeleteResult |
deleteAssistantFile(java.lang.String assistantId,
java.lang.String fileId) |
com.theokanning.openai.DeleteResult |
deleteFile(java.lang.String fileId) |
com.theokanning.openai.DeleteResult |
deleteFineTune(java.lang.String fineTuneId) |
com.theokanning.openai.DeleteResult |
deleteThread(java.lang.String threadId) |
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) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.assistants.Assistant> |
listAssistantFiles(java.lang.String assistantId,
com.theokanning.openai.ListSearchParameters params) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.assistants.Assistant> |
listAssistants(com.theokanning.openai.ListSearchParameters params) |
java.util.List<com.theokanning.openai.file.File> |
listFiles() |
java.util.List<com.theokanning.openai.finetune.FineTuneEvent> |
listFineTuneEvents(java.lang.String fineTuneId)
Deprecated.
|
java.util.List<com.theokanning.openai.finetune.FineTuneResult> |
listFineTunes()
Deprecated.
|
java.util.List<com.theokanning.openai.fine_tuning.FineTuningEvent> |
listFineTuningJobEvents(java.lang.String fineTuningJobId) |
java.util.List<com.theokanning.openai.fine_tuning.FineTuningJob> |
listFineTuningJobs() |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.MessageFile> |
listMessageFiles(java.lang.String threadId,
java.lang.String messageId) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.MessageFile> |
listMessageFiles(java.lang.String threadId,
java.lang.String messageId,
com.theokanning.openai.ListSearchParameters params) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.Message> |
listMessages(java.lang.String threadId) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.Message> |
listMessages(java.lang.String threadId,
com.theokanning.openai.ListSearchParameters params) |
java.util.List<com.theokanning.openai.model.Model> |
listModels() |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.runs.Run> |
listRuns(java.lang.String threadId,
com.theokanning.openai.ListSearchParameters listSearchParameters) |
com.theokanning.openai.OpenAiResponse<com.theokanning.openai.runs.RunStep> |
listRunSteps(java.lang.String threadId,
java.lang.String runId,
com.theokanning.openai.ListSearchParameters listSearchParameters) |
io.reactivex.Flowable<ChatMessageAccumulator> |
mapStreamToAccumulator(io.reactivex.Flowable<com.theokanning.openai.completion.chat.ChatCompletionChunk> flowable) |
com.theokanning.openai.assistants.Assistant |
modifyAssistant(java.lang.String assistantId,
com.theokanning.openai.assistants.ModifyAssistantRequest request) |
com.theokanning.openai.messages.Message |
modifyMessage(java.lang.String threadId,
java.lang.String messageId,
com.theokanning.openai.messages.ModifyMessageRequest request) |
com.theokanning.openai.runs.Run |
modifyRun(java.lang.String threadId,
java.lang.String runId,
java.util.Map<java.lang.String,java.lang.String> metadata) |
com.theokanning.openai.threads.Thread |
modifyThread(java.lang.String threadId,
com.theokanning.openai.threads.ThreadRequest request) |
com.theokanning.openai.assistants.Assistant |
retrieveAssistant(java.lang.String assistantId) |
com.theokanning.openai.assistants.AssistantFile |
retrieveAssistantFile(java.lang.String assistantId,
java.lang.String fileId) |
com.theokanning.openai.file.File |
retrieveFile(java.lang.String fileId) |
okhttp3.ResponseBody |
retrieveFileContent(java.lang.String fileId) |
com.theokanning.openai.finetune.FineTuneResult |
retrieveFineTune(java.lang.String fineTuneId)
Deprecated.
|
com.theokanning.openai.fine_tuning.FineTuningJob |
retrieveFineTuningJob(java.lang.String fineTuningJobId) |
com.theokanning.openai.messages.Message |
retrieveMessage(java.lang.String threadId,
java.lang.String messageId) |
com.theokanning.openai.messages.MessageFile |
retrieveMessageFile(java.lang.String threadId,
java.lang.String messageId,
java.lang.String fileId) |
com.theokanning.openai.runs.Run |
retrieveRun(java.lang.String threadId,
java.lang.String runId) |
com.theokanning.openai.runs.RunStep |
retrieveRunStep(java.lang.String threadId,
java.lang.String runId,
java.lang.String stepId) |
com.theokanning.openai.threads.Thread |
retrieveThread(java.lang.String threadId) |
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.runs.Run |
submitToolOutputs(java.lang.String threadId,
java.lang.String runId,
com.theokanning.openai.runs.SubmitToolOutputsRequest submitToolOutputsRequest) |
com.theokanning.openai.billing.Subscription |
subscription()
Account information inquiry: including total amount and other information.
|
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.client.OpenAiApi api)
api - OpenAiApi instance to use for all methodspublic OpenAiService(com.theokanning.openai.client.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 okhttp3.ResponseBody retrieveFileContent(java.lang.String fileId)
public com.theokanning.openai.fine_tuning.FineTuningJob createFineTuningJob(com.theokanning.openai.fine_tuning.FineTuningJobRequest request)
public java.util.List<com.theokanning.openai.fine_tuning.FineTuningJob> listFineTuningJobs()
public com.theokanning.openai.fine_tuning.FineTuningJob retrieveFineTuningJob(java.lang.String fineTuningJobId)
public com.theokanning.openai.fine_tuning.FineTuningJob cancelFineTuningJob(java.lang.String fineTuningJobId)
public java.util.List<com.theokanning.openai.fine_tuning.FineTuningEvent> listFineTuningJobEvents(java.lang.String fineTuningJobId)
@Deprecated 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)
@Deprecated public java.util.List<com.theokanning.openai.finetune.FineTuneResult> listFineTunes()
@Deprecated public com.theokanning.openai.finetune.FineTuneResult retrieveFineTune(java.lang.String fineTuneId)
@Deprecated public com.theokanning.openai.finetune.FineTuneResult cancelFineTune(java.lang.String fineTuneId)
@Deprecated 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.audio.TranscriptionResult createTranscription(com.theokanning.openai.audio.CreateTranscriptionRequest request,
java.lang.String audioPath)
public com.theokanning.openai.audio.TranscriptionResult createTranscription(com.theokanning.openai.audio.CreateTranscriptionRequest request,
java.io.File audio)
public com.theokanning.openai.audio.TranslationResult createTranslation(com.theokanning.openai.audio.CreateTranslationRequest request,
java.lang.String audioPath)
public com.theokanning.openai.audio.TranslationResult createTranslation(com.theokanning.openai.audio.CreateTranslationRequest request,
java.io.File audio)
public com.theokanning.openai.moderation.ModerationResult createModeration(com.theokanning.openai.moderation.ModerationRequest request)
public okhttp3.ResponseBody createSpeech(com.theokanning.openai.audio.CreateSpeechRequest request)
public com.theokanning.openai.assistants.Assistant createAssistant(com.theokanning.openai.assistants.AssistantRequest request)
public com.theokanning.openai.assistants.Assistant retrieveAssistant(java.lang.String assistantId)
public com.theokanning.openai.assistants.Assistant modifyAssistant(java.lang.String assistantId,
com.theokanning.openai.assistants.ModifyAssistantRequest request)
public com.theokanning.openai.DeleteResult deleteAssistant(java.lang.String assistantId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.assistants.Assistant> listAssistants(com.theokanning.openai.ListSearchParameters params)
public com.theokanning.openai.assistants.AssistantFile createAssistantFile(java.lang.String assistantId,
com.theokanning.openai.assistants.AssistantFileRequest fileRequest)
public com.theokanning.openai.assistants.AssistantFile retrieveAssistantFile(java.lang.String assistantId,
java.lang.String fileId)
public com.theokanning.openai.DeleteResult deleteAssistantFile(java.lang.String assistantId,
java.lang.String fileId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.assistants.Assistant> listAssistantFiles(java.lang.String assistantId,
com.theokanning.openai.ListSearchParameters params)
public com.theokanning.openai.threads.Thread createThread(com.theokanning.openai.threads.ThreadRequest request)
public com.theokanning.openai.threads.Thread retrieveThread(java.lang.String threadId)
public com.theokanning.openai.threads.Thread modifyThread(java.lang.String threadId,
com.theokanning.openai.threads.ThreadRequest request)
public com.theokanning.openai.DeleteResult deleteThread(java.lang.String threadId)
public com.theokanning.openai.messages.Message createMessage(java.lang.String threadId,
com.theokanning.openai.messages.MessageRequest request)
public com.theokanning.openai.messages.Message retrieveMessage(java.lang.String threadId,
java.lang.String messageId)
public com.theokanning.openai.messages.Message modifyMessage(java.lang.String threadId,
java.lang.String messageId,
com.theokanning.openai.messages.ModifyMessageRequest request)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.Message> listMessages(java.lang.String threadId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.Message> listMessages(java.lang.String threadId,
com.theokanning.openai.ListSearchParameters params)
public com.theokanning.openai.messages.MessageFile retrieveMessageFile(java.lang.String threadId,
java.lang.String messageId,
java.lang.String fileId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.MessageFile> listMessageFiles(java.lang.String threadId,
java.lang.String messageId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.messages.MessageFile> listMessageFiles(java.lang.String threadId,
java.lang.String messageId,
com.theokanning.openai.ListSearchParameters params)
public com.theokanning.openai.runs.Run createRun(java.lang.String threadId,
com.theokanning.openai.runs.RunCreateRequest runCreateRequest)
public com.theokanning.openai.runs.Run retrieveRun(java.lang.String threadId,
java.lang.String runId)
public com.theokanning.openai.runs.Run modifyRun(java.lang.String threadId,
java.lang.String runId,
java.util.Map<java.lang.String,java.lang.String> metadata)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.runs.Run> listRuns(java.lang.String threadId,
com.theokanning.openai.ListSearchParameters listSearchParameters)
public com.theokanning.openai.runs.Run submitToolOutputs(java.lang.String threadId,
java.lang.String runId,
com.theokanning.openai.runs.SubmitToolOutputsRequest submitToolOutputsRequest)
public com.theokanning.openai.runs.Run cancelRun(java.lang.String threadId,
java.lang.String runId)
public com.theokanning.openai.runs.Run createThreadAndRun(com.theokanning.openai.runs.CreateThreadAndRunRequest createThreadAndRunRequest)
public com.theokanning.openai.runs.RunStep retrieveRunStep(java.lang.String threadId,
java.lang.String runId,
java.lang.String stepId)
public com.theokanning.openai.OpenAiResponse<com.theokanning.openai.runs.RunStep> listRunSteps(java.lang.String threadId,
java.lang.String runId,
com.theokanning.openai.ListSearchParameters listSearchParameters)
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.client.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)
public io.reactivex.Flowable<ChatMessageAccumulator> mapStreamToAccumulator(io.reactivex.Flowable<com.theokanning.openai.completion.chat.ChatCompletionChunk> flowable)
public com.theokanning.openai.billing.Subscription subscription()
public com.theokanning.openai.billing.BillingUsage billingUsage(@NotNull
@NotNull java.time.LocalDate starDate,
@NotNull
@NotNull java.time.LocalDate endDate)
starDate - endDate -