Module: Deja
- Defined in:
- lib/deja.rb,
lib/deja/cache.rb,
lib/deja/rspec.rb,
lib/deja/session.rb,
lib/deja/version.rb,
lib/deja/judges/base.rb,
lib/deja/adapters/base.rb,
lib/deja/configuration.rb,
lib/deja/judges/anthropic.rb,
lib/deja/adapters/anthropic.rb,
lib/deja/requirements_cache.rb
Overview
Deja records a non-deterministic call (today: an Anthropic LLM call) the first time it happens and replays the recorded response on every run after that, so tests that exercise real model behavior stay fast, offline, and deterministic.
Providers are pluggable via adapters (see Deja::Adapters) — a suite can mix them, and each test exercises whichever it actually calls.
It also ships ‘meet_requirements`, an RSpec matcher that asserts an LLM-produced value satisfies a free-text description (judged once, then cached).
See README.md for the full record/replay workflow and configuration.
Defined Under Namespace
Modules: Adapters, Cache, Helpers, Judges, RequirementsCache, Session Classes: Configuration, Error, MissingCacheError, MissingIdError
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.adapters ⇒ Object
The registered adapters, in registration order.
-
.calls ⇒ Object
— captured calls (reset per example by Session.enable) —.
- .configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
Configure the gem.
- .record_call(provider, method, kwargs) ⇒ Object
-
.register(provider, **opts) ⇒ Object
Register a provider adapter (delegates to the configuration).
- .reset_calls! ⇒ Object
-
.reset_configuration! ⇒ Object
Drops configuration and the captured call log — used between examples and by the gem’s own suite.
Class Method Details
.adapters ⇒ Object
The registered adapters, in registration order.
57 58 59 |
# File 'lib/deja.rb', line 57 def adapters configuration.adapters.values end |
.calls ⇒ Object
— captured calls (reset per example by Session.enable) —
63 64 65 |
# File 'lib/deja.rb', line 63 def calls @calls ||= [] end |
.configuration ⇒ Object
39 40 41 |
# File 'lib/deja.rb', line 39 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configure the gem. Yields the Configuration; returns it.
Deja.configure do |c|
c.cache_root = Rails.root.join("spec/support/cache")
c.register :anthropic,
install: ->(client) { allow(AnthropicClient).to receive(:client).and_return(client) }
end
34 35 36 37 |
# File 'lib/deja.rb', line 34 def configure yield(configuration) configuration end |
.record_call(provider, method, kwargs) ⇒ Object
67 68 69 |
# File 'lib/deja.rb', line 67 def record_call(provider, method, kwargs) calls << {provider:, method:, kwargs:} end |
.register(provider, **opts) ⇒ Object
Register a provider adapter (delegates to the configuration). See Configuration#register.
52 53 54 |
# File 'lib/deja.rb', line 52 def register(provider, **opts) configuration.register(provider, **opts) end |
.reset_calls! ⇒ Object
71 72 73 |
# File 'lib/deja.rb', line 71 def reset_calls! @calls = [] end |
.reset_configuration! ⇒ Object
Drops configuration and the captured call log — used between examples and by the gem’s own suite.
45 46 47 48 |
# File 'lib/deja.rb', line 45 def reset_configuration! @configuration = Configuration.new reset_calls! end |