Class LambdaStreamingResponseHandler

  • All Implemented Interfaces:

    
    public class LambdaStreamingResponseHandler
    
                        

    Utility class with lambda-based streaming response handlers.

    Lets you use Java lambda functions to receive onPartialResponse and onError events, from your streaming chat model, instead of creating an anonymous inner class implementing StreamingChatResponseHandler.

    Example:

    import static dev.langchain4j.model.LambdaStreamingResponseHandler.*;
    
    model.chat("Why is the sky blue?",
          onPartialResponse(text -> System.out.println(text));
    model.chat("Why is the sky blue?",
          onPartialResponse(System.out::println);
    model.chat("Why is the sky blue?",
          onPartialResponseAndError(System.out::println, Throwable::printStackTrace));