Interface OpenAIHttpExecutor<I extends Streamable,O extends Mergeable<O>>

Type Parameters:
I - The request (Input) model
O - The response (Output) model
All Known Implementing Classes:
ChatHttpExecutor, CreateImageHttpExecutor, DefaultOpenAIHttpExecutor, EditImageHttpExecutor, ImageVariationHttpExecutor, SpeechHttpExecutor, TranscriptionHttpExecutor, TranslationHttpExecutor, VisionHttpExecutor

public interface OpenAIHttpExecutor<I extends Streamable,O extends Mergeable<O>>

Abstraction over HTTP execution to OpenAPI. It takes a potentially Streamable request, and sends HTTP request, which execution can be immediately executed in a blocking manner, or scheduled for execution in asynchronous (reactive included) fashion.

  • Method Details

    • execute

      O execute(I request)
      Executes HTTP request synchronously
      Parameters:
      request - The request (Input) model
      Returns:
      deserialized HTTP Response in the Output model
    • executeAsync

      void executeAsync(I request, Consumer<String> callBack, Consumer<O> finalizer)

      Executes HTTP request asynchronously. Since response can be streamed, it can be potentially beneficial for the developer, to subscribe to each line, hence the callback parameter.

      It makes a little bit more sense to subscribe, to the whole response, using the finalizer parameter.

      Parameters:
      request - The request (Input) model
      callBack - A callback of type stringLine -> consume(stringLine)
      finalizer - A callback of type outputModel -> consume(outputModel)
    • executeReactive

      OpenAIHttpExecutor.ReactiveExecution<O> executeReactive(I request)

      Executes HTTP request in reactive fashion. We strongly recommend to use this only if a real reactive runtime is present, such as Reactor netty.

      Parameters:
      request - The request (Input) model
      Returns:
      OpenAIHttpExecutor.ReactiveExecution<O extends Mergeable<O>> object holding a single observable (reactor.core.publisher.Mono<O extends Mergeable<O>>) to the whole response, and a multi-emit observable (reactor.core.publisher.Flux<String>) to each response line.
    • canStream

      boolean canStream(I input)

      Denotes whether the response can be streamed, mostly taking into account the value of Streamable.stream() which usually is implemented like inputModel -> inputModel.stream() invalid input: '&'invalid input: '&' specificApiLogic.

      Parameters:
      input - The request (Input) model
      Returns:
      boolean saying if you can stream the response or not. Usually beneficial for internal calls like execute(Streamable)