Skip to content

Conversation

@SL-Mar
Copy link
Owner

@SL-Mar SL-Mar commented Nov 11, 2025

Refactoring to improve algo generation

SL-Mar and others added 8 commits November 11, 2025 09:02
## Major Changes

### OpenAI SDK Migration (0.28 → 1.x+)
- Created LLMClient abstraction layer (quantcli/llm_client.py)
- Migrated all openai.ChatCompletion.create() calls to new SDK
- Removed global openai.api_key configuration
- Added LLMResponse dataclass for standardized responses
- Improved error handling and logging for LLM calls

### Dependency Updates
- Bumped Python requirement to >= 3.9
- Updated OpenAI SDK to >= 1.0.0
- Added modern dependencies: rich, pytest, mypy, ruff
- Created clean requirements.txt (replaced legacy freeze)
- Updated setup.py to v1.0.0 with enhanced metadata

### Testing Infrastructure
- Added pytest configuration (pytest.ini)
- Created test suite for LLMClient (tests/test_llm_client.py)
- Configured coverage reporting
- Added test markers (unit/integration/slow)

### Documentation
- Completely rewrote README.md (removed "legacy" branding)
- Added CHANGELOG.md with migration guide
- Updated installation instructions
- Added badges and modern formatting
- Highlighted v1.0.0 improvements

### Code Quality
- Added LLMClient with proper type hints
- Improved logging in processor.py
- Token usage tracking for cost monitoring
- Structured error handling

## Breaking Changes
- Requires OpenAI SDK >= 1.0.0 (incompatible with 0.28)
- Python >= 3.9 required (was 3.8)

## Migration Path
Users can upgrade seamlessly:
```bash
pip install --upgrade openai>=1.0.0
pip install -e .
```

No code changes required - LLMClient handles SDK differences internally.

---

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Move tkinter imports from module level to function level in processor.py
- Make GUI imports conditional in cli.py
- CLI commands now work without python3-tk system package
- Interactive mode shows helpful error message if tkinter unavailable
- All other CLI commands (search, list, download, etc.) fully functional
PROBLEM: Generated algorithms had 3 runtime errors on first backtest
- NoneType comparison in max/min operations
- Division by zero in position sizing
- Missing null guards before trading logic

SOLUTION: Multi-layered quality improvements

1. Enhanced Code Generation Prompt
   - Added explicit defensive programming requirements
   - Included safety pattern examples (None checks, division guards)
   - Emphasized PRODUCTION-READY code generation

2. Enhanced Refinement Prompt
   - Added safety checklist to refinement process
   - Ensures all defensive patterns are present

3. New QuantConnectValidator Class
   - Runtime safety validation layer
   - Detects: division by zero, None comparisons, missing IsReady checks
   - Provides actionable fix suggestions
   - File: quantcli/qc_validator.py

4. CLI Improvements
   - Fixed None return value handling in generate-code command
   - Better error messages for failed code generation

IMPACT:
- Improves generated code reliability
- Reduces manual fixes required
- Moves toward production-ready algorithms

TODO (v1.1.0):
- Integrate validator into generation pipeline
- Add test suite
- Document in CHANGELOG

Issue: See /tmp/github_issue_quality.md for full details
## Security Enhancements
- Add missing `requests` import in utils.py (CRITICAL BUG FIX)
- Implement URL validation before webbrowser.open() calls
- Add validate_url() function to check URL safety
- Replace hardcoded email with UNPAYWALL_EMAIL environment variable

## Configuration
- Create .env.example documenting all environment variables
- Add support for UNPAYWALL_EMAIL configuration

## Changes
- quantcli/utils.py: Add requests import, urlparse, validate_url()
- quantcli/cli.py: Add URL validation to browser operations
- quantcli/gui.py: Add URL validation to browser operations
- .env.example: Document all configurable environment variables

These changes improve security by validating all URLs before opening
them in the browser and fix the critical missing requests import bug.
- Installation verification steps
- Security testing procedures
- Example workflows
- Troubleshooting guide
- Complete CLI command reference
…V1sadPRrxj5sPHjWp7Wa

Claude/refactor modernize 2025 011 cv1sad p rrxj5s p hj wp7 wa
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.

3 participants