From 2380dd4617685640f596cbfd83e88a581cffd9c9 Mon Sep 17 00:00:00 2001 From: aszerW Date: Fri, 17 Apr 2026 23:35:37 +0800 Subject: [PATCH] feat: add python-dotenv support for local .env files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 python-dotenv 依赖 - 在 config.py 中加载 .env 文件 - 添加 .env.example 示例文件 --- .env.example | 6 ++++++ config.py | 3 +++ requirements.txt | 1 + 3 files changed, 10 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d8b0faa --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# OpenAI API Key +OPENAI_API_KEY=sk-your-api-key-here + +# 可选:自定义路由阈值 +# ROUTE_SIMPLE_THRESHOLD=100 +# ROUTE_MEDIUM_THRESHOLD=500 diff --git a/config.py b/config.py index 3275d4e..e79abff 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,10 @@ """ import os from typing import Literal +from dotenv import load_dotenv +# 加载 .env 文件 +load_dotenv() # 模型配置 MODEL_CONFIG = { diff --git a/requirements.txt b/requirements.txt index c9d22f4..ccbd1d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,6 @@ pydantic>=2.5.0 openai>=1.6.0 tiktoken>=0.5.0 httpx>=0.25.0 +python-dotenv>=1.0.0 pytest>=7.4.0 pytest-asyncio>=0.21.0