Class ChatRequestAssert
java.lang.Object
org.assertj.core.api.AbstractAssert<ChatRequestAssert, ChatRequest>
org.assertj.core.api.AbstractObjectAssert<ChatRequestAssert, ChatRequest>
dev.langchain4j.test.model.ChatRequestAssert
- All Implemented Interfaces:
org.assertj.core.api.Assert<ChatRequestAssert, ChatRequest>, org.assertj.core.api.Descriptable<ChatRequestAssert>, org.assertj.core.api.ExtensionPoints<ChatRequestAssert, ChatRequest>
@Experimental
public final class ChatRequestAssert
extends org.assertj.core.api.AbstractObjectAssert<ChatRequestAssert, ChatRequest>
Assertions on a request sent to a chat model: its messages and the tools it offers. Use them to check what an AI
Service sent to the model, for example that the system message and the prompt template were filled in as expected.
To get the requests, capture what the AI Service does with
AiServiceCapture:
import static dev.langchain4j.test.LangChain4jAssertions.assertThat;
import static dev.langchain4j.test.service.AiServiceCapture.capture;
AiServiceCapture capture = capture(() -> assistant.chat("Cancel booking MS-777"));
assertThat(capture.firstRequest())
.hasSystemMessageContaining("support agent")
.hasUserMessageContaining("MS-777")
.hasToolSpecification("cancelBooking");
Any other ChatRequest can be checked too, for example the request a mock received
(MockChatModel.request()) or one collected by a ChatModelListener. When an
assertion fails, the message lists all messages or tools of the request; each message text is cut to 1000
characters.-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsConstructorDescriptionChatRequestAssert(ChatRequest actual) Creates assertions on the given chat request. -
Method Summary
Modifier and TypeMethodDescriptionAsserts that the last user message of the request contains the given text.Asserts that the request has a system message containing the given text.hasToolSpecification(String toolName) Asserts that the request offers the model the tool with the given name.Asserts that the request has a user message containing the given text.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Constructor Details
-
ChatRequestAssert
Creates assertions on the given chat request. PreferLangChain4jAssertions.assertThat(ChatRequest).
-
-
Method Details
-
hasSystemMessageContaining
Asserts that the request has a system message containing the given text. -
hasUserMessageContaining
Asserts that the request has a user message containing the given text. All user messages of the request are checked, including those from the chat memory, not only the last one: to check only the message of the current turn, usehasLastUserMessageContaining(String). The text of a user message includes what the AI Service added to it, for example the retrieved contents. -
hasLastUserMessageContaining
Asserts that the last user message of the request contains the given text. In the first request of an AI Service invocation, this is the message of the current turn: the messages from the chat memory come before it. The text of a user message includes what the AI Service added to it, for example the retrieved contents. -
hasToolSpecification
Asserts that the request offers the model the tool with the given name.
-