Class AiServiceTokenStreamParameters.Builder
- Enclosing class:
AiServiceTokenStreamParameters
AiServiceTokenStreamParameters.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionavailableTools(List<ToolSpecification> availableTools) Deprecated.build()Builds a newAiServiceTokenStreamParameters.commonGuardrailParams(GuardrailRequestParams commonGuardrailParams) Sets the common guardrail parameters for validating interactions between a user and a language model.completeResponseProcessingExecutor(Executor completeResponseProcessingExecutor) Sets the executor that processes each complete response received from theStreamingChatModel: updating the chat memory, executing the requested tools (or, whentoolExecutor(Executor)is set, waiting for their results), sending the next request to the model, running the output guardrails, firing the AI Service listener events and invokingTokenStream.onIntermediateResponse(java.util.function.Consumer)andTokenStream.onCompleteResponse(java.util.function.Consumer).context(AiServiceContext context) Sets the AI service context.effectiveTools(List<ToolSpecification> effectiveTools) Deprecated.usetoolServiceContext(ToolServiceContext)insteadinvocationContext(InvocationContext invocationContext) messages(List<ChatMessage> messages) Sets the messages.Sets the method key.retrievedContents(List<Content> retrievedContents) Sets the retrieved contents.toolExecutor(Executor toolExecutor) toolExecutors(Map<String, ToolExecutor> toolExecutors) Deprecated.usetoolServiceContext(ToolServiceContext)insteadtoolServiceContext(ToolServiceContext toolServiceContext) Sets the tool service context.toolSpecifications(List<ToolSpecification> toolSpecifications) Deprecated.usetoolServiceContext(ToolServiceContext)instead
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
messages
Sets the messages.- Parameters:
messages- the messages- Returns:
- this builder
-
toolServiceContext
public AiServiceTokenStreamParameters.Builder toolServiceContext(ToolServiceContext toolServiceContext) Sets the tool service context.- Since:
- 1.13.0
-
effectiveTools
@Deprecated(since="1.13.0") public AiServiceTokenStreamParameters.Builder effectiveTools(List<ToolSpecification> effectiveTools) Deprecated.usetoolServiceContext(ToolServiceContext)insteadSets effective tool specifications that should be included in the nextChatRequest.- See Also:
-
toolSpecifications
@Deprecated(since="1.12.0") public AiServiceTokenStreamParameters.Builder toolSpecifications(List<ToolSpecification> toolSpecifications) Deprecated.usetoolServiceContext(ToolServiceContext)insteadSets tool specifications that should be included in the nextChatRequest. -
availableTools
@Deprecated(since="1.13.0") public AiServiceTokenStreamParameters.Builder availableTools(List<ToolSpecification> availableTools) Deprecated.usetoolServiceContext(ToolServiceContext)insteadSets all available tool specifications configured for AI service.- See Also:
-
toolExecutors
@Deprecated(since="1.13.0") public AiServiceTokenStreamParameters.Builder toolExecutors(Map<String, ToolExecutor> toolExecutors) Deprecated.usetoolServiceContext(ToolServiceContext)insteadSets the tool executors. -
toolArgumentsErrorHandler
public AiServiceTokenStreamParameters.Builder toolArgumentsErrorHandler(ToolArgumentsErrorHandler handler) - Since:
- 1.4.0
-
toolExecutionErrorHandler
public AiServiceTokenStreamParameters.Builder toolExecutionErrorHandler(ToolExecutionErrorHandler handler) - Since:
- 1.4.0
-
toolExecutor
- Since:
- 1.4.0
-
completeResponseProcessingExecutor
public AiServiceTokenStreamParameters.Builder completeResponseProcessingExecutor(Executor completeResponseProcessingExecutor) Sets the executor that processes each complete response received from theStreamingChatModel: updating the chat memory, executing the requested tools (or, whentoolExecutor(Executor)is set, waiting for their results), sending the next request to the model, running the output guardrails, firing the AI Service listener events and invokingTokenStream.onIntermediateResponse(java.util.function.Consumer)andTokenStream.onCompleteResponse(java.util.function.Consumer). Partial responses are still delivered on the thread of theStreamingChatModel.If not set (or
null), the response is processed on the thread that delivers it, which is usually a thread of the HTTP client used by theStreamingChatModel. Use this executor when that thread must not be blocked (e.g., an event loop thread) and the processing can block (e.g., a tool, a chat memory store or an output guardrail doing I/O). The executor can also decide per task whether to run it on the calling thread. The context captured withExecutorProvider.captureContext()when the AI Service was invoked is restored on the executor's thread. LangChain4j never shuts the executor down.Anything thrown while processing the response, including an
Error, is passed toTokenStream.onError(java.util.function.Consumer). So is an exception thrown by the executor itself (e.g.,RejectedExecutionException), on the thread that delivered the response.Ignored by
AiServiceStreamingEventPublisher, which does not block the thread that delivers the response.- Since:
- 1.23.0
-
retrievedContents
Sets the retrieved contents.- Parameters:
retrievedContents- the retrieved contents- Returns:
- this builder
-
context
Sets the AI service context.- Parameters:
context- the AI service context- Returns:
- this builder
-
invocationContext
public AiServiceTokenStreamParameters.Builder invocationContext(InvocationContext invocationContext) -
commonGuardrailParams
public AiServiceTokenStreamParameters.Builder commonGuardrailParams(GuardrailRequestParams commonGuardrailParams) Sets the common guardrail parameters for validating interactions between a user and a language model.- Parameters:
commonGuardrailParams- an instance ofGuardrailRequestParamscontaining the shared parameters required for guardrail checks, such as chat memory, user message template, and additional variables.- Returns:
- this builder instance.
-
methodKey
Sets the method key.- Parameters:
methodKey- the method key- Returns:
- this builder
-
build
Builds a newAiServiceTokenStreamParameters.- Returns:
- a new
AiServiceTokenStreamParameters
-
toolServiceContext(ToolServiceContext)instead