Interface OpenAIHttpExecutor<I extends Streamable,O extends Mergeable<O>>
- Type Parameters:
I- The request (Input) modelO- The response (Output) model
- All Known Implementing Classes:
ChatHttpExecutor,CreateImageHttpExecutor,DefaultOpenAIHttpExecutor,EditImageHttpExecutor,ImageVariationHttpExecutor,SpeechHttpExecutor,TranscriptionHttpExecutor,TranslationHttpExecutor,VisionHttpExecutor
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordData holder for the response ofexecuteReactive(Streamable) -
Method Summary
Modifier and TypeMethodDescriptionbooleanDenotes whether the response can be streamed, mostly taking into account the value ofStreamable.stream()which usually is implemented like inputModel -> inputModel.stream() invalid input: '&'invalid input: '&' specificApiLogic.Executes HTTP request synchronouslyvoidExecutes HTTP request asynchronously.executeReactive(I request) Executes HTTP request in reactive fashion.
-
Method Details
-
execute
Executes HTTP request synchronously- Parameters:
request- The request (Input) model- Returns:
- deserialized HTTP Response in the Output model
-
executeAsync
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) modelcallBack- A callback of type stringLine -> consume(stringLine)finalizer- A callback of type outputModel -> consume(outputModel)
-
executeReactive
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
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)
-