GEPA.LLM.Mock (GEPA v0.3.0)

Copy Markdown View Source

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

t()

@type t() :: %GEPA.LLM.Mock{
  call_count: non_neg_integer(),
  response_fn: (GEPA.LLM.prompt() -> String.t()) | nil,
  responses: [String.t()] | nil
}

Functions

complete(messages)

@spec complete([map()]) :: {:ok, %{content: String.t()}}

Legacy complete function for backward compatibility.

Prefer using GEPA.LLM.complete/3 instead.

generate(prompt)

@spec generate(String.t()) :: {:ok, String.t()}

Legacy generate function for backward compatibility.

Prefer using GEPA.LLM.complete/3 instead.

new(opts \\ [])

@spec new(keyword()) :: t()

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()