Skip to content

Conversation

@dongsjoa-byte
Copy link

Summary

Extract duplicated LLM client code from 4 engines (Insight/Media/Query/Report) into a single utils/llm_provider.py module, reducing ~700 lines of boilerplate.

Key Changes

  • New unified module: utils/llm_provider.py - auto-detects token type:
    • sk-ant-oat* → Anthropic SDK + OAuth mode (Claude Code tokens)
    • sk-ant-* → Anthropic SDK + standard API key
    • Others → OpenAI SDK (backward compatible)
  • Engine refactoring: Each engine's llms/base.py now inherits from the unified client with engine-specific defaults
  • ForumEngine/KeywordOptimizer/TopicExtractor: Updated to use unified client
  • requirements.txt: Added anthropic>=0.34.0, relaxed pinned versions for broader compatibility

Motivation

  1. The 4 engines had nearly identical LLM client implementations (~170 lines each)
  2. Adding Anthropic support required modifying all 4 files identically
  3. This PR centralizes the logic so future provider additions only need one change

Backward Compatibility

  • All existing OpenAI-compatible API keys continue to work unchanged
  • Constructor signatures remain the same: LLMClient(api_key, model_name, base_url)
  • No changes to engine behavior or output

- Extract duplicated LLM client code from 4 engines into utils/llm_provider.py
- Auto-detect token type: OpenAI SDK, Anthropic API key, or Claude Code OAuth
- Each engine's llms/base.py now inherits from the unified client
- Add anthropic SDK to requirements.txt
- Update ForumEngine, KeywordOptimizer, TopicExtractor to use unified client
- Fix pinned versions (Pillow, matplotlib) for broader compatibility

Reduces ~700 lines of duplicated boilerplate code across engines.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. LLM API Various issues caused by large model APIs labels Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLM API Various issues caused by large model APIs size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant