Package com.tnsai.llm
Class ChatRequest
java.lang.Object
com.tnsai.llm.ChatRequest
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder for ChatRequest. -
Method Summary
Modifier and TypeMethodDescriptionstatic ChatRequest.Builderbuilder()Returns a new builder instance.Conversation history (null if not set).The text message (null for multimodal-only requests).Multimodal content parts (null for text-only requests).Arbitrary metadata for provider-specific extensions.The system prompt (null if not set).Temperature override (null to use client default).getTools()Tool catalog as JSON-Schema fragments (null if not set).booleanReturns true if conversation history is provided.booleanReturns true if a system prompt is set.booleanReturns true if a temperature override is set.booleanhasTools()Returns true if tools are specified.History as Optional (for bridging to existing LLMClient methods).booleanReturns true if this is a multimodal request (has content parts).static ChatRequestCreates a simple text-only request.static ChatRequestCreates a request with system prompt.System prompt as Optional (for bridging to existing LLMClient methods).toolsOpt()Tools as Optional maps (for bridging to existing LLMClient methods).toString()
-
Method Details
-
getMessage
The text message (null for multimodal-only requests). -
getMessageParts
Multimodal content parts (null for text-only requests). -
getSystemPrompt
The system prompt (null if not set). -
getHistory
Conversation history (null if not set). -
getTools
Tool catalog as JSON-Schema fragments (null if not set). Each entry carries at minimumname,description, andparametersper the Anthropic-style tool-use format. Type changed fromList<ToolDefinition>in v0.6.0 (RFC #188) — providers operate directly on the map shape they serialize anyway. -
getTemperature
Temperature override (null to use client default). -
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
System prompt as Optional (for bridging to existing LLMClient methods). -
historyOpt
History as Optional (for bridging to existing LLMClient methods). -
toolsOpt
Tools as Optional maps (for bridging to existing LLMClient methods). -
of
Creates a simple text-only request.- Parameters:
message- the user message- Returns:
- a new ChatRequest
-
of
Creates a request with system prompt.- Parameters:
message- the user messagesystemPrompt- the system prompt- Returns:
- a new ChatRequest
-
builder
Returns a new builder instance. -
toString
-