Package org.mockserver.client
Class TurnBuilder
- java.lang.Object
-
- org.mockserver.client.TurnBuilder
-
public class TurnBuilder extends Object
Sub-builder for configuring a single turn within an LLM conversation mock.Provides fluent predicates for matching inbound requests and a response to return when all predicates match. Returns to the parent
LlmConversationBuilderviaandThen().
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LlmConversationBuilderandThen()Return to the parent conversation builder for chaining additional turns.Expectation[]applyTo(MockServerClient client)Shortcut: build and register all turns with the MockServerClient.TurnBuilderrespondingWith(Completion completion)Set the completion to return for this turn.TurnBuilderwhenContainsToolResultFor(String toolName)Match when the conversation contains a tool result for a prior call of the named tool.TurnBuilderwhenLatestMessageContains(String text)Match when the latest message's text content contains the given substring.TurnBuilderwhenLatestMessageContains(Pattern regex)Match when the latest message's text content matches the given regex.TurnBuilderwhenLatestMessageRole(ParsedMessage.Role role)Match when the latest message has the given role.TurnBuilderwhenTurnIndex(int n)Match when the conversation has exactlynassistant turns.
-
-
-
Method Detail
-
whenTurnIndex
public TurnBuilder whenTurnIndex(int n)
Match when the conversation has exactlynassistant turns.- Parameters:
n- the turn index (0-based count of assistant messages)- Returns:
- this builder
-
whenLatestMessageContains
public TurnBuilder whenLatestMessageContains(String text)
Match when the latest message's text content contains the given substring.- Parameters:
text- the substring to match- Returns:
- this builder
-
whenLatestMessageContains
public TurnBuilder whenLatestMessageContains(Pattern regex)
Match when the latest message's text content matches the given regex.- Parameters:
regex- the regex pattern to match- Returns:
- this builder
- Throws:
IllegalArgumentException- if the regex fails to compile
-
whenLatestMessageRole
public TurnBuilder whenLatestMessageRole(ParsedMessage.Role role)
Match when the latest message has the given role.- Parameters:
role- the role to match- Returns:
- this builder
-
whenContainsToolResultFor
public TurnBuilder whenContainsToolResultFor(String toolName)
Match when the conversation contains a tool result for a prior call of the named tool.- Parameters:
toolName- the tool name to look for- Returns:
- this builder
-
respondingWith
public TurnBuilder respondingWith(Completion completion)
Set the completion to return for this turn.- Parameters:
completion- the completion response- Returns:
- this builder
-
andThen
public LlmConversationBuilder andThen()
Return to the parent conversation builder for chaining additional turns.- Returns:
- the parent LlmConversationBuilder
-
applyTo
public Expectation[] applyTo(MockServerClient client)
Shortcut: build and register all turns with the MockServerClient. Delegates to the parent builder'sapplyTo.- Parameters:
client- the MockServerClient- Returns:
- the created expectations
-
-