Class ChatRequest.Builder
java.lang.Object
com.codename1.ai.ChatRequest.Builder
- Enclosing class:
ChatRequest
Mutable fluent builder for
ChatRequest. Collection arguments
are copied when the immutable request is built.-
Method Summary
Modifier and TypeMethodDescriptionAppends one conversation message.build()Validates and creates an immutable request.Limits response length.messages(List<ChatMessage> messages) Replaces the conversation history.Attaches provider-specific request metadata.Selects a provider model.Requests text or structured JSON output.Installs a client-side filter evaluated before network submission.Requests deterministic sampling where supported.stopSequences(List<String> stops) Sets sequences that terminate generation.temperature(Float t) Sets sampling temperature.toolChoice(ToolChoice choice) Controls whether and which tool the model may call.Replaces the callable tools advertised to the model.Sets nucleus sampling probability.
-
Method Details
-
model
Selects a provider model.- Parameters:
model- provider model id;nulluses the client default- Returns:
- this builder
-
messages
Replaces the conversation history.- Parameters:
messages- messages in chronological order;nullclears them- Returns:
- this builder
-
addMessage
Appends one conversation message.- Parameters:
m- message to append- Returns:
- this builder
-
temperature
Sets sampling temperature.- Parameters:
t- provider-supported temperature, ornullto omit- Returns:
- this builder
-
maxTokens
Limits response length.- Parameters:
n- maximum generated token count, ornullto omit- Returns:
- this builder
-
topP
Sets nucleus sampling probability.- Parameters:
p- provider-supported probability, ornullto omit- Returns:
- this builder
-
stopSequences
Sets sequences that terminate generation.- Parameters:
stops- stop strings, ornullfor none- Returns:
- this builder
-
seed
Requests deterministic sampling where supported.- Parameters:
seed- provider sampling seed, ornullto omit- Returns:
- this builder
-
responseFormat
Requests text or structured JSON output.- Parameters:
f- desired format, ornullfor provider default- Returns:
- this builder
-
tools
Replaces the callable tools advertised to the model.- Parameters:
tools- tool definitions, ornullfor none- Returns:
- this builder
-
toolChoice
Controls whether and which tool the model may call.- Parameters:
choice- selection policy, ornullfor provider default- Returns:
- this builder
-
metadata
Attaches provider-specific request metadata.- Parameters:
meta- metadata copied into the request, ornull- Returns:
- this builder
-
safetyFilter
Installs a client-side filter evaluated before network submission.- Parameters:
f- safety policy, ornullto disable it- Returns:
- this builder
-
build
Validates and creates an immutable request.- Returns:
- completed request
- Throws:
IllegalStateException- when no messages were supplied
-