diff --git a/kb_workflow/__init__.py b/kb_workflow/__init__.py index cd9271a..5c815d5 100644 --- a/kb_workflow/__init__.py +++ b/kb_workflow/__init__.py @@ -3,6 +3,6 @@ 知识库工作流管道入口。 """ -from .kb_workflow import process_command, main +from .cli import process_command, main __all__ = ["process_command", "main"] diff --git a/kb_workflow/__main__.py b/kb_workflow/__main__.py new file mode 100644 index 0000000..4ef118c --- /dev/null +++ b/kb_workflow/__main__.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +KB Workflow 包入口点 + +支持通过 python -m kb_workflow 直接运行 CLI。 +""" + +from .cli import main + +if __name__ == '__main__': + main() diff --git a/kb_workflow/kb_workflow.py b/kb_workflow/cli.py similarity index 86% rename from kb_workflow/kb_workflow.py rename to kb_workflow/cli.py index c89108c..ca2fe0f 100644 --- a/kb_workflow/kb_workflow.py +++ b/kb_workflow/cli.py @@ -9,11 +9,15 @@ KB Workflow - Knowledge Base Workflow Orchestrator 内部使用 kb_workflow.pipeline 包实现完整的内容处理流程。 使用方式: - python kb_workflow.py process "https://www.bilibili.com/video/BVxxx" - python kb_workflow.py process "https://..." -o /path/to/output - python kb_workflow.py login # QR code login - python kb_workflow.py login --import-cookie cookies.json - python kb_workflow.py login --status + python -m kb_workflow process "https://www.bilibili.com/video/BVxxx" + python -m kb_workflow process "https://..." -o /path/to/output + python -m kb_workflow login # QR code login + python -m kb_workflow login --import-cookie cookies.json + python -m kb_workflow login --status + +或者通过包接口调用: + from kb_workflow import process_command + result = process_command("https://...") """ import argparse @@ -41,13 +45,13 @@ def process_command( Dictionary with success status, content_dir, and results """ try: - from kb_workflow.pipeline.config import get_settings - from kb_workflow.pipeline.pipeline import Pipeline - from kb_workflow.pipeline.processors import ( + from .pipeline.config import get_settings + from .pipeline.pipeline import Pipeline + from .pipeline.processors import ( ASRProcessor, AnalyzeProcessor, ArchiveProcessor, DownloadProcessor, ParseProcessor ) - from kb_workflow.pipeline.schemas import PipelineConfig + from .pipeline.schemas import PipelineConfig async def run_pipeline(): # Determine output directory - default to intermediate_path @@ -119,9 +123,9 @@ def login_command( Dictionary with login result """ try: - from kb_workflow.auth import ZhihuLogin - from kb_workflow.auth.cookie_manager import CookieManager, parse_json_cookies - from kb_workflow.pipeline.config import get_settings + from .auth import ZhihuLogin + from .auth.cookie_manager import CookieManager, parse_json_cookies + from .pipeline.config import get_settings settings = get_settings() manager = CookieManager() @@ -175,22 +179,22 @@ def main(): epilog=''' 使用示例: # 处理URL (通过完整管道) - python kb_workflow.py process "https://www.bilibili.com/video/BVxxx" + python -m kb_workflow process "https://www.bilibili.com/video/BVxxx" # 指定输出目录 - python kb_workflow.py process "https://..." -o /path/to/output + python -m kb_workflow process "https://..." -o /path/to/output # 强制重新执行(忽略已完成状态) - python kb_workflow.py process "https://..." --no-skip + python -m kb_workflow process "https://..." --no-skip # 知乎登录 (二维码扫码) - python kb_workflow.py login + python -m kb_workflow login # 导入 Cookie - python kb_workflow.py login --import-cookie cookies.json + python -m kb_workflow login --import-cookie cookies.json # 检查 Cookie 状态 - python kb_workflow.py login --status + python -m kb_workflow login --status ''' )