Package dev.langchain4j.model
Class LambdaStreamingResponseHandler
-
- All Implemented Interfaces:
public class LambdaStreamingResponseHandler<T>
Utility class with lambda-based streaming response handlers. Lets you use Java lambda functions to receive
onNext
andonError
events, from your streaming chat model, instead of creating an anonymous inner class implementingStreamingResponseHandler
. Example:import static dev.langchain4j.model.LambdaStreamingResponseHandler.*; model.generate("Why is the sky blue?", onNext(text -> System.out.println(text)); model.generate("Why is the sky blue?", onNext(System.out::println); model.generate("Why is the sky blue?", onNextAndError(System.out::println, Throwable::printStackTrace));
-
-
Constructor Summary
Constructors Constructor Description LambdaStreamingResponseHandler()
-
Method Summary
Modifier and Type Method Description static <T> StreamingResponseHandler<T>
onNext(Consumer<String> nextLambda)
static <T> StreamingResponseHandler<T>
onNextAndError(Consumer<String> nextLambda, Consumer<Throwable> errorLambda)
-
-
Method Detail
-
onNext
static <T> StreamingResponseHandler<T> onNext(Consumer<String> nextLambda)
-
onNextAndError
static <T> StreamingResponseHandler<T> onNextAndError(Consumer<String> nextLambda, Consumer<Throwable> errorLambda)
-
-
-
-