Class MockStreamingChatModel
- All Implemented Interfaces:
dev.langchain4j.model.chat.StreamingChatModel,RuntimeType.Api<MockStreamingChatModelConfig>
This model evaluates incoming chat requests against a set of MockChatRules and
streams the corresponding mock responses. If no rule matches, a default mock response is used.
Rules are initialized from the provided MockStreamingChatModelConfig and can be inspected
and modified at runtime using activeRules() and resetRules().
-
Method Summary
Modifier and TypeMethodDescriptionReturns the list ofMockChatRules currently used by this model.builder()Returns a newMockStreamingChatModelConfig.Builderinstance for building a configuration.static MockStreamingChatModelcreate(MockStreamingChatModelConfig config) Creates a newMockStreamingChatModelinstance using the provided configuration.static MockStreamingChatModelcreate(Consumer<MockStreamingChatModelConfig.Builder> consumer) Creates a newMockStreamingChatModelinstance using a builder consumer to configure the model.voiddoChat(dev.langchain4j.model.chat.request.ChatRequest chatRequest, dev.langchain4j.model.chat.response.StreamingChatResponseHandler handler) Processes a chat request and streams the mock response to the provided handler.Returns the configuration prototype of this mock chat model.voidResets the active mock chat rules to the original set defined by the initial configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.langchain4j.model.chat.StreamingChatModel
chat, chat, chat, defaultRequestParameters, listeners, provider, supportedCapabilities
-
Method Details
-
create
Creates a newMockStreamingChatModelinstance using the provided configuration.- Parameters:
config- the mock chat model configuration- Returns:
- a new
MockStreamingChatModel
-
create
public static MockStreamingChatModel create(Consumer<MockStreamingChatModelConfig.Builder> consumer) Creates a newMockStreamingChatModelinstance using a builder consumer to configure the model.- Parameters:
consumer- a consumer that modifies theMockStreamingChatModelConfig.Builder- Returns:
- a new
MockStreamingChatModel
-
builder
Returns a newMockStreamingChatModelConfig.Builderinstance for building a configuration.- Returns:
- a builder for
MockStreamingChatModelConfig
-
doChat
public void doChat(dev.langchain4j.model.chat.request.ChatRequest chatRequest, dev.langchain4j.model.chat.response.StreamingChatResponseHandler handler) Processes a chat request and streams the mock response to the provided handler.The request is evaluated against the configured
MockChatRules in order; the first matching rule is used to produce and stream the response. If no rule matches, the default rule is applied.- Specified by:
doChatin interfacedev.langchain4j.model.chat.StreamingChatModel- Parameters:
chatRequest- the incoming chat request to evaluatehandler- the response handler that receives streamed response chunks and completion events
-
activeRules
Returns the list ofMockChatRules currently used by this model.The returned list is the live internal list; modifications to it will affect the model's behavior. Use
resetRules()to restore the original configuration.- Returns:
- mutable list of mock chat rules
-
resetRules
public void resetRules()Resets the active mock chat rules to the original set defined by the initial configuration.This method clears any modifications made to the
activeRules()list and restores the rules from the initialMockStreamingChatModelConfig. -
prototype
Returns the configuration prototype of this mock chat model.- Specified by:
prototypein interfaceRuntimeType.Api<MockStreamingChatModelConfig>- Returns:
- the
MockStreamingChatModelConfigused by this model
-