Package dev.langchain4j.model
Class LambdaStreamingResponseHandler<T>
java.lang.Object
dev.langchain4j.model.LambdaStreamingResponseHandler<T>
- Type Parameters:
T
- The type of the response.
Utility class with lambda-based streaming response handlers.
Lets you use Java lambda functions to receive
onNext
and onError
events,
from your streaming chat model, instead of creating an anonymous inner class
implementing StreamingResponseHandler
.
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));
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> StreamingResponseHandler
<T> static <T> StreamingResponseHandler
<T> onNextAndError
(Consumer<String> nextLambda, Consumer<Throwable> errorLambda)
-
Constructor Details
-
LambdaStreamingResponseHandler
public LambdaStreamingResponseHandler()
-
-
Method Details
-
onNext
-
onNextAndError
public static <T> StreamingResponseHandler<T> onNextAndError(Consumer<String> nextLambda, Consumer<Throwable> errorLambda)
-