Package org.codelibs.fess.chat
Class PhaseAwareStreamCallback
java.lang.Object
org.codelibs.fess.chat.PhaseAwareStreamCallback
- All Implemented Interfaces:
LlmStreamCallback
Bridges
LlmStreamCallback events from the LLM layer to a phase-aware
ChatPhaseCallback. Forwards onChunk/onError to an inner LlmStreamCallback
and forwards onRetry/onWaiting/onWarning to the phase callback together with
the phase name supplied at construction.-
Constructor Summary
ConstructorsConstructorDescriptionPhaseAwareStreamCallback(String phase, ChatPhaseCallback phaseCallback, LlmStreamCallback inner) Creates a callback that forwards chunk/error events toinnerand retry/waiting/warning events tophaseCallbacktagged withphase. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled for each chunk of the streaming response.voidCalled when an error occurs during streaming.voidCalled when the LLM HTTP call is being retried.voidCalled when the request is waiting for a concurrency permit.voidCalled when an internal silent fallback occurs (e.g., reasoning model token exhaustion).
-
Constructor Details
-
PhaseAwareStreamCallback
public PhaseAwareStreamCallback(String phase, ChatPhaseCallback phaseCallback, LlmStreamCallback inner) Creates a callback that forwards chunk/error events toinnerand retry/waiting/warning events tophaseCallbacktagged withphase.- Parameters:
phase- the phase name to attach to phase callback eventsphaseCallback- the phase callback to forward retry/waiting/warning events to (may be null)inner- the LlmStreamCallback to forward chunk/error events to (never null)
-
-
Method Details
-
onChunk
Description copied from interface:LlmStreamCallbackCalled for each chunk of the streaming response.- Specified by:
onChunkin interfaceLlmStreamCallback- Parameters:
chunk- the text chunk from the LLM responsedone- true if this is the final chunk
-
onError
Description copied from interface:LlmStreamCallbackCalled when an error occurs during streaming.- Specified by:
onErrorin interfaceLlmStreamCallback- Parameters:
error- the error that occurred
-
onRetry
Description copied from interface:LlmStreamCallbackCalled when the LLM HTTP call is being retried.- Specified by:
onRetryin interfaceLlmStreamCallback- Parameters:
operation- log label for the operation (e.g., "chat", "streamChat")attempt- 1-based current attempt index that just failedmaxAttempts- total attempts including the firstsleepMs- milliseconds the client will sleep before the next attemptcause- the cause of the retry (RetryableHttpException or IOException)
-
onWaiting
Description copied from interface:LlmStreamCallbackCalled when the request is waiting for a concurrency permit.- Specified by:
onWaitingin interfaceLlmStreamCallback- Parameters:
reason- short reason code, currently always "concurrency_limit"elapsedMs- milliseconds already spent waiting (0 on the first call)timeoutMs- maximum milliseconds the client will wait before giving up
-
onWarning
Description copied from interface:LlmStreamCallbackCalled when an internal silent fallback occurs (e.g., reasoning model token exhaustion).- Specified by:
onWarningin interfaceLlmStreamCallback- Parameters:
code- short machine-readable warning code (e.g., "reasoning_token_exhausted")detail- human-readable detail (free-form)
-