Uses of Class
dev.langchain4j.test.mock.MockStreamingChatModel
Packages that use MockStreamingChatModel
Package
Description
Model mocks for tests: they need no network, answer the way a test tells them to, and record the requests they
receive.
-
Uses of MockStreamingChatModel in dev.langchain4j.test.mock
Methods in dev.langchain4j.test.mock that return MockStreamingChatModelModifier and TypeMethodDescriptionMockStreamingChatModel.andFails(RuntimeException exception) Makes the response of the last step fail after its thinking and text were streamed, the way a broken connection does: the handler gets the partial responses and then the error, but no tool calls and no complete response.static MockStreamingChatModelMockStreamingChatModel.thatCallsTool(String toolName, String jsonArguments) A model that answers the first request with a call of the given tool.static MockStreamingChatModelMockStreamingChatModel.thatCallsTool(String toolName, Map<String, ?> arguments) A model that answers the first request with a call of the given tool.static MockStreamingChatModelMockStreamingChatModel.thatFails(RuntimeException exception) A model whose first request fails with the given exception, before anything is streamed: the handler gets it inonError.static MockStreamingChatModelMockStreamingChatModel.thatResponds(AiMessage... aiMessages) A model that streams the given messages in order, one per request, in word-like tokens.static MockStreamingChatModelMockStreamingChatModel.thatResponds(ChatResponse chatResponse) A model that answers the first request by streaming the message of the given response, in word-like tokens, and completing with exactly that response, including its metadata, for example its token usage, model name or finish reason.static MockStreamingChatModelMockStreamingChatModel.thatResponds(String text) A model that answers the first request by streaming the given text, in word-like tokens.static MockStreamingChatModelMockStreamingChatModel.thatResponds(Function<ChatRequest, AiMessage> answers) A model that computes the answer to the first request from the request and streams it, in word-like tokens.static MockStreamingChatModelMockStreamingChatModel.thatResponds(List<AiMessage> aiMessages) A model that streams the given messages in order, one per request, in word-like tokens.static MockStreamingChatModelMockStreamingChatModel.thatStreams(String... tokens) A model that answers the first request by streaming exactly the given tokens, which together make up one answer:thatStreams("Hel", "lo")streams"Hel"and then"lo", and completes with"Hello".static MockStreamingChatModelMockStreamingChatModel.thatStreams(List<String> tokens) A model that answers the first request by streaming exactly the given tokens, seeMockStreamingChatModel.thatStreams(String...).MockStreamingChatModel.thenCallsTool(String toolName, String jsonArguments) Adds a step: the next request is answered with a call of the given tool.MockStreamingChatModel.thenCallsTool(String toolName, Map<String, ?> arguments) Adds a step: the next request is answered with a call of the given tool.MockStreamingChatModel.thenFails(RuntimeException exception) Adds a step: the next request fails with the given exception before anything is streamed.MockStreamingChatModel.thenRepeats()Answers every further request with the last step of the script.MockStreamingChatModel.thenResponds(AiMessage aiMessage) Adds a step: the next request is answered by streaming the given message, in word-like tokens.MockStreamingChatModel.thenResponds(ChatResponse chatResponse) Adds a step: the next request is answered by streaming the message of the given response, in word-like tokens, and completing with exactly that response, including its metadata, for example its token usage.MockStreamingChatModel.thenResponds(String text) Adds a step: the next request is answered by streaming the given text, in word-like tokens.MockStreamingChatModel.thenStreams(String... tokens) Adds a step: the next request is answered by streaming exactly the given tokens, which together make up one answer.MockStreamingChatModel.thenStreams(List<String> tokens) Adds a step: the next request is answered by streaming exactly the given tokens, seeMockStreamingChatModel.thenStreams(String...).MockStreamingChatModel.withListeners(ChatModelListener... listeners) Notifies the given listeners of each call, like a real model does.MockStreamingChatModel.withListeners(List<ChatModelListener> listeners) Notifies the given listeners of each call, like a real model does.MockStreamingChatModel.withSupportedCapabilities(Capability... capabilities) Reports the given capabilities fromMockStreamingChatModel.supportedCapabilities(), like a model that supports them.MockStreamingChatModel.withSupportedCapabilities(Set<Capability> capabilities) Reports the given capabilities fromMockStreamingChatModel.supportedCapabilities(), seeMockStreamingChatModel.withSupportedCapabilities(Capability...).MockStreamingChatModel.withTokenUsage(@Nullable TokenUsage tokenUsage) Reports the given token usage in the response to every request, except for a step that gives the whole response: that one reports exactly its own token usage.