-
Notifications
You must be signed in to change notification settings - Fork 0
Auto-detect DEFAULT_PROVIDER from whichever LLM API key is set #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,9 +229,34 @@ def _empty_str_to_none_int(cls, v: object) -> object: | |
| FIRESTORE_DATABASE_NAME: str = "default" # Firestore database name (default: "(default)") | ||
|
|
||
| # LLM Provider Configuration | ||
| # Active LLM provider: "openrouter" (default) or "anthropic". | ||
| # Active LLM provider: "openrouter" (default) or "anthropic". Auto-detected from | ||
| # whichever API key is set when left unset — see _infer_default_provider_from_keys. | ||
| # Set explicitly to override the auto-detection (e.g. both keys present but you | ||
| # want Anthropic). | ||
| DEFAULT_PROVIDER: LLMProvider = LLMProvider.OPENROUTER | ||
|
|
||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def _infer_default_provider_from_keys(cls, data: object) -> object: | ||
| """Infer DEFAULT_PROVIDER from whichever API key is set, when not explicit. | ||
|
|
||
| Single source of truth for the auto-detection documented in | ||
| .env.quickstart.example ("set ONE of the two keys ... if both are set, | ||
| OpenRouter is used by default"). Runs on every Settings() construction — | ||
| not only at `specflow-init.sh` time — so switching keys by hand later | ||
| (without re-running init) still resolves to the right provider instead | ||
| of silently falling back to OpenRouter and failing startup validation. | ||
|
Comment on lines
+243
to
+248
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this logic will be buried here - better to remove this docstring and just explain this in Settings class as it is now. And make sure README / QUICKSTART have same wording |
||
| """ | ||
| if not isinstance(data, dict): | ||
| return data | ||
| if not data.get("DEFAULT_PROVIDER"): | ||
| data.pop("DEFAULT_PROVIDER", None) | ||
| anthropic_key = data.get("ANTHROPIC_API_KEY") | ||
| openrouter_key = data.get("OPENROUTER_API_KEY") | ||
| if anthropic_key and not openrouter_key: | ||
| data["DEFAULT_PROVIDER"] = LLMProvider.ANTHROPIC.value | ||
| return data | ||
|
|
||
| # LLM Model Tier Configuration | ||
| # Values follow OpenRouter naming convention: provider/model (e.g., anthropic/claude-opus-4.5) | ||
| # Can be comma-separated for multiple models (used in multi-workspace generation for variance reduction) | ||
|
|
||
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this hooked to the DEFAULT_PROVIDER field?? I dont see direct connection