Skip to content

refactor(apps): eliminate RAG app boilerplate across 14 apps#371

Closed
luojiyin1987 wants to merge 5 commits into
StarTrail-org:mainfrom
luojiyin1987:refactor/chat-export-dedup
Closed

refactor(apps): eliminate RAG app boilerplate across 14 apps#371
luojiyin1987 wants to merge 5 commits into
StarTrail-org:mainfrom
luojiyin1987:refactor/chat-export-dedup

Conversation

@luojiyin1987

Copy link
Copy Markdown

Closes #370

Summary

Eliminates ~230 lines of duplicated boilerplate across the 14 RAG example apps.

Changes

Phase 1: Merge chatgpt_rag ↔ claude_rag

  • New ChatExportRAG shared base class with unified _find_exports, _add_specific_arguments, load_data, per-source max_items loop
  • chatgpt_rag.py: 187 → 36 lines, claude_rag.py: 190 → 37 lines

Phase 2: Extract per-source processing loop

  • New _foreach_source() helper in BaseRAGExample — handles max_items tracking, exception handling, progress printing
  • 4 apps migrated, max_items logic now lives in ONE place

Phase 3: Eliminate __main__ boilerplate

  • New ClassName.main() classmethod + _print_header() in BaseRAGExample
  • example_queries param moved to __init__
  • All 14 app if __name__ == "__main__" blocks → 1 line: ClassName.main()

Line counts

File Before After
chatgpt_rag.py 187 36
claude_rag.py 190 37
wechat_rag.py 190 166
email_rag.py 158 134
browser_rag.py 172 134
chat_export_rag.py (new) 134
Net ~-230

No functional changes. 5 separate commits for easy review.

…lass

- Create apps/chat_export_rag.py (153 lines) with unified: _find_exports,
  _add_specific_arguments, load_data, per-source max_items loop
- chatgpt_rag.py: 187 → 50 lines (-137)
- claude_rag.py: 190 → 51 lines (-139)
- Net: -123 lines, config-driven via constructor params
…urce iteration

- Add _foreach_source() to BaseRAGExample — handles max_items tracking,
  per-source printing, and exception handling in one place
- Migrate chat_export_rag, browser_rag, email_rag, wechat_rag to use it
- Each app's load_data() drops the verbose per-source loop (~20 lines
  each) replacing it with a single _foreach_source() call
- Net: +81/-124 lines across 5 files
…_ boilerplate

- Add BaseRAGExample.main() classmethod — prints header + runs app
- Add example_queries param to BaseRAGExample.__init__
- Add _print_header() method (overridable for platform warnings, help text)
- All 14 app __main__ blocks reduced to 1-line ClassName.main()
- Fix ChatExportRAG to pass example_queries through to BaseRAGExample
- Net: +110/-171 lines across 15 files
@luojiyin1987

Copy link
Copy Markdown
Author

pr 太大了, 我先关闭了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(apps): eliminate RAG app boilerplate across 14 apps

1 participant