Interface StreamingChatResponseHandler
public interface StreamingChatResponseHandler
Represents a handler for a
StreamingChatModel response.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidonCompleteResponse(ChatResponse completeResponse) Invoked when the model has finished streaming a response.voidThis method is invoked when an error occurs during streaming.voidonPartialResponse(String partialResponse) Invoked each time the model generates a partial response (usually a single token) in a textual response.
-
Method Details
-
onPartialResponse
Invoked each time the model generates a partial response (usually a single token) in a textual response. If the model decides to execute a tool instead, this method will not be invoked;onCompleteResponse(dev.langchain4j.model.chat.response.ChatResponse)will be invoked instead.- Parameters:
partialResponse- The partial response (usually a single token), which is a part of the complete response.
-
onCompleteResponse
Invoked when the model has finished streaming a response. If the model requests the execution of one or multiple tools, this can be accessed viaChatResponse.aiMessage()->AiMessage.toolExecutionRequests().- Parameters:
completeResponse- The complete response generated by the model. For textual responses, it contains all tokens fromonPartialResponse(java.lang.String)concatenated.
-
onError
This method is invoked when an error occurs during streaming.- Parameters:
error- The error that occurred
-