Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ Metrics/BlockLength:
- "*.gemspec"
- "test/**/*.rb"

# Test classes are naturally long
# Test classes are naturally long; Configuration is mostly declarative
# (grouped settings + flat compatibility aliases)
Metrics/ClassLength:
Exclude:
- "test/**/*.rb"
- "lib/llm_optimizer/configuration.rb"

# validate!/validate_values! raise on failure and return true (like AR's save!)
Naming/PredicateMethod:
AllowedMethods:
- validate!
- validate_values!

# The optimize method is intentionally a pipeline — complexity is expected
Metrics/MethodLength:
Expand Down
32 changes: 31 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.0] - 2026-07-15

Ease-of-use refactor: one adapter interface replaces the four caller lambdas, configuration is grouped and validated, and the Rails initializer shrinks to a minimal working config. 0.1.x initializers keep working via compatibility aliases.

### Added
- **Adapter interface** (`config.adapter`) — the single integration point between the gem and your LLM provider. Built-in adapters: `:ruby_llm` (chat + embeddings across OpenAI/Anthropic/Gemini/Bedrock/Ollama), `:open_ai` (ruby-openai, chat + embeddings), `:anthropic` (official anthropic gem, chat only). Adapter gems are lazily required with an actionable error if missing
- `LlmOptimizer::Adapters::Custom` — wrap any provider with `chat:` / `embed:` lambdas
- **Grouped configuration** — `config.routing.*`, `config.cache.*`, `config.compression.*`, `config.history.*`, `config.conversation.*`; flat 0.1.x keys remain as aliases
- `config.routing.classifier_model` — enables the LLM routing classifier through the adapter (replaces hand-written `classifier_caller` lambdas)
- **Fail-fast validation** — `LlmOptimizer.configure` validates values immediately; each `optimize` call validates cross-field consistency; `LlmOptimizer.validate!` runs the full check at boot with actionable error messages
- **Defensive lambda invocation** (`LlmOptimizer::Invoker`) — user-supplied lambdas only receive the keyword arguments their signature accepts, so lambdas written against older signatures keep working
- `schema` config option is now actually passed through to adapters (it was declared but unused in 0.1.7)

### Changed
- **Rails initializer template rewritten** — ~25-line minimal working config with advanced options in a commented appendix, instead of 120 lines of mixed provider examples
- Default complex model updated from `claude-3-5-sonnet-20241022` to `claude-sonnet-4-5`
- `embedding_model` default is now `nil` (the adapter picks its own default) and lives at `cache.embedding_model`
- `llm_caller`, `messages_caller`, `embedding_caller`, `classifier_caller` are deprecated; when set they are wrapped in an internal legacy adapter automatically
- Enabling the semantic cache without `redis_url` or embedding support now raises `ConfigurationError` instead of silently disabling the cache (`validate_configuration!` removed)
- Semantic cache lookup no longer connects to a default localhost Redis when `redis_url` is unset — it logs a warning and skips the cache

### Fixed
- `llm_caller` lambdas written as `->(prompt, model:)` (the documented signature) crashed with `unknown keyword: :tools` since 0.1.6 — the gem passed `tools:` unconditionally; lambdas now only receive keywords they accept
- History summarization injected a `[content, token_info]` array as the summary message content instead of the summary string
- `tools` and `with_tools` are now true aliases of one value instead of two separate config keys
- Removed dead code: unused `tools_caller` config key and the never-assigned `@_current_llm_caller`

## [0.1.7] - 2026-05-05

### Added
Expand Down Expand Up @@ -127,7 +154,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `OptimizeResult` struct with `response`, `model`, `model_tier`, `cache_status`, `original_tokens`, `compressed_tokens`, `latency_ms`, `messages`
- Unit test suite covering all components with positive and negative scenarios using Minitest + Mocha

[Unreleased]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.5...HEAD
[Unreleased]: https://github.com/arunkumarry/llm_optimizer/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.7...v0.2.0
[0.1.7]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.6...v0.1.7
[0.1.6]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/arunkumarry/llm_optimizer/compare/v0.1.2...v0.1.3
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
llm_optimizer (0.1.6)
llm_optimizer (0.2.0)
logger (~> 1.6)
msgpack (~> 1.7)
redis (~> 5.0)
Expand Down Expand Up @@ -107,7 +107,7 @@ CHECKSUMS
json (2.19.3) sha256=289b0bb53052a1fa8c34ab33cc750b659ba14a5c45f3fcf4b18762dc67c78646
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
llm_optimizer (0.1.6)
llm_optimizer (0.2.0)
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
minitest (5.27.0) sha256=2d3b17f8a36fe7801c1adcffdbc38233b938eb0b4966e97a6739055a45fa77d5
mocha (2.8.2) sha256=1f77e729db47e72b4ef776461ce20caeec2572ffdf23365b0a03608fee8f4eee
Expand Down
Loading
Loading