Skip to content

feat: support configurable HTTP User-Agent for LLM API Requests - #285

Open
Xlucidator wants to merge 3 commits into
TideDra:mainfrom
Xlucidator:configurable-llmservice-user-agent
Open

feat: support configurable HTTP User-Agent for LLM API Requests#285
Xlucidator wants to merge 3 commits into
TideDra:mainfrom
Xlucidator:configurable-llmservice-user-agent

Conversation

@Xlucidator

Copy link
Copy Markdown

This PR adds an optional llm.api.user_agent setting for compatibility with third-party LLM API services that filter requests by User-Agent, while preserving the OpenAI Python SDK default when unset. It also updates the README to reflect the current configuration and project behavior. The changes have been verified locally and with the complete GitHub Actions workflow.

动机

接入第三方 LLM API 网站时,GitHub Actions 中所有 TL;DR 和作者机构请求均失败,报错为 Failed to generate tldr/affiliations of xxx: Your request was blocked.

在本地进行对照测试后发现,在其他条件完全一致的情况下:

  • 使用 OpenAI Python SDK 默认 User-Agent(OpenAI/Python 2.29.0):返回 HTTP 403
  • 显式设置其他 User-Agent:返回 HTTP 200

仅修改 User-Agent 即可解决问题,说明 有些第三方API中转站服务可能会根据安全策略,按请求头过滤请求 。所以个人希望项目能 增加自定义 User-Agent 配置 ,以适配更多的 LLM 服务。

修改内容

  1. 新增可选配置项 llm.api.user_agent:配置非空时,将其传递给 OpenAI 客户端。
    • 默认值保持为 null,不改变现有用户的 SDK 默认行为。
    • test/test_executor.py 中增加默认、自定义和禁用 User-Agent 三种情况的测试。
  2. 更新 README,同步当前修改
    • 顺便修复了原本过时的内容,与当前项目代码实现对齐:配置、debug 数量、本地运行命令、测试方式和论文获取流程

相关修改内容通过了个人测试:

  • 本地 test 测试:86 passed,1 deselected。
  • 使用真实第三方 LLM API 完成本地验证。
  • 该分支上完整的 GitHub Actions 工作流测试。

使用方式

llm:
  api:
    key: ${oc.env:OPENAI_API_KEY}
    base_url: ${oc.env:OPENAI_API_BASE}
    user_agent: zotero-arxiv-daily/1.0

设置为 null 时继续使用 OpenAI Python SDK 的默认 User-Agent。

Copilot AI lite review requested due to automatic review settings August 11, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_agent value into the OpenAI client via default_headers when configured.
  • Add a unit test to verify the default_headers argument is (or is not) passed based on config.
  • Update README.md and config/base.yaml to 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.

Comment thread src/zotero_arxiv_daily/executor.py Outdated
Comment thread README.md Outdated
Comment thread tests/test_executor.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants