feat: gem-level credential configuration (Locallingo.configure + .locallingo.rb) - #3
Merged
Merged
Conversation
Keys were only ever read from process ENV, so apps whose credentials live
elsewhere (an app config object, Rails credentials, a vault) had no way to
hand them to the gem outside a Rails initializer.
- New Locallingo::Settings with per-provider api-key accessors; values are
Strings or callables (resolved fresh on every LLM call, never memoized)
- Locallingo.configure { |c| c.anthropic_api_key = ... } yields the memoized
settings; reset_settings! for test isolation
- Providers::RubyLLM resolves keys across three sources, first wins:
Locallingo settings -> host RubyLLM.config -> ENV. credentials? and
ensure_credentials! now see all three, and the error message names each
option.
bin/lingo never boots Rails, so initializers can't configure credentials for standalone runs. The CLI now loads an optional .locallingo.rb from the project root (next to .locallingo.yml) before dispatching — the place for Locallingo.configure. Absent file is silent; errors propagate loudly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #2, which only filled RubyLLM's key from process ENV. Juraj's report: zazu keeps its Anthropic key in
AppConf, andbin/lingois a plain Bundler binstub — no Rails boot, no dotenv — so standalone CLI runs could never see it. The gem needed a way to receive credentials outside a Rails initializer.Locallingo.configure { |c| c.anthropic_api_key = ... }— newLocallingo::Settingswith per-provider api-key accessors (same provider set asCREDENTIAL_ENV). Values are Strings or callables; callables are resolved fresh on every LLM call, never memoized, so keys can come from sources that rotate or aren't ready at configure time..locallingo.rbsetup file — the CLI loads it from the project root before dispatch. Absent file is silent; errors in it propagate loudly.Locallingo.configure→ hostRubyLLM.config(Rails initializer) → ENV.credentials?/ensure_credentials!now see all three sources, and the missing-credentials error names each option.Test plan
bundle exec rake)ANTHROPIC_API_KEYunset in the shell,bin/lingo translate --dry-runpreviously failed withNo credentials for provider :anthropic; with this branch + a.locallingo.rb(Dotenv → AppConf →Locallingo.configure) it completes, and the resolved key is the real 108-charsk-ant-api…from.envviaAppConf.anthropic_api_keyZazu-side wiring PR follows separately.