Class ObservableLLMClient.CompositeObserver

java.lang.Object
com.tnsai.llm.observability.ObservableLLMClient.CompositeObserver
All Implemented Interfaces:
LLMObserver
Enclosing class:
ObservableLLMClient

public static class ObservableLLMClient.CompositeObserver extends Object implements LLMObserver
Composes multiple observers into one.
  • Method Details

    • of

      public static LLMObserver of(LLMObserver... observers)
    • 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: LLMObserver
      Called before sending a request to the LLM.
      Specified by:
      onRequest in interface LLMObserver
      Parameters:
      client - The LLM client being used
      message - The user message
      systemPrompt - Optional system prompt
      history - Optional conversation history
      tools - Optional tools
    • onResponse

      public void onResponse(com.tnsai.llm.LLMClient client, com.tnsai.llm.ChatResponse response, long latencyMs)
      Description copied from interface: LLMObserver
      Called after receiving a successful response.
      Specified by:
      onResponse in interface LLMObserver
      Parameters:
      client - The LLM client that was used
      response - The response received
      latencyMs - Time taken in milliseconds
    • onError

      public void onError(com.tnsai.llm.LLMClient client, Exception error, long latencyMs)
      Description copied from interface: LLMObserver
      Called when an error occurs.
      Specified by:
      onError in interface LLMObserver
      Parameters:
      client - The LLM client that was used
      error - The exception that occurred
      latencyMs - Time taken before error in milliseconds
    • onStreamChunk

      public void onStreamChunk(com.tnsai.llm.LLMClient client, String chunk, int chunkIndex)
      Description copied from interface: LLMObserver
      Called for each streaming chunk received.
      Specified by:
      onStreamChunk in interface LLMObserver
      Parameters:
      client - The LLM client being used
      chunk - The content chunk
      chunkIndex - The index of this chunk (0-based)
    • onStreamComplete

      public void onStreamComplete(com.tnsai.llm.LLMClient client, int totalChunks, long latencyMs)
      Description copied from interface: LLMObserver
      Called when streaming completes.
      Specified by:
      onStreamComplete in interface LLMObserver
      Parameters:
      client - The LLM client that was used
      totalChunks - Total number of chunks received
      latencyMs - Total time taken in milliseconds
    • onStreamError

      public void onStreamError(com.tnsai.llm.LLMClient client, Exception error, int chunksReceived, long latencyMs)
      Description copied from interface: LLMObserver
      Called when streaming encounters an error.
      Specified by:
      onStreamError in interface LLMObserver
      Parameters:
      client - The LLM client that was used
      error - The exception that occurred
      chunksReceived - Number of chunks received before error
      latencyMs - Time taken before error in milliseconds