Class HttpStreamingChatPublisher
java.lang.Object
dev.langchain4j.reactive.streaming.HttpStreamingChatPublisher
Builds a reactive
Publisher<ChatModelStreamingEvent> for a streaming chat model from an upstream
Publisher<HttpStreamingEvent> (typically httpClient.stream(request, parser)), factoring out the
boilerplate every provider's reactive path otherwise hand-rolls:
- a bounded, back-pressured
TubeofChatModelStreamingEvents (ZeroPublisher); - a subscriber whose cancellation is subscription-based — it cancels the upstream
Flow.Subscriptionon any terminal signal (a downstream cancel, an error, or a buffer overflow), so, for example, an overflow actually aborts the HTTP connection; and - delegation of each upstream event to a provider-supplied
HttpStreamingChatPublisher.Sink.
StreamingChatResponseHandler / TubeBackedStreamingChatResponseHandler) is provider-specific; that
lives in the HttpStreamingChatPublisher.Sink, created per subscription from the Tube.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConsumes the upstreamHttpStreamingEvents of a single subscription and drives the assembledChatModelStreamingEvents into theTube(typically via aTubeBackedStreamingChatResponseHandler). -
Method Summary
Modifier and TypeMethodDescriptioncreate(int bufferSize, Supplier<Flow.Publisher<HttpStreamingEvent>> upstream, Function<mutiny.zero.Tube<ChatModelStreamingEvent>, HttpStreamingChatPublisher.Sink> sinkFactory)
-
Method Details
-
create
public static Flow.Publisher<ChatModelStreamingEvent> create(int bufferSize, Supplier<Flow.Publisher<HttpStreamingEvent>> upstream, Function<mutiny.zero.Tube<ChatModelStreamingEvent>, HttpStreamingChatPublisher.Sink> sinkFactory) - Parameters:
bufferSize- size of the bounded back-pressure bufferupstream- supplies the upstream HTTP event publisher (subscribed once per downstream subscription)sinkFactory- creates the per-subscriptionHttpStreamingChatPublisher.Sinkfrom the subscription'sTube
-