Class GPULlama3ResponseParser

java.lang.Object
dev.langchain4j.model.gpullama3.GPULlama3ResponseParser

public class GPULlama3ResponseParser extends Object
Utility class for parsing GPULlama3 model responses that contain thinking content.

GPULlama3 models can generate responses with embedded thinking content in the format: <think>thinking content...</think>actual response content

This parser separates the thinking content from the actual response content for both complete responses and streaming responses, while preserving the thinking tags.

  • Method Details

    • parseResponse

      public static GPULlama3ResponseParser.ParsedResponse parseResponse(String rawResponse)
      Parses a raw GPULlama3 response to separate thinking content from actual response. Preserves the thinking tags in the thinking content.
      Parameters:
      rawResponse - the raw response from the model
      Returns:
      ParsedResponse containing separated thinking and response content
      Throws:
      IllegalArgumentException - if rawResponse is null
    • extractThinking

      public static String extractThinking(String rawResponse)
      Convenience method to extract only the thinking content from a response. Returns thinking content with tags preserved.
      Parameters:
      rawResponse - the raw response from the model
      Returns:
      the thinking content with tags, or null if none found
    • extractResponse

      public static String extractResponse(String rawResponse)
      Convenience method to extract only the cleaned response content.
      Parameters:
      rawResponse - the raw response from the model
      Returns:
      the response content with thinking tags removed
    • createStreamingParser

      public static GPULlama3ResponseParser.StreamingParser createStreamingParser(StreamingChatResponseHandler handler, org.beehive.gpullama3.model.Model model)
      Creates a new streaming parser for real-time thinking content separation.
      Parameters:
      handler - the streaming response handler
      model - the GPULlama3 model instance for token decoding
      Returns:
      a new StreamingThinkingParser instance