From 47e0030939dee662d6957d15e2d893f2fe3b0040 Mon Sep 17 00:00:00 2001 From: Miyamura80 Date: Mon, 26 Jan 2026 21:34:07 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20Make=20API=20keys=20option?= =?UTF-8?q?al=20&=20add=20code=20quality=20TODOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Make all 5 LLM API keys optional with None default - Add runtime validation in llm_api_key() with descriptive errors - Add code quality issues to TODO.md (high/medium priority) Co-Authored-By: Claude Opus 4.5 --- TODO.md | 16 ++++++++++++++++ common/global_config.py | 20 +++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index fe995d5..d04d75c 100644 --- a/TODO.md +++ b/TODO.md @@ -4,3 +4,19 @@ - [ ] Integrate [Strix](https://github.com/usestrix/strix) - **Requires human supervision** - [ ] Re-init Postgres API key due to potential leak + +## Code Quality + +### High Priority + +- [ ] Broad exception handling in `src/utils/logging_config.py:64` - catches all exceptions indiscriminately +- [ ] Validator anti-pattern in `common/global_config.py:188-198` - validators ignore input parameter `v` +- [ ] Circular import risk in `common/flags.py:6-7` - `setup_logging()` called at import time +- [ ] Broad exceptions in `utils/llm/dspy_langfuse.py:280,321,438` - catches generic `Exception` +- [ ] Unsafe exception re-instantiation in `src/utils/logging_config.py:61-71` - reconstructs exceptions unsafely + +### Medium Priority + +- [ ] Type ignore comments in `utils/llm/dspy_langfuse.py` - indicates type system gaps +- [ ] Limited test coverage for `init/`, `utils/llm/` directories +- [ ] Feature flag not checked in all fallback paths diff --git a/common/global_config.py b/common/global_config.py index 77e261e..012779f 100644 --- a/common/global_config.py +++ b/common/global_config.py @@ -172,13 +172,13 @@ class Config(BaseSettings): logging: LoggingConfig features: FeaturesConfig = Field(default_factory=lambda: FeaturesConfig()) - # Environment variables (required) + # Environment variables DEV_ENV: str - OPENAI_API_KEY: str - ANTHROPIC_API_KEY: str - GROQ_API_KEY: str - PERPLEXITY_API_KEY: str - GEMINI_API_KEY: str + OPENAI_API_KEY: str | None = None + ANTHROPIC_API_KEY: str | None = None + GROQ_API_KEY: str | None = None + PERPLEXITY_API_KEY: str | None = None + GEMINI_API_KEY: str | None = None # Runtime environment (computed) is_local: bool = Field(default=False) @@ -252,7 +252,13 @@ def llm_api_key(self, model_name: str | None = None) -> str: "gemini": self.GEMINI_API_KEY, } if provider in api_keys: - return api_keys[provider] + key = api_keys[provider] + if key is None: + raise ValueError( + f"API key for provider '{provider}' is not configured. " + f"Set {provider.upper()}_API_KEY in your .env file." + ) + return key raise ValueError(f"No API key configured for model: {model_identifier}")