Mock LLM implementation for testing.
Returns deterministic responses for testing the optimization loop without making actual API calls. Useful for:
- Unit testing
- Integration testing
- CI/CD pipelines
- Development without API keys
Examples
# With fixed responses
llm = GEPA.LLM.Mock.new(responses: ["Response 1", "Response 2"])
{:ok, "Response 1"} = GEPA.LLM.complete(llm, "Any prompt")
{:ok, "Response 2"} = GEPA.LLM.complete(llm, "Any prompt")
# With dynamic response function
llm = GEPA.LLM.Mock.new(response_fn: fn p -> "Echo: " <> p end)
{:ok, "Echo: Hello"} = GEPA.LLM.complete(llm, "Hello")
# Default behavior (improved instructions)
llm = GEPA.LLM.Mock.new()
{:ok, response} = GEPA.LLM.complete(llm, "test prompt")
Summary
Functions
Legacy complete function for backward compatibility.
Legacy generate function for backward compatibility.
Creates a new Mock LLM instance.
Types
@type t() :: %GEPA.LLM.Mock{ call_count: non_neg_integer(), response_fn: (GEPA.LLM.prompt() -> String.t()) | nil, responses: [String.t()] | nil }
Functions
Legacy complete function for backward compatibility.
Prefer using GEPA.LLM.complete/3 instead.
Legacy generate function for backward compatibility.
Prefer using GEPA.LLM.complete/3 instead.
Creates a new Mock LLM instance.
Options
:responses- List of fixed responses to cycle through:response_fn- Function to generate dynamic responses (prompt -> response)- If neither is provided, uses default improvement behavior
Examples
# Fixed responses
llm = GEPA.LLM.Mock.new(responses: ["Yes", "No", "Maybe"])
# Dynamic responses
llm = GEPA.LLM.Mock.new(response_fn: fn p -> "Processed: " <> String.upcase(p) end)
# Default behavior
llm = GEPA.LLM.Mock.new()