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 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));