Skip to content

chore: 简化社区版本地部署的环境变量配置 - #24

Draft
Yinling-Faye wants to merge 1 commit into
MingfengHong:mainfrom
Yinling-Faye:chore/simplify-env-example
Draft

chore: 简化社区版本地部署的环境变量配置#24
Yinling-Faye wants to merge 1 commit into
MingfengHong:mainfrom
Yinling-Faye:chore/simplify-env-example

Conversation

@Yinling-Faye

@Yinling-Faye Yinling-Faye commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

修复 #23

变更内容

社区版本地部署时需要填写的环境变量过多,本 PR 将不常改动的参数从 .env.example 中移除,改为依赖代码中的默认值,从而简化部署流程。

主要改动

  • .env.example:精简为仅保留最常用的配置项:

    • LLM 服务商相关(LLM_PROVIDERLLM_API_TYPELLM_MODELLLM_BASE_URLLLM_API_KEY
    • 数据源 API Key(OPENALEX_API_KEYOPENALEX_EMAILCROSSREF_EMAILWOS_API_KEY
    • 检索默认值(SEARCH_FIELDDISCIPLINE_FIELDS
    • 其余参数(如 DATA_SOURCETARGET_MIN/TARGET_MAXMAX_ITERATIONSEXPAND_CITATIONSRANKING_BATCH_SIZELLM_TIMEOUT_SECONDSPAPERSEEK_HISTORY_ENABLED 等)均已在代码中提供合理默认值,需要时再覆盖即可。
  • docker-compose.yml:改用 env_file: .env 加载环境变量,仅显式保留容器端口相关配置,避免重复维护大量默认值。

  • README.md:更新「环境变量」章节,区分常用变量与高级变量,并说明默认值位置。

  • docs/deployment.md:同步 Docker 环境变量说明。

  • tests/test_deployment.py:更新 compose 测试断言,验证 env_file: .env 的使用。

验证

本地运行测试套件:

python3 -m unittest discover -s tests -v

结果:82 个测试通过(1 个跳过,因未安装 mcp 包)。

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request simplifies configuration management by streamlining .env.example to only include the most common settings, while relying on code-defined defaults for advanced parameters. The docker-compose.yml has been updated to load environment variables directly from .env instead of mapping them individually, and documentation and tests have been updated accordingly. Feedback on these changes suggests keeping LLM_API_KEY empty in .env.example to avoid false-positive key detection in the UI, making the .env file optional in docker-compose.yml to prevent startup failures when the file is missing, and updating the deployment tests to accommodate this optional configuration.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread .env.example Outdated
LLM_API_TYPE=openai_chat
LLM_MODEL=deepseek-v4-flash
LLM_BASE_URL=https://api.deepseek.com
LLM_API_KEY=your-llm-api-key

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.

medium

.env.example 中,默认启用的 LLM_API_KEY 被设置为了占位符 your-llm-api-key。如果用户直接复制该文件为 .env 且未修改此项,系统会认为已配置有效的 API Key(例如 has_llm_api_key 判定为 True),从而在 Web UI 中隐藏输入框,但在实际发起请求时会因使用无效的占位符而报错。\n\n建议将默认的 LLM_API_KEY 保持为空,以便系统能够正确检测到缺失的 Key 并提示用户输入。

LLM_API_KEY=

Comment thread docker-compose.yml Outdated
ports:
- "${PAPERSEEK_PORT:-8765}:${PAPERSEEK_CONTAINER_PORT:-7860}"
restart: unless-stopped
env_file: .env

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.

medium

直接使用 env_file: .env 会导致在本地不存在 .env 文件时,docker compose up 启动失败并报错。为了提高容错性,允许用户在不创建 .env 的情况下(例如完全通过系统环境变量或在 Web UI 中临时填写 Key)直接启动容器,建议将 .env 设置为可选(required: false)。

    env_file:\n      - path: .env\n        required: false

Comment thread tests/test_deployment.py Outdated
self.assertIn("PORT: ${PAPERSEEK_CONTAINER_PORT:-7860}", compose)
self.assertIn("LLM_PROVIDER", compose)
self.assertIn("OPENALEX_API_KEY", compose)
self.assertIn("env_file: .env", compose)

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.

medium

如果将 docker-compose.yml 中的 env_file 改为更具容错性的可选格式(例如使用 required: false),此处的断言 self.assertIn("env_file: .env", compose) 将会失败。建议将其放宽为仅验证包含 .env 文件名。

Suggested change
self.assertIn("env_file: .env", compose)
self.assertIn(".env", compose)

@Yinling-Faye
Yinling-Faye force-pushed the chore/simplify-env-example branch from a9af808 to b9fdaa3 Compare June 27, 2026 07:42
@Yinling-Faye

Copy link
Copy Markdown
Collaborator Author

@gemini-code-assist 感谢 review,已按建议调整:

  1. .env.example 中的 LLM_API_KEY 保持为空,避免 Web UI 误判为已配置密钥。
  2. docker-compose.yml 中的 env_file 改为可选加载(required: false),避免缺少 .env 文件时启动失败。
  3. tests/test_deployment.py 同步更新断言,验证可选 env_file 配置。

本地测试已通过,请再次 review。

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request simplifies configuration by removing advanced and optional environment variables from .env.example and docker-compose.yml, relying instead on reasonable defaults defined in the code. The documentation and deployment tests have been updated accordingly. The reviewer noted that completely removing environment variables from docker-compose.yml prevents host shell environment variables from being passed to the container, and suggested declaring them without default values to allow pass-through.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread docker-compose.yml
Comment on lines 14 to 15
environment:
PORT: ${PAPERSEEK_CONTAINER_PORT:-7860}

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.

high

docker-compose.yml 中,完全移除这些环境变量声明会导致宿主机的 Shell 环境变量(例如通过 export LLM_API_KEY=... 设置的变量)无法传递给容器。\n\n根据 README 中的说明:'已经存在的系统环境变量优先于 .env'。为了保持这一行为,并在不引入默认值冗余的前提下允许 Shell 变量透传,建议在 environment 中以无默认值的方式声明这些关键变量。这样 Docker Compose 会自动从宿主机环境透传同名变量,且其优先级高于 env_file

    environment:\n      PORT: ${PAPERSEEK_CONTAINER_PORT:-7860}\n      LLM_PROVIDER:\n      LLM_API_TYPE:\n      LLM_MODEL:\n      LLM_BASE_URL:\n      LLM_API_KEY:\n      OPENALEX_API_KEY:\n      OPENALEX_EMAIL:\n      CROSSREF_EMAIL:\n      WOS_API_KEY:\n      SEARCH_FIELD:\n      DISCIPLINE_FIELDS:

@Yinling-Faye
Yinling-Faye force-pushed the chore/simplify-env-example branch from b9fdaa3 to 1bb282c Compare June 27, 2026 07:46
@Yinling-Faye

Copy link
Copy Markdown
Collaborator Author

@gemini-code-assist 已按 review 调整:

docker-compose.ymlenvironment 中以 ${VAR} 形式声明了 .env.example 中的关键变量(LLM_PROVIDERLLM_API_KEYOPENALEX_API_KEYDISCIPLINE_FIELDS 等),保证:

  1. 宿主机 Shell 环境变量可以透传给容器,且优先级高于 .env
  2. 仅使用 .env 文件的用户也能正常工作,因为 Docker Compose 会用 .env 中的值完成 compose 文件插值。
  3. 若两者均未设置,容器得到空字符串,PaperSeek 代码会回退到内置默认值。

同时保留可选的 env_file: .env required: false,用于透传 .env.example 未列出的其他变量。

测试已更新并全部通过。

@gemini-code-assist

Copy link
Copy Markdown
Contributor

感谢你的详细说明和测试更新。目前的配置方案在 docker-compose.yml 中显式声明环境变量,结合 env_filerequired: false 设置,既保证了宿主机环境变量的优先级,又兼顾了 .env 文件的易用性,这是一个非常稳健的改进。测试用例的同步更新也确保了配置逻辑的正确性。此 PR 已准备就绪。

@MingfengHong MingfengHong left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

英文文档 README.en.md 没同步。

@MingfengHong
MingfengHong marked this pull request as draft July 8, 2026 13:09
@MingfengHong MingfengHong added the wontfix This will not be worked on label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants