Interface OpenAiRestApi
@Path("")
@ClientHeaderParam(name="Authorization",value="Bearer {apiKey}") @ClientHeaderParam(name="api-key",value="{apiKey}")
@Consumes("application/json")
@Produces("application/json")
@RegisterProvider(OpenAiRestApiJacksonReader.class) @RegisterProvider(OpenAiRestApiJacksonWriter.class) @RegisterProvider(OpenAiRestApiReaderInterceptor.class) @RegisterProvider(OpenAiRestApiWriterInterceptor.class)
public interface OpenAiRestApi
This Microprofile REST client is used as the building block of all the API calls to OpenAI.
The implementation is provided by the Reactive REST Client in Quarkus.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Ensures that the terminal event sent by OpenAI is not processed (as it is not a valid json event)static class
static class
Introduce a custom logger as the stock one logs at the DEBUG level by default...static class
static class
static class
This method validates that the response is not empty, which happens when the API returns an error objectstatic class
The point of this is to properly set thestream
value of the request so users don't have to remember to set it manually -
Method Summary
Modifier and TypeMethodDescriptiondev.ai4j.openai4j.chat.ChatCompletionResponse
blockingChatCompletion
(dev.ai4j.openai4j.chat.ChatCompletionRequest request, String apiKey, String apiVersion) Perform a blocking request for a chat completion responsedev.ai4j.openai4j.completion.CompletionResponse
blockingCompletion
(dev.ai4j.openai4j.completion.CompletionRequest request, String apiKey, String apiVersion) Perform a blocking request for a completion responsedev.ai4j.openai4j.embedding.EmbeddingResponse
blockingEmbedding
(dev.ai4j.openai4j.embedding.EmbeddingRequest request, String apiKey, String apiVersion) Perform a blocking request to get the embeddings of an input textdev.ai4j.openai4j.image.GenerateImagesResponse
blockingImagesGenerations
(dev.ai4j.openai4j.image.GenerateImagesRequest request, String apiKey, String apiVersion) dev.ai4j.openai4j.moderation.ModerationResponse
blockingModeration
(dev.ai4j.openai4j.moderation.ModerationRequest request, String apiKey, String apiVersion) Perform a blocking request to get a moderated version of an input textio.smallrye.mutiny.Uni<dev.ai4j.openai4j.completion.CompletionResponse>
completion
(dev.ai4j.openai4j.completion.CompletionRequest request, String apiKey, String apiVersion) Perform a non-blocking request for a completion responseio.smallrye.mutiny.Uni<dev.ai4j.openai4j.chat.ChatCompletionResponse>
createChatCompletion
(dev.ai4j.openai4j.chat.ChatCompletionRequest request, String apiKey, String apiVersion) Perform a non-blocking request for a chat completion responseio.smallrye.mutiny.Uni<dev.ai4j.openai4j.embedding.EmbeddingResponse>
Perform a non-blocking request to get the embeddings of an input textio.smallrye.mutiny.Uni<dev.ai4j.openai4j.image.GenerateImagesResponse>
imagesGenerations
(dev.ai4j.openai4j.image.GenerateImagesRequest request, String apiKey, String apiVersion) io.smallrye.mutiny.Uni<dev.ai4j.openai4j.moderation.ModerationResponse>
moderation
(dev.ai4j.openai4j.moderation.ModerationRequest request, String apiKey, String apiVersion) Perform a non-blocking request to get a moderated version of an input textio.smallrye.mutiny.Multi<dev.ai4j.openai4j.chat.ChatCompletionResponse>
streamingChatCompletion
(dev.ai4j.openai4j.chat.ChatCompletionRequest request, String apiKey, String apiVersion) Performs a non-blocking request for a streaming chat completion requestio.smallrye.mutiny.Multi<dev.ai4j.openai4j.completion.CompletionResponse>
streamingCompletion
(dev.ai4j.openai4j.completion.CompletionRequest request, String apiKey, String apiVersion) Performs a non-blocking request for a streaming completion requeststatic RuntimeException
toException
(jakarta.ws.rs.core.Response response)
-
Method Details
-
completion
@Path("completions") @POST io.smallrye.mutiny.Uni<dev.ai4j.openai4j.completion.CompletionResponse> completion(dev.ai4j.openai4j.completion.CompletionRequest request, @NotBody String apiKey, String apiVersion) Perform a non-blocking request for a completion response -
blockingCompletion
@Path("completions") @POST dev.ai4j.openai4j.completion.CompletionResponse blockingCompletion(dev.ai4j.openai4j.completion.CompletionRequest request, @NotBody String apiKey, String apiVersion) Perform a blocking request for a completion response -
streamingCompletion
@Path("chat/completions") @POST @RestStreamElementType("application/json") io.smallrye.mutiny.Multi<dev.ai4j.openai4j.completion.CompletionResponse> streamingCompletion(dev.ai4j.openai4j.completion.CompletionRequest request, @NotBody String apiKey, String apiVersion) Performs a non-blocking request for a streaming completion request -
createChatCompletion
@Path("chat/completions") @POST io.smallrye.mutiny.Uni<dev.ai4j.openai4j.chat.ChatCompletionResponse> createChatCompletion(dev.ai4j.openai4j.chat.ChatCompletionRequest request, @NotBody String apiKey, String apiVersion) Perform a non-blocking request for a chat completion response -
blockingChatCompletion
@Path("chat/completions") @POST dev.ai4j.openai4j.chat.ChatCompletionResponse blockingChatCompletion(dev.ai4j.openai4j.chat.ChatCompletionRequest request, @NotBody String apiKey, String apiVersion) Perform a blocking request for a chat completion response -
streamingChatCompletion
@Path("chat/completions") @POST @RestStreamElementType("application/json") io.smallrye.mutiny.Multi<dev.ai4j.openai4j.chat.ChatCompletionResponse> streamingChatCompletion(dev.ai4j.openai4j.chat.ChatCompletionRequest request, @NotBody String apiKey, String apiVersion) Performs a non-blocking request for a streaming chat completion request -
embedding
@Path("embeddings") @POST io.smallrye.mutiny.Uni<dev.ai4j.openai4j.embedding.EmbeddingResponse> embedding(dev.ai4j.openai4j.embedding.EmbeddingRequest request, @NotBody String apiKey, String apiVersion) Perform a non-blocking request to get the embeddings of an input text -
blockingEmbedding
@Path("embeddings") @POST dev.ai4j.openai4j.embedding.EmbeddingResponse blockingEmbedding(dev.ai4j.openai4j.embedding.EmbeddingRequest request, @NotBody String apiKey, String apiVersion) Perform a blocking request to get the embeddings of an input text -
moderation
@Path("moderations") @POST io.smallrye.mutiny.Uni<dev.ai4j.openai4j.moderation.ModerationResponse> moderation(dev.ai4j.openai4j.moderation.ModerationRequest request, @NotBody String apiKey, String apiVersion) Perform a non-blocking request to get a moderated version of an input text -
blockingModeration
@Path("moderations") @POST dev.ai4j.openai4j.moderation.ModerationResponse blockingModeration(dev.ai4j.openai4j.moderation.ModerationRequest request, @NotBody String apiKey, String apiVersion) Perform a blocking request to get a moderated version of an input text -
blockingImagesGenerations
-
imagesGenerations
-
toException
-