Class StreamingChatHandlerGuard
java.lang.Object
dev.langchain4j.internal.StreamingChatHandlerGuard
Guards one call of
StreamingChatModel.chat(request, options, handler), so that the model implementation never
receives what the handler's onError throws:
- what
onErrorthrows on the thread that calledchat(...), beforechat(...)returns, is recorded and thrown fromchat(...)once the call of the model has ended; - what
onErrorthrows on another thread, or afterchat(...)returned, is logged; - a failure thrown by the call of the model is reported to
onError, unless the handler already received the complete response or an error: it is then logged.
chat(...), pass the complete response and the errors to the handler
through onCompleteResponse(ChatResponse) and onError(Throwable), and call the model with
run(Runnable, StreamingChatResponseHandler).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidonCompleteResponse(ChatResponse completeResponse) Passes the complete response to the handler.voidPasses the error to the handler.voidrun(Runnable call, StreamingChatResponseHandler reportTo) Runs the call of the model, then throws what the handler'sonErrorthrew on the calling thread meanwhile.
-
Constructor Details
-
StreamingChatHandlerGuard
-
-
Method Details
-
onCompleteResponse
Passes the complete response to the handler. What the handler throws is passed on. -
onError
Passes the error to the handler. Never throws: what the handler'sonErrorthrows is recorded or logged. -
run
Runs the call of the model, then throws what the handler'sonErrorthrew on the calling thread meanwhile.- Parameters:
call- the call of the modelreportTo- the handler whoseonErrorreceives a failure thrown by the call, when the handler did not receive the complete response or an error yet; itsonErrormust not throw
-