feat(06-02): move pipeline core files to kb_workflow.pipeline
- Move pipeline.py, schemas.py, config.py, state.py, errors.py - Move retry.py, idempotency.py, link_parser.py - Create pipeline/__init__.py with updated imports - Update all internal imports to use kb_workflow.pipeline prefix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""Configuration management for KB Pipeline
|
||||
|
||||
Provides centralized configuration using pydantic-settings.
|
||||
Configuration is loaded from ~/.kb_env file and environment variables.
|
||||
"""
|
||||
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import Field, SecretStr
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class KBSettings(BaseSettings):
|
||||
"""KB 工作流配置
|
||||
|
||||
使用 pydantic-settings 从环境变量和 ~/.kb_env 文件加载配置。
|
||||
|
||||
Attributes:
|
||||
base_path: 知识库根目录(必需)
|
||||
archive_path: 归档目录(必需)
|
||||
git_root: Git 仓库根目录(可选)
|
||||
git_user: Git 用户名(可选)
|
||||
git_email: Git 邮箱(可选)
|
||||
hf_token: HuggingFace Token(敏感信息)
|
||||
zhihu_cookie: 知乎 Cookie(敏感信息)
|
||||
"""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=str(Path.home() / ".kb_env"),
|
||||
env_file_encoding="utf-8",
|
||||
env_prefix="KB_",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
# 必需配置
|
||||
base_path: str = Field(..., description="知识库根目录")
|
||||
archive_path: str = Field(..., description="归档目录")
|
||||
intermediate_path: str = Field(
|
||||
default_factory=lambda: str(Path.home() / "work" / "intermediate" / "analysis"),
|
||||
description="中间文件存储目录"
|
||||
)
|
||||
|
||||
# 可选配置
|
||||
git_root: str = Field(default="", description="Git 仓库根目录")
|
||||
git_user: str = Field(default="", description="Git 用户名")
|
||||
git_email: str = Field(default="", description="Git 邮箱")
|
||||
|
||||
# 敏感信息(从环境变量读取)
|
||||
hf_token: SecretStr = Field(
|
||||
default=SecretStr(""), description="HuggingFace Token"
|
||||
)
|
||||
zhihu_cookie: SecretStr = Field(
|
||||
default=SecretStr(""), description="知乎 Cookie"
|
||||
)
|
||||
bilibili_cookie: SecretStr = Field(
|
||||
default=SecretStr(""), description="B站 Cookie (for video download)"
|
||||
)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> KBSettings:
|
||||
"""获取配置单例
|
||||
|
||||
使用 lru_cache 确保配置只加载一次。
|
||||
如需重新加载配置,调用 get_settings.cache_clear()。
|
||||
|
||||
Returns:
|
||||
KBSettings 实例
|
||||
"""
|
||||
return KBSettings()
|
||||
Reference in New Issue
Block a user