refactor: 精简环境配置,移除废弃配置项
.env: - 移除 HOST/PORT/DEBUG(代码未读取,由 uvicorn 命令行控制) - 移除 WEWORK_BOT_SEARCH_LIMIT(已被 SEARCH_LIMIT 取代) - 补充硅基流动配置注释 .env.example: - 同步移除 HOST/PORT/DEBUG/WEWORK_BOT_SEARCH_LIMIT - 补充 OpenAI 兼容硅基流动的说明 - 更新机器人注释(集成模式自动启动) config.py: - 移除 HOST/PORT/DEBUG 字段定义 - 移除 WEWORK_BOT_SEARCH_LIMIT 字段定义 wework_bot.py: - 改为从 settings 统一读取配置(不再 os.getenv) - _get_search_limit fallback 改为 settings.SEARCH_LIMIT - 更新模块文档注释
This commit is contained in:
13
.env.example
13
.env.example
@@ -11,11 +11,12 @@ POSTGRES_PASSWORD=postgres
|
|||||||
|
|
||||||
# ── 嵌入模型配置 ──
|
# ── 嵌入模型配置 ──
|
||||||
# 可选值: openai / zhipu / local_bge / dashscope / minimax
|
# 可选值: openai / zhipu / local_bge / dashscope / minimax
|
||||||
|
# openai 模式也兼容硅基流动等第三方 OpenAI 兼容接口
|
||||||
EMBEDDING_PROVIDER=minimax
|
EMBEDDING_PROVIDER=minimax
|
||||||
EMBEDDING_MODEL=MiniMax-Text-Embedding
|
EMBEDDING_MODEL=MiniMax-Text-Embedding
|
||||||
EMBEDDING_DIMENSIONS=1024
|
EMBEDDING_DIMENSIONS=1024
|
||||||
|
|
||||||
# ── OpenAI 配置 ──
|
# ── OpenAI 配置(也兼容硅基流动等第三方接口) ──
|
||||||
OPENAI_API_KEY=sk-your-openai-api-key
|
OPENAI_API_KEY=sk-your-openai-api-key
|
||||||
OPENAI_BASE_URL=https://api.openai.com/v1
|
OPENAI_BASE_URL=https://api.openai.com/v1
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ DEEPSEEK_API_KEY=your-deepseek-api-key
|
|||||||
DEEPSEEK_BASE_URL=https://api.deepseek.com
|
DEEPSEEK_BASE_URL=https://api.deepseek.com
|
||||||
DEEPSEEK_OCR_MODEL=deepseek-chat
|
DEEPSEEK_OCR_MODEL=deepseek-chat
|
||||||
|
|
||||||
# ── LLM 配置(用于查询扩展、实体检测) ──
|
# ── LLM 配置(用于查询扩展、实体检测等) ──
|
||||||
# 可选值: minimax / deepseek / openai
|
# 可选值: minimax / deepseek / openai
|
||||||
LLM_PROVIDER=minimax
|
LLM_PROVIDER=minimax
|
||||||
|
|
||||||
@@ -63,11 +64,6 @@ DATA_DIR=/app/data
|
|||||||
CHUNK_SIZE=300
|
CHUNK_SIZE=300
|
||||||
CHUNK_OVERLAP=50
|
CHUNK_OVERLAP=50
|
||||||
|
|
||||||
# ── 服务配置 ──
|
|
||||||
HOST=0.0.0.0
|
|
||||||
PORT=8000
|
|
||||||
DEBUG=false
|
|
||||||
|
|
||||||
# ── CORS 配置(多个来源用逗号分隔) ──
|
# ── CORS 配置(多个来源用逗号分隔) ──
|
||||||
CORS_ORIGINS=["*"]
|
CORS_ORIGINS=["*"]
|
||||||
|
|
||||||
@@ -76,9 +72,8 @@ APP_PORT=8000
|
|||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
|
|
||||||
# ── 企业微信智能机器人(WebSocket 长连接) ──
|
# ── 企业微信智能机器人(WebSocket 长连接) ──
|
||||||
# 作为独立进程运行:python -m app.wework_bot
|
# 后端启动时会自动检测配置并拉起机器人(后台线程)
|
||||||
WEWORK_BOT_ENABLED=false
|
WEWORK_BOT_ENABLED=false
|
||||||
WEWORK_BOT_ID=your-bot-id
|
WEWORK_BOT_ID=your-bot-id
|
||||||
WEWORK_BOT_SECRET=your-bot-secret
|
WEWORK_BOT_SECRET=your-bot-secret
|
||||||
WEWORK_BOT_SEARCH_LIMIT=3
|
|
||||||
EDUBRAIN_BASE_URL=http://localhost:8765
|
EDUBRAIN_BASE_URL=http://localhost:8765
|
||||||
|
|||||||
@@ -153,11 +153,6 @@ class Settings(BaseSettings):
|
|||||||
SEARCH_LIMIT: int = Field(default=3, description="图片搜索默认返回数量(1-10)")
|
SEARCH_LIMIT: int = Field(default=3, description="图片搜索默认返回数量(1-10)")
|
||||||
JUDGE_BATCH_SIZE: int = Field(default=10, description="每次LLM判断的文章数量(1-50)")
|
JUDGE_BATCH_SIZE: int = Field(default=10, description="每次LLM判断的文章数量(1-50)")
|
||||||
|
|
||||||
# ──────────────────────────── 服务端口 ────────────────────────────
|
|
||||||
HOST: str = Field(default="0.0.0.0", description="服务监听地址")
|
|
||||||
PORT: int = Field(default=8000, description="服务监听端口")
|
|
||||||
DEBUG: bool = Field(default=False, description="调试模式")
|
|
||||||
|
|
||||||
# ──────────────────────────── CORS ────────────────────────────
|
# ──────────────────────────── CORS ────────────────────────────
|
||||||
CORS_ORIGINS: list[str] = Field(
|
CORS_ORIGINS: list[str] = Field(
|
||||||
default=["*"],
|
default=["*"],
|
||||||
@@ -177,12 +172,6 @@ class Settings(BaseSettings):
|
|||||||
default=None,
|
default=None,
|
||||||
description="企业微信智能机器人 Secret",
|
description="企业微信智能机器人 Secret",
|
||||||
)
|
)
|
||||||
WEWORK_BOT_SEARCH_LIMIT: int = Field(
|
|
||||||
default=3,
|
|
||||||
ge=1,
|
|
||||||
le=10,
|
|
||||||
description="企业微信机器人搜索返回图片数量上限",
|
|
||||||
)
|
|
||||||
EDUBRAIN_BASE_URL: str = Field(
|
EDUBRAIN_BASE_URL: str = Field(
|
||||||
default="http://localhost:8765",
|
default="http://localhost:8765",
|
||||||
description="EduBrain 后端服务地址,企业微信机器人通过此地址调用后端 API(搜索/OCR识别等)。当机器人与后端部署在同一台机器时使用默认值 http://localhost:8765;若机器人独立部署到其他服务器,需改为后端的实际访问地址(如 http://192.168.1.100:8765)",
|
description="EduBrain 后端服务地址,企业微信机器人通过此地址调用后端 API(搜索/OCR识别等)。当机器人与后端部署在同一台机器时使用默认值 http://localhost:8765;若机器人独立部署到其他服务器,需改为后端的实际访问地址(如 http://192.168.1.100:8765)",
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
使用官方 SDK (wecom-aibot-python-sdk) 的 WSClient 类,
|
使用官方 SDK (wecom-aibot-python-sdk) 的 WSClient 类,
|
||||||
封装了连接管理、心跳、断线重连等能力。
|
封装了连接管理、心跳、断线重连等能力。
|
||||||
|
|
||||||
作为独立进程运行:python -m app.wework_bot
|
支持两种运行方式:
|
||||||
|
1. 集成模式:后端启动时自动拉起(BotManager)
|
||||||
|
2. 独立进程:python -m app.wework_bot
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -28,6 +30,8 @@ from dotenv import load_dotenv
|
|||||||
# 加载 .env 文件(独立运行时需要)
|
# 加载 .env 文件(独立运行时需要)
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
from app.config import settings
|
||||||
|
|
||||||
logger = logging.getLogger("wework_bot")
|
logger = logging.getLogger("wework_bot")
|
||||||
|
|
||||||
# 分片上传参数(参考官方文档)
|
# 分片上传参数(参考官方文档)
|
||||||
@@ -38,13 +42,10 @@ class WeComBotService:
|
|||||||
"""企业微信智能机器人服务(WebSocket 长连接模式)"""
|
"""企业微信智能机器人服务(WebSocket 长连接模式)"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bot_id = os.getenv("WEWORK_BOT_ID", "")
|
self.bot_id = settings.WEWORK_BOT_ID or ""
|
||||||
self.bot_secret = os.getenv("WEWORK_BOT_SECRET", "")
|
self.bot_secret = settings.WEWORK_BOT_SECRET or ""
|
||||||
self.edubrain_base_url = os.getenv(
|
self.edubrain_base_url = settings.EDUBRAIN_BASE_URL
|
||||||
"EDUBRAIN_BASE_URL", "http://localhost:8765"
|
self.enabled = settings.WEWORK_BOT_ENABLED
|
||||||
)
|
|
||||||
self.search_limit = int(os.getenv("WEWORK_BOT_SEARCH_LIMIT", "3"))
|
|
||||||
self.enabled = os.getenv("WEWORK_BOT_ENABLED", "false").lower() == "true"
|
|
||||||
self.ws_client: WSClient | None = None
|
self.ws_client: WSClient | None = None
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
@@ -430,10 +431,12 @@ class WeComBotService:
|
|||||||
resp = await client.get(f"{self.edubrain_base_url}/api/v1/settings")
|
resp = await client.get(f"{self.edubrain_base_url}/api/v1/settings")
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
return data.get("search_limit", self.search_limit)
|
limit = data.get("search_limit")
|
||||||
|
if limit:
|
||||||
|
return limit
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("获取 search_limit 失败,使用默认值: %s", e)
|
logger.warning("获取 search_limit 失败,使用默认值: %s", e)
|
||||||
return self.search_limit
|
return settings.SEARCH_LIMIT
|
||||||
|
|
||||||
async def _search_images(self, keyword: str) -> list:
|
async def _search_images(self, keyword: str) -> list:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user