diff --git a/.env b/.env deleted file mode 100644 index 1ecd2f9..0000000 --- a/.env +++ /dev/null @@ -1,30 +0,0 @@ -# File Brain 配置文件 - -# ============================================ -# 向量模型配置 -# ============================================ -# 可选值: -# - "tfidf" : 使用 TF-IDF (完全离线,基于关键词) -# - "sentence-transformers" : 使用 AI 嵌入模型 (首次需联网下载) -EMBEDDING_MODEL=tfidf - -# ============================================ -# AI 配置(默认:无 AI,完全离线) -# ============================================ -# AI_PROVIDER 可选值: -# - "none" : 无 AI(完全离线,默认) -# - "ollama" : 使用 Ollama 本地模型(需安装 Ollama) -# - "lmstudio" : 使用 LM Studio(需启动 LM Studio 服务器) -# - "local" : 使用本地 transformers 小模型(首次需联网下载) -# - "openai" : 使用 OpenAI API(需密钥,数据发送到 OpenAI) -AI_PROVIDER=none - -# Notion API (可选) -# NOTION_API_KEY=your_notion_api_key -# NOTION_DATABASE_ID=your_database_id - -# Obsidian 配置 (可选) -# OBSIDIAN_VAULT_PATH=C:\Users\YourName\Documents\Obsidian Vault - -# Google API (可选,用于 NotebookLM) -# GOOGLE_API_KEY=your_google_api_key diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6db559..b376eda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,23 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies + - name: Install test dependencies run: | python -m pip install --upgrade pip - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install \ + fastapi uvicorn python-multipart httpx \ + python-docx python-pptx openpyxl \ + PyPDF2 pdfplumber reportlab fpdf \ + beautifulsoup4 requests lxml markdown python-frontmatter \ + numpy scikit-learn networkx xmindparser notion-client \ + pydantic python-dotenv tqdm watchdog pytest - name: Run tests + env: + EMBEDDING_MODEL: tfidf + AI_PROVIDER: none run: | python -m pytest @@ -32,7 +41,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.12' - name: Install dependencies @@ -42,6 +51,6 @@ jobs: - name: Lint with flake8 run: | # 停止构建,如果有语法错误或未定义的名称 - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --exclude=.git,.venv,.venv-ci-ubuntu,venv,data,logs,__pycache__ --count --select=E9,F63,F7,F82 --show-source --statistics # 更宽松的检查 - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics \ No newline at end of file + flake8 . --exclude=.git,.venv,.venv-ci-ubuntu,venv,data,logs,__pycache__ --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a1e83e --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Python caches/build artifacts +__pycache__/ +*.py[cod] +*$py.class +*.egg-info/ +.eggs/ +build/ +dist/ + +# Virtual environments +.venv/ +venv/ +env/ +ENV/ + +# Test/type/lint caches +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ +.coverage +coverage.xml +htmlcov/ + +# Runtime data and indexes +data/ +vector_db/ +uploads/ +logs/ +*.log + +# Local config/secrets +.env +*.env +*.key +*.pem +secrets/ + +# Local/editor/system files +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store +Thumbs.db +Desktop.ini diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc deleted file mode 100644 index f272bc0..0000000 Binary files a/__pycache__/config.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/file_brain.cpython-312.pyc b/__pycache__/file_brain.cpython-312.pyc deleted file mode 100644 index 65fb0da..0000000 Binary files a/__pycache__/file_brain.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/test_api.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_api.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 5c57296..0000000 Binary files a/__pycache__/test_api.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/__pycache__/test_basic.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_basic.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 1ae6ad7..0000000 Binary files a/__pycache__/test_basic.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/__pycache__/test_file_formats.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_file_formats.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 69142d6..0000000 Binary files a/__pycache__/test_file_formats.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/__pycache__/test_file_organizer.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_file_organizer.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index f614b37..0000000 Binary files a/__pycache__/test_file_organizer.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/__pycache__/test_knowledge_graph.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_knowledge_graph.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 47d5e57..0000000 Binary files a/__pycache__/test_knowledge_graph.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/__pycache__/test_monitor.cpython-312-pytest-9.0.2.pyc b/__pycache__/test_monitor.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 17b7d9d..0000000 Binary files a/__pycache__/test_monitor.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/ai/__pycache__/__init__.cpython-312.pyc b/ai/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 432dfb5..0000000 Binary files a/ai/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/ai/__pycache__/ai_provider.cpython-312.pyc b/ai/__pycache__/ai_provider.cpython-312.pyc deleted file mode 100644 index 811f290..0000000 Binary files a/ai/__pycache__/ai_provider.cpython-312.pyc and /dev/null differ diff --git a/ai/__pycache__/qa_engine.cpython-312.pyc b/ai/__pycache__/qa_engine.cpython-312.pyc deleted file mode 100644 index 2103cce..0000000 Binary files a/ai/__pycache__/qa_engine.cpython-312.pyc and /dev/null differ diff --git a/api/__pycache__/__init__.cpython-312.pyc b/api/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index af38df4..0000000 Binary files a/api/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/api/__pycache__/server.cpython-312.pyc b/api/__pycache__/server.cpython-312.pyc deleted file mode 100644 index e5b4893..0000000 Binary files a/api/__pycache__/server.cpython-312.pyc and /dev/null differ diff --git a/benchmarks/__pycache__/performance_test.cpython-312-pytest-9.0.2.pyc b/benchmarks/__pycache__/performance_test.cpython-312-pytest-9.0.2.pyc deleted file mode 100644 index 145e7a0..0000000 Binary files a/benchmarks/__pycache__/performance_test.cpython-312-pytest-9.0.2.pyc and /dev/null differ diff --git a/core/__pycache__/__init__.cpython-312.pyc b/core/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index c5f6456..0000000 Binary files a/core/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/content_indexer.cpython-312.pyc b/core/__pycache__/content_indexer.cpython-312.pyc deleted file mode 100644 index 935747a..0000000 Binary files a/core/__pycache__/content_indexer.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/file_reader.cpython-312.pyc b/core/__pycache__/file_reader.cpython-312.pyc deleted file mode 100644 index 9906144..0000000 Binary files a/core/__pycache__/file_reader.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/logger.cpython-312.pyc b/core/__pycache__/logger.cpython-312.pyc deleted file mode 100644 index 4c5e975..0000000 Binary files a/core/__pycache__/logger.cpython-312.pyc and /dev/null differ diff --git a/core/__pycache__/search_engine.cpython-312.pyc b/core/__pycache__/search_engine.cpython-312.pyc deleted file mode 100644 index 0a2d4d7..0000000 Binary files a/core/__pycache__/search_engine.cpython-312.pyc and /dev/null differ diff --git a/core/config/__pycache__/smart_monitor_config.cpython-312.pyc b/core/config/__pycache__/smart_monitor_config.cpython-312.pyc deleted file mode 100644 index 19f74cb..0000000 Binary files a/core/config/__pycache__/smart_monitor_config.cpython-312.pyc and /dev/null differ diff --git a/core/embedding/__pycache__/__init__.cpython-312.pyc b/core/embedding/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 93e22b8..0000000 Binary files a/core/embedding/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/core/embedding/__pycache__/base.cpython-312.pyc b/core/embedding/__pycache__/base.cpython-312.pyc deleted file mode 100644 index 03f9252..0000000 Binary files a/core/embedding/__pycache__/base.cpython-312.pyc and /dev/null differ diff --git a/core/embedding/__pycache__/sentence_transformers.cpython-312.pyc b/core/embedding/__pycache__/sentence_transformers.cpython-312.pyc deleted file mode 100644 index 01869ae..0000000 Binary files a/core/embedding/__pycache__/sentence_transformers.cpython-312.pyc and /dev/null differ diff --git a/core/embedding/__pycache__/tfidf.cpython-312.pyc b/core/embedding/__pycache__/tfidf.cpython-312.pyc deleted file mode 100644 index 0234a31..0000000 Binary files a/core/embedding/__pycache__/tfidf.cpython-312.pyc and /dev/null differ diff --git a/core/file_organizer/__pycache__/__init__.cpython-312.pyc b/core/file_organizer/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 5b56e67..0000000 Binary files a/core/file_organizer/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/core/file_organizer/__pycache__/file_namer.cpython-312.pyc b/core/file_organizer/__pycache__/file_namer.cpython-312.pyc deleted file mode 100644 index 3657c04..0000000 Binary files a/core/file_organizer/__pycache__/file_namer.cpython-312.pyc and /dev/null differ diff --git a/core/file_organizer/__pycache__/tag_extractor.cpython-312.pyc b/core/file_organizer/__pycache__/tag_extractor.cpython-312.pyc deleted file mode 100644 index 4a884ea..0000000 Binary files a/core/file_organizer/__pycache__/tag_extractor.cpython-312.pyc and /dev/null differ diff --git a/core/knowledge_graph/__pycache__/__init__.cpython-312.pyc b/core/knowledge_graph/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index d6884c4..0000000 Binary files a/core/knowledge_graph/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/core/knowledge_graph/__pycache__/graph_builder.cpython-312.pyc b/core/knowledge_graph/__pycache__/graph_builder.cpython-312.pyc deleted file mode 100644 index b230a87..0000000 Binary files a/core/knowledge_graph/__pycache__/graph_builder.cpython-312.pyc and /dev/null differ diff --git a/core/knowledge_graph/__pycache__/graph_storage.cpython-312.pyc b/core/knowledge_graph/__pycache__/graph_storage.cpython-312.pyc deleted file mode 100644 index ed16a2a..0000000 Binary files a/core/knowledge_graph/__pycache__/graph_storage.cpython-312.pyc and /dev/null differ diff --git a/core/knowledge_graph/__pycache__/graph_visualizer.cpython-312.pyc b/core/knowledge_graph/__pycache__/graph_visualizer.cpython-312.pyc deleted file mode 100644 index 2da9fb8..0000000 Binary files a/core/knowledge_graph/__pycache__/graph_visualizer.cpython-312.pyc and /dev/null differ diff --git a/core/models/__pycache__/__init__.cpython-312.pyc b/core/models/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 56f0147..0000000 Binary files a/core/models/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/core/models/__pycache__/file_content.cpython-312.pyc b/core/models/__pycache__/file_content.cpython-312.pyc deleted file mode 100644 index 6e57973..0000000 Binary files a/core/models/__pycache__/file_content.cpython-312.pyc and /dev/null differ diff --git a/core/smart_monitor/__pycache__/smart_monitor_manager.cpython-312.pyc b/core/smart_monitor/__pycache__/smart_monitor_manager.cpython-312.pyc deleted file mode 100644 index 318c48d..0000000 Binary files a/core/smart_monitor/__pycache__/smart_monitor_manager.cpython-312.pyc and /dev/null differ diff --git a/logs/file_brain_20260329.log b/logs/file_brain_20260329.log deleted file mode 100644 index e69de29..0000000 diff --git a/monitor/__pycache__/__init__.cpython-312.pyc b/monitor/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index e4fca60..0000000 Binary files a/monitor/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/monitor/__pycache__/file_monitor.cpython-312.pyc b/monitor/__pycache__/file_monitor.cpython-312.pyc deleted file mode 100644 index 5033bc7..0000000 Binary files a/monitor/__pycache__/file_monitor.cpython-312.pyc and /dev/null differ diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..30e42d0 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +python_files = test_*.py +addopts = -q +norecursedirs = benchmarks .git .venv venv data logs diff --git a/readers/__pycache__/__init__.cpython-312.pyc b/readers/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index daca37f..0000000 Binary files a/readers/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/html_reader.cpython-312.pyc b/readers/__pycache__/html_reader.cpython-312.pyc deleted file mode 100644 index 96de8f1..0000000 Binary files a/readers/__pycache__/html_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/mindmap_reader.cpython-312.pyc b/readers/__pycache__/mindmap_reader.cpython-312.pyc deleted file mode 100644 index bb1c660..0000000 Binary files a/readers/__pycache__/mindmap_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/notion_reader.cpython-312.pyc b/readers/__pycache__/notion_reader.cpython-312.pyc deleted file mode 100644 index e96e51a..0000000 Binary files a/readers/__pycache__/notion_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/obsidian_reader.cpython-312.pyc b/readers/__pycache__/obsidian_reader.cpython-312.pyc deleted file mode 100644 index 96b6f39..0000000 Binary files a/readers/__pycache__/obsidian_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/office_reader.cpython-312.pyc b/readers/__pycache__/office_reader.cpython-312.pyc deleted file mode 100644 index 49691b6..0000000 Binary files a/readers/__pycache__/office_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/pdf_reader.cpython-312.pyc b/readers/__pycache__/pdf_reader.cpython-312.pyc deleted file mode 100644 index 1af7717..0000000 Binary files a/readers/__pycache__/pdf_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/__pycache__/text_reader.cpython-312.pyc b/readers/__pycache__/text_reader.cpython-312.pyc deleted file mode 100644 index c65bc65..0000000 Binary files a/readers/__pycache__/text_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/external/__pycache__/__init__.cpython-312.pyc b/readers/external/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 5c8fc1a..0000000 Binary files a/readers/external/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/readers/external/__pycache__/notion_reader.cpython-312.pyc b/readers/external/__pycache__/notion_reader.cpython-312.pyc deleted file mode 100644 index 6b76fa9..0000000 Binary files a/readers/external/__pycache__/notion_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/external/__pycache__/obsidian_reader.cpython-312.pyc b/readers/external/__pycache__/obsidian_reader.cpython-312.pyc deleted file mode 100644 index ec5c623..0000000 Binary files a/readers/external/__pycache__/obsidian_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/office/__pycache__/__init__.cpython-312.pyc b/readers/office/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 054d3b8..0000000 Binary files a/readers/office/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/readers/office/__pycache__/excel_reader.cpython-312.pyc b/readers/office/__pycache__/excel_reader.cpython-312.pyc deleted file mode 100644 index 4e2777d..0000000 Binary files a/readers/office/__pycache__/excel_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/office/__pycache__/ppt_reader.cpython-312.pyc b/readers/office/__pycache__/ppt_reader.cpython-312.pyc deleted file mode 100644 index 9298d30..0000000 Binary files a/readers/office/__pycache__/ppt_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/office/__pycache__/word_reader.cpython-312.pyc b/readers/office/__pycache__/word_reader.cpython-312.pyc deleted file mode 100644 index f7bc5d6..0000000 Binary files a/readers/office/__pycache__/word_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/others/__pycache__/__init__.cpython-312.pyc b/readers/others/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index f820145..0000000 Binary files a/readers/others/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/readers/others/__pycache__/html_reader.cpython-312.pyc b/readers/others/__pycache__/html_reader.cpython-312.pyc deleted file mode 100644 index 9547f6f..0000000 Binary files a/readers/others/__pycache__/html_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/others/__pycache__/mindmap_reader.cpython-312.pyc b/readers/others/__pycache__/mindmap_reader.cpython-312.pyc deleted file mode 100644 index df1d4c0..0000000 Binary files a/readers/others/__pycache__/mindmap_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/others/__pycache__/pdf_reader.cpython-312.pyc b/readers/others/__pycache__/pdf_reader.cpython-312.pyc deleted file mode 100644 index 798e6a7..0000000 Binary files a/readers/others/__pycache__/pdf_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/text/__pycache__/__init__.cpython-312.pyc b/readers/text/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index a7e7740..0000000 Binary files a/readers/text/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/readers/text/__pycache__/markdown_reader.cpython-312.pyc b/readers/text/__pycache__/markdown_reader.cpython-312.pyc deleted file mode 100644 index 26bd4ad..0000000 Binary files a/readers/text/__pycache__/markdown_reader.cpython-312.pyc and /dev/null differ diff --git a/readers/text/__pycache__/text_reader.cpython-312.pyc b/readers/text/__pycache__/text_reader.cpython-312.pyc deleted file mode 100644 index b8d9c6b..0000000 Binary files a/readers/text/__pycache__/text_reader.cpython-312.pyc and /dev/null differ diff --git a/test_pdf.py b/test_pdf.py index e43e95b..9b22d59 100644 --- a/test_pdf.py +++ b/test_pdf.py @@ -6,7 +6,7 @@ sys.path.insert(0, str(Path(__file__).parent)) -from readers.others.pdf_reader import PdfReader +from readers.others.pdf_reader import PdfReader as PDFReader from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import A4