getMockExecutor
fun getMockExecutor(toolRegistry: ToolRegistry? = null, init: MockLLMBuilder.() -> Unit): PromptExecutor(source)
Creates a mock LLM executor for testing.
This function provides a convenient way to create a mock LLM executor with the specified tool registry and configuration. It handles the setup of the MockLLMBuilder and applies all the configured responses and tool actions.
Return
A configured PromptExecutor for testing
Example usage:
val mockLLMApi = getMockExecutor(toolRegistry) {
// Mock LLM text responses
mockLLMAnswer("Hello!") onRequestContains "Hello"
mockLLMAnswer("I don't know how to answer that.").asDefaultResponse
// Mock LLM tool calls
mockLLMToolCall(CreateTool, CreateTool.Args("solve")) onRequestEquals "Solve task"
// Mock tool behavior
mockTool(PositiveToneTool) alwaysReturns "The text has a positive tone."
mockTool(NegativeToneTool) alwaysTells {
println("Negative tone tool called")
"The text has a negative tone."
}
}
Content copied to clipboard
Parameters
toolRegistry
Optional tool registry to be used for tool execution
init
A lambda with receiver that configures the mock LLM executor