支持在大模型配置中设置 User-Agent#178
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds optional ChangesCustom HTTP Headers for LLM Requests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@frontend/src/components/workbench/LLMControlPanel.vue`:
- Around line 480-486: The current setSelectedUserAgent(userAgent) replaces
extraHeadersText with a header merge from the last committed
selectedProfile.value.extra_headers and therefore silently discards any
uncommitted edits in extraHeadersText; change it to first attempt to parse
extraHeadersText.value (falling back to selectedProfile.value.extra_headers if
parsing fails) and merge the User-Agent into that parsed/active headers object,
then assign the merged headers back to both selectedProfile.value.extra_headers
and extraHeadersText.value (using prettyJson); apply the identical change to the
other User-Agent update handler at lines 488-490 so both handlers preserve
uncommitted editor changes when injecting the UA header.
🪄 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: 3496f7ef-bbe9-4aaf-8c57-56fa628e1378
📒 Files selected for processing (4)
frontend/src/api/llmControl.tsfrontend/src/components/workbench/LLMControlPanel.vueinfrastructure/ai/provider_factory.pyinterfaces/api/v1/workbench/llm_control.py
5a2c1b4 to
b844fa9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/unit/interfaces/test_openai_models_base.py (1)
56-85: ⚡ Quick winConsider asserting that
trust_env=Falseis passed to the HTTP client.The upstream
list_modelsimplementation explicitly passestrust_env=Falsetohttpx.AsyncClientto prevent inheriting system proxy settings, which can cause TLS errors. Line 73 capturesclient_kwargsbut the test doesn't verify this critical parameter.Adding an assertion would prevent accidental regression of this proxy-isolation behavior:
assert captured['client_kwargs'].get('trust_env') is False🤖 Prompt for 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. In `@tests/unit/interfaces/test_openai_models_base.py` around lines 56 - 85, In the test_list_models_sends_extra_headers test, assert that the HTTP client was created with proxy isolation by checking captured['client_kwargs'] for trust_env=False; update the test (which uses FakeClient.__init__ to populate captured['client_kwargs']) to include an assertion like assert captured['client_kwargs'].get('trust_env') is False so the test ensures list_models continues to pass trust_env=False to the HTTP client.tests/unit/infrastructure/ai/test_provider_factory.py (1)
16-21: 💤 Low valueConsider testing cache key inequality without checking substring presence.
Line 21 asserts that
"UA"appears in the cache key string, which couples the test to the JSON serialization format. If the encoding changes (e.g., escaping, minification), this assertion could break even though the cache key behavior remains correct.The inequality assertion on line 20 already verifies the core requirement. The substring check is optional and adds brittleness.
🤖 Prompt for 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. In `@tests/unit/infrastructure/ai/test_provider_factory.py` around lines 16 - 21, The test test_provider_cache_key_changes_with_extra_headers currently asserts the cache key string contains "UA", coupling it to serialization format; remove the brittle substring assertion and rely only on the inequality check using _make_cache_key(base) != _make_cache_key(with_ua) (keep use of helper _profile and function _make_cache_key) so the test verifies behavior without depending on JSON formatting.
🤖 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 @.github/workflows/backend-ci.yml:
- Around line 25-34: The CI workflow step "Run targeted backend checks"
currently only runs py_compile and two specific test files; update the
.github/workflows/backend-ci.yml job named "Run targeted backend checks" to
execute the entire unit test suite (run pytest tests/unit -q --tb=short) or, if
you intentionally exclude files, add a clear comment and update the PR template
to document which tests are excluded and why; ensure the pytest invocation
replaces the current targeted file list so the CI command matches the PR
template requirement.
---
Nitpick comments:
In `@tests/unit/infrastructure/ai/test_provider_factory.py`:
- Around line 16-21: The test test_provider_cache_key_changes_with_extra_headers
currently asserts the cache key string contains "UA", coupling it to
serialization format; remove the brittle substring assertion and rely only on
the inequality check using _make_cache_key(base) != _make_cache_key(with_ua)
(keep use of helper _profile and function _make_cache_key) so the test verifies
behavior without depending on JSON formatting.
In `@tests/unit/interfaces/test_openai_models_base.py`:
- Around line 56-85: In the test_list_models_sends_extra_headers test, assert
that the HTTP client was created with proxy isolation by checking
captured['client_kwargs'] for trust_env=False; update the test (which uses
FakeClient.__init__ to populate captured['client_kwargs']) to include an
assertion like assert captured['client_kwargs'].get('trust_env') is False so the
test ensures list_models continues to pass trust_env=False to the HTTP client.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
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: 385dc395-84a4-425d-8247-ac81132f2fc5
📒 Files selected for processing (7)
.github/workflows/backend-ci.ymlfrontend/src/api/llmControl.tsfrontend/src/components/workbench/LLMControlPanel.vueinfrastructure/ai/provider_factory.pyinterfaces/api/v1/workbench/llm_control.pytests/unit/infrastructure/ai/test_provider_factory.pytests/unit/interfaces/test_openai_models_base.py
🚧 Files skipped from review as they are similar to previous changes (4)
- infrastructure/ai/provider_factory.py
- frontend/src/api/llmControl.ts
- interfaces/api/v1/workbench/llm_control.py
- frontend/src/components/workbench/LLMControlPanel.vue
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The agent generated fixes only for
Lines 28–34 interfaces/api/v1/workbench/llm_control.py \
infrastructure/ai/provider_factory.py \
application/ai/llm_control_service.py
- pytest \
- tests/unit/interfaces/test_openai_models_base.py \
- tests/unit/infrastructure/ai/test_provider_factory.py \
- -q --tb=short
+ pytest tests/unit -q --tb=short |
b844fa9 to
f0940d0
Compare
f0940d0 to
8866b31
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
.github/workflows/backend-ci.yml (1)
25-34:⚠️ Potential issue | 🟠 Major | ⚡ Quick winTest coverage regression: CI runs only 2 unit test files instead of full suite.
This change narrows backend CI from the full
tests/unitsuite to only 2 specific test files. Per the bot comment in PR objectives, the intended fix is to runpytest tests/unit -q --tb=shortto match the PR template requirement.🔧 Apply the bot's suggested fix
- name: Run targeted backend checks run: | python -m py_compile \ interfaces/api/v1/workbench/llm_control.py \ infrastructure/ai/provider_factory.py \ application/ai/llm_control_service.py - pytest \ - tests/unit/interfaces/test_openai_models_base.py \ - tests/unit/infrastructure/ai/test_provider_factory.py \ - -q --tb=short + pytest tests/unit -q --tb=short🤖 Prompt for 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. In @.github/workflows/backend-ci.yml around lines 25 - 34, The CI step labeled "Run targeted backend checks" was narrowed to two test files; update the pytest invocation in the backend-ci.yml job so it runs the whole unit test suite: replace the current pytest command that lists specific tests with a single call to "pytest tests/unit -q --tb=short" (leave the py_compile lines intact) so the workflow executes all unit tests rather than only tests/unit/interfaces/test_openai_models_base.py and tests/unit/infrastructure/ai/test_provider_factory.py.
🤖 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.
Duplicate comments:
In @.github/workflows/backend-ci.yml:
- Around line 25-34: The CI step labeled "Run targeted backend checks" was
narrowed to two test files; update the pytest invocation in the backend-ci.yml
job so it runs the whole unit test suite: replace the current pytest command
that lists specific tests with a single call to "pytest tests/unit -q
--tb=short" (leave the py_compile lines intact) so the workflow executes all
unit tests rather than only tests/unit/interfaces/test_openai_models_base.py and
tests/unit/infrastructure/ai/test_provider_factory.py.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 199c67ac-66fd-4fb6-8f3b-f543cb0b516d
📒 Files selected for processing (7)
.github/workflows/backend-ci.ymlfrontend/src/api/llmControl.tsfrontend/src/components/workbench/LLMControlPanel.vueinfrastructure/ai/provider_factory.pyinterfaces/api/v1/workbench/llm_control.pytests/unit/infrastructure/ai/test_provider_factory.pytests/unit/interfaces/test_openai_models_base.py
🚧 Files skipped from review as they are similar to previous changes (2)
- frontend/src/api/llmControl.ts
- frontend/src/components/workbench/LLMControlPanel.vue
There was a problem hiding this comment.
🧹 Nitpick comments (1)
interfaces/api/v1/workbench/llm_control.py (1)
99-111: 💤 Low valueAuth-header protection and empty-value trimming look correct.
One minor edge case:
protectedis derived only from the baseheaders, so two caller-supplied extras that differ only in case (e.g.X-Fooandx-foo) would both be retained as distinct dict keys and forwarded as duplicate headers. Not exploitable and httpx tolerates it, but you could canonicalize againstmergedkeys case-insensitively if you want last-write-wins dedup.🤖 Prompt for 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. In `@interfaces/api/v1/workbench/llm_control.py` around lines 99 - 111, The current _merge_extra_headers function only protects against base headers case-insensitively but can retain multiple extra headers that differ only by case (e.g. "X-Foo" and "x-foo"); update the merge loop so that after skipping keys in protected (derived from headers) you canonicalize against existing merged keys case-insensitively by removing any existing merged key whose lower() equals clean_key.lower() before assigning merged[clean_key] = clean_value, which makes last-write-wins for extras while still preventing overrides of protected auth headers.
🤖 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.
Nitpick comments:
In `@interfaces/api/v1/workbench/llm_control.py`:
- Around line 99-111: The current _merge_extra_headers function only protects
against base headers case-insensitively but can retain multiple extra headers
that differ only by case (e.g. "X-Foo" and "x-foo"); update the merge loop so
that after skipping keys in protected (derived from headers) you canonicalize
against existing merged keys case-insensitively by removing any existing merged
key whose lower() equals clean_key.lower() before assigning merged[clean_key] =
clean_value, which makes last-write-wins for extras while still preventing
overrides of protected auth headers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a67941f0-17d5-43fa-b093-107377e4ea17
📒 Files selected for processing (7)
.github/workflows/backend-ci.ymlfrontend/src/api/llmControl.tsfrontend/src/components/workbench/LLMControlPanel.vueinfrastructure/ai/provider_factory.pyinterfaces/api/v1/workbench/llm_control.pytests/unit/infrastructure/ai/test_provider_factory.pytests/unit/interfaces/test_openai_models_base.py
🚧 Files skipped from review as they are similar to previous changes (3)
- frontend/src/api/llmControl.ts
- .github/workflows/backend-ci.yml
- frontend/src/components/workbench/LLMControlPanel.vue
|
按提交者请求关闭此 PR。 |
变更类型
feat新功能fixBug 修复refactor重构(不影响功能)perf性能优化docs文档chore构建/工具链变更说明
在大模型配置档案中新增 User-Agent 输入框和随机生成按钮,并将 User-Agent 保存到
extra_headers.User-Agent。拉取模型、测试连接和正式生成会携带配置中的额外请求头;同时将extra_headers、extra_query、extra_body纳入 Provider 缓存键,避免修改 User-Agent 后继续复用旧客户端。本次也修复了输入或随机生成 User-Agent 时可能覆盖高级请求头编辑框未保存内容的问题,并补充模型列表请求头合并、认证头保护、运行时缓存键变化的后端单元测试。
架构影响
infrastructure/interfaces/frontend/scriptsPOST /llm-control/models请求体新增可选字段extra_headers: Dict[str, str]extra_headers作为持久化和请求透传载体,并保护认证请求头不被用户自定义头覆盖测试
python -m uvicorn ...)npm run dev)风险说明
extra_headers保存和透传;自定义请求头不会覆盖认证头,避免破坏 API Key 鉴权Summary by CodeRabbit
New Features
Tests
Chores