feat: support configurable HTTP User-Agent for LLM API Requests - #285
Open
Xlucidator wants to merge 3 commits into
Open
feat: support configurable HTTP User-Agent for LLM API Requests#285Xlucidator wants to merge 3 commits into
Xlucidator wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an optional llm.api.user_agent configuration to allow overriding the HTTP User-Agent header used by the OpenAI-compatible client, improving compatibility with third-party gateways that block the OpenAI SDK default header. The PR also updates docs to reflect current configuration and workflow behavior.
Changes:
- Pass an optional
llm.api.user_agentvalue into the OpenAI client viadefault_headerswhen configured. - Add a unit test to verify the
default_headersargument is (or is not) passed based on config. - Update
README.mdandconfig/base.yamlto document the new setting and refresh usage/testing guidance.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/zotero_arxiv_daily/executor.py |
Constructs OpenAI client kwargs conditionally adding default_headers for User-Agent. |
tests/test_executor.py |
Verifies optional User-Agent propagation to the OpenAI client constructor via monkeypatch capture. |
config/base.yaml |
Documents the new llm.api.user_agent config key and default (null). |
README.md |
Documents llm.api.user_agent and refreshes configuration + local run/testing instructions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
动机
接入第三方 LLM API 网站时,GitHub Actions 中所有 TL;DR 和作者机构请求均失败,报错为
Failed to generate tldr/affiliations of xxx: Your request was blocked.在本地进行对照测试后发现,在其他条件完全一致的情况下:
仅修改 User-Agent 即可解决问题,说明 有些第三方API中转站服务可能会根据安全策略,按请求头过滤请求 。所以个人希望项目能 增加自定义 User-Agent 配置 ,以适配更多的 LLM 服务。
修改内容
test/test_executor.py中增加默认、自定义和禁用 User-Agent 三种情况的测试。相关修改内容通过了个人测试:
使用方式
设置为 null 时继续使用 OpenAI Python SDK 的默认 User-Agent。