Package com.tnsai.llm.observability
Class ObservableLLMClient.CompositeObserver
java.lang.Object
com.tnsai.llm.observability.ObservableLLMClient.CompositeObserver
- All Implemented Interfaces:
LLMObserver
- Enclosing class:
ObservableLLMClient
Composes multiple observers into one.
-
Field Summary
Fields inherited from interface com.tnsai.llm.observability.LLMObserver
NOOP -
Method Summary
Modifier and TypeMethodDescriptionstatic LLMObserverof(LLMObserver... observers) voidCalled when an error occurs.voidonRequest(com.tnsai.llm.LLMClient client, String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) Called before sending a request to the LLM.voidonResponse(com.tnsai.llm.LLMClient client, com.tnsai.llm.ChatResponse response, long latencyMs) Called after receiving a successful response.voidonStreamChunk(com.tnsai.llm.LLMClient client, String chunk, int chunkIndex) Called for each streaming chunk received.voidonStreamComplete(com.tnsai.llm.LLMClient client, int totalChunks, long latencyMs) Called when streaming completes.voidonStreamError(com.tnsai.llm.LLMClient client, Exception error, int chunksReceived, long latencyMs) Called when streaming encounters an error.
-
Method Details
-
of
-
onRequest
public void onRequest(com.tnsai.llm.LLMClient client, String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) Description copied from interface:LLMObserverCalled before sending a request to the LLM.- Specified by:
onRequestin interfaceLLMObserver- Parameters:
client- The LLM client being usedmessage- The user messagesystemPrompt- Optional system prompthistory- Optional conversation historytools- Optional tools
-
onResponse
public void onResponse(com.tnsai.llm.LLMClient client, com.tnsai.llm.ChatResponse response, long latencyMs) Description copied from interface:LLMObserverCalled after receiving a successful response.- Specified by:
onResponsein interfaceLLMObserver- Parameters:
client- The LLM client that was usedresponse- The response receivedlatencyMs- Time taken in milliseconds
-
onError
Description copied from interface:LLMObserverCalled when an error occurs.- Specified by:
onErrorin interfaceLLMObserver- Parameters:
client- The LLM client that was usederror- The exception that occurredlatencyMs- Time taken before error in milliseconds
-
onStreamChunk
Description copied from interface:LLMObserverCalled for each streaming chunk received.- Specified by:
onStreamChunkin interfaceLLMObserver- Parameters:
client- The LLM client being usedchunk- The content chunkchunkIndex- The index of this chunk (0-based)
-
onStreamComplete
public void onStreamComplete(com.tnsai.llm.LLMClient client, int totalChunks, long latencyMs) Description copied from interface:LLMObserverCalled when streaming completes.- Specified by:
onStreamCompletein interfaceLLMObserver- Parameters:
client- The LLM client that was usedtotalChunks- Total number of chunks receivedlatencyMs- Total time taken in milliseconds
-
onStreamError
public void onStreamError(com.tnsai.llm.LLMClient client, Exception error, int chunksReceived, long latencyMs) Description copied from interface:LLMObserverCalled when streaming encounters an error.- Specified by:
onStreamErrorin interfaceLLMObserver- Parameters:
client- The LLM client that was usederror- The exception that occurredchunksReceived- Number of chunks received before errorlatencyMs- Time taken before error in milliseconds
-