Class MockChatModel
java.lang.Object
io.helidon.integrations.langchain4j.providers.mock.MockChatModel
- All Implemented Interfaces:
dev.langchain4j.model.chat.ChatModel,RuntimeType.Api<MockChatModelConfig>
public class MockChatModel
extends Object
implements RuntimeType.Api<MockChatModelConfig>, dev.langchain4j.model.chat.ChatModel
Mock implementation of
ChatModel for testing.
This model evaluates the list of MockChatRule defined in configuration or injected as singleton service.
The first rule that matches the incoming ChatRequest
is used to generate a mock ChatResponse. If no rule matches, a default rule is applied.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the list ofMockChatRules currently used by this model.static MockChatModelConfig.Builderbuilder()Returns a newMockChatModelConfig.Builderinstance for building a configuration.static MockChatModelcreate(MockChatModelConfig config) Creates a newMockChatModelinstance using the provided configuration.static MockChatModelcreate(Consumer<MockChatModelConfig.Builder> consumer) Creates a newMockChatModelinstance using a builder consumer to configure the model.dev.langchain4j.model.chat.response.ChatResponsedoChat(dev.langchain4j.model.chat.request.ChatRequest chatRequest) Returns the configuration prototype of this mock chat model.voidResets the mock chat rules to the original set defined in the 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.ChatModel
chat, chat, chat, chat, defaultRequestParameters, listeners, provider, supportedCapabilities
-
Method Details
-
create
Creates a newMockChatModelinstance using the provided configuration.- Parameters:
config- the mock chat model configuration- Returns:
- a new
MockChatModel
-
create
Creates a newMockChatModelinstance using a builder consumer to configure the model.- Parameters:
consumer- a consumer that modifies theMockChatModelConfig.Builder- Returns:
- a new
MockChatModel
-
builder
Returns a newMockChatModelConfig.Builderinstance for building a configuration.- Returns:
- a builder for
MockChatModelConfig
-
doChat
public dev.langchain4j.model.chat.response.ChatResponse doChat(dev.langchain4j.model.chat.request.ChatRequest chatRequest) - Specified by:
doChatin interfacedev.langchain4j.model.chat.ChatModel
-
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 mock chat rules to the original set defined in the configuration.This method clears any modifications made to the
activeRules()list and restores the rules from the initialMockChatModelConfig. -
prototype
Returns the configuration prototype of this mock chat model.- Specified by:
prototypein interfaceRuntimeType.Api<MockChatModelConfig>- Returns:
- the
MockChatModelConfigused by this model
-