Add configurable LLM request headers - #118
Conversation
📝 WalkthroughWalkthroughAdds environment-based custom HTTP headers for primary and fallback LLM providers. Headers are strictly parsed, stored immutably, validated against provider compatibility, passed through composition, and forwarded to any-llm clients as ChangesLLM header configuration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Environment
participant Settings.from_env
participant llm_provider
participant create_any_llm_provider
participant AnyLLM
Environment->>Settings.from_env: LLM_EXTRA_HEADERS and fallback headers
Settings.from_env-->>llm_provider: validated immutable mappings
llm_provider->>create_any_llm_provider: primary or fallback extra_headers
create_any_llm_provider->>AnyLLM: default_headers client argument
AnyLLM-->>llm_provider: configured provider adapter
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/agentic_review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #118 +/- ##
========================================
Coverage 99.85% 99.86%
========================================
Files 111 115 +4
Lines 11989 12154 +165
Branches 716 729 +13
========================================
+ Hits 11972 12137 +165
Misses 12 12
Partials 5 5 ☔ View full report in Codecov by Harness. |
Code Review by Qodo
Context used✅ Compliance rules (platform):
46 rules 1.
|
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 6a00c0f |
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 974df1c |
974df1c to
77db7f9
Compare
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 77db7f9 |
f500cfd to
77a2a24
Compare
00d9707 to
ce273ef
Compare
69110da to
74fff44
Compare
74fff44 to
c71033d
Compare
PR Summary by QodoAdd configurable LLM request headers with strict JSON parsing
AI Description
Diagram
High-Level Assessment
Files changed (13)
|
|
Code review by qodo was updated up to the latest commit c71033d |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@weather_briefing/config/settings.py`:
- Around line 311-319: The _validate_llm_headers_provider function checks the
raw provider spelling instead of the canonical identifier used by
create_any_llm_provider. Canonicalize the provider before comparing it with
UNSUPPORTED_DEFAULT_HEADER_PROVIDERS, and add primary coverage for an
unsupported uppercase provider plus fallback coverage for
LLM_FALLBACK_EXTRA_HEADERS while preserving the existing ConfigurationError
behavior.
In `@weather_briefing/llm/any_llm.py`:
- Around line 264-280: The provider/header validation in create_any_llm_provider
must use the same canonical provider representation as settings validation.
Update the relevant settings validation for LLM_PROVIDER and
LLM_FALLBACK_PROVIDER to resolve each value through AnyLLM.get_provider_class
and validate header support against PROVIDER_NAME, preserving existing behavior
for unsupported providers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c9d359b7-1067-439b-a491-91b876ce63db
📒 Files selected for processing (13)
docs/design.mddocs/notes.mdenv.exampletests/test_any_llm_compatibility.pytests/test_any_llm_provider.pytests/test_cli.pytests/test_config.pytests/test_http_headers.pyweather_briefing/composition/providers.pyweather_briefing/config/http_headers.pyweather_briefing/config/settings.pyweather_briefing/data/any_llm_compatibility.pyweather_briefing/llm/any_llm.py
Adds strict JSON configuration for primary and fallback LLM request headers, forwarding non-empty mappings through the existing any-llm compatibility layer. Covers DeepSeek, OpenAI, and OpenRouter with transport-level tests and privacy-safe validation. Stacked on #115. Verification: prek passed; 1187 tests passed; line coverage 99.90%; branch coverage 99.66%.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation