Package com.tnsai.llm

Class ChatRequest

java.lang.Object
com.tnsai.llm.ChatRequest

public final class ChatRequest extends Object
Unified request model for LLM chat operations.

Consolidates the repeated parameter pattern (message, systemPrompt, history, tools) into a single immutable request object with a fluent builder API. Supports both text and multimodal requests.

Usage


 // Simple text request
 ChatRequest req = ChatRequest.of("What is 2+2?");

 // With system prompt
 ChatRequest req = ChatRequest.builder()
     .message("Explain quantum physics")
     .systemPrompt("You are a physics teacher")
     .build();

 // With tools and history
 ChatRequest req = ChatRequest.builder()
     .message("Search for weather in Tokyo")
     .systemPrompt("You are a helpful assistant")
     .history(conversationHistory)
     .tools(toolDefinitions)
     .temperature(0.3f)
     .build();

 // Multimodal
 ChatRequest req = ChatRequest.builder()
     .messageParts(List.of(new TextPart("What's in this image?"), imagePart))
     .build();

 // Use with LLMClient
 ChatResponse response = client.chat(req);
 Stream<String> stream = client.streamChat(req);
 
See Also:
  • Method Details

    • getMessage

      public String getMessage()
      The text message (null for multimodal-only requests).
    • getMessageParts

      public List<ContentPart> getMessageParts()
      Multimodal content parts (null for text-only requests).
    • getSystemPrompt

      public String getSystemPrompt()
      The system prompt (null if not set).
    • getHistory

      public List<Map<String,Object>> getHistory()
      Conversation history (null if not set).
    • getTools

      public List<Map<String,Object>> getTools()
      Tool catalog as JSON-Schema fragments (null if not set). Each entry carries at minimum name, description, and parameters per the Anthropic-style tool-use format. Type changed from List<ToolDefinition> in v0.6.0 (RFC #188) — providers operate directly on the map shape they serialize anyway.
    • getTemperature

      public Float getTemperature()
      Temperature override (null to use client default).
    • getMetadata

      public Map<String,Object> getMetadata()
      Arbitrary metadata for provider-specific extensions.
    • isMultimodal

      public boolean isMultimodal()
      Returns true if this is a multimodal request (has content parts).
    • hasTools

      public boolean hasTools()
      Returns true if tools are specified.
    • hasHistory

      public boolean hasHistory()
      Returns true if conversation history is provided.
    • hasSystemPrompt

      public boolean hasSystemPrompt()
      Returns true if a system prompt is set.
    • hasTemperature

      public boolean hasTemperature()
      Returns true if a temperature override is set.
    • systemPromptOpt

      public Optional<String> systemPromptOpt()
      System prompt as Optional (for bridging to existing LLMClient methods).
    • historyOpt

      public Optional<List<Map<String,Object>>> historyOpt()
      History as Optional (for bridging to existing LLMClient methods).
    • toolsOpt

      public Optional<List<Map<String,Object>>> toolsOpt()
      Tools as Optional maps (for bridging to existing LLMClient methods).
    • of

      public static ChatRequest of(String message)
      Creates a simple text-only request.
      Parameters:
      message - the user message
      Returns:
      a new ChatRequest
    • of

      public static ChatRequest of(String message, String systemPrompt)
      Creates a request with system prompt.
      Parameters:
      message - the user message
      systemPrompt - the system prompt
      Returns:
      a new ChatRequest
    • builder

      public static ChatRequest.Builder builder()
      Returns a new builder instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object