refactor: remove explicit None assignments for usage token fields#53
Conversation
Remove unnecessary explicit None assignments for optional usage fields (input_tokens, output_tokens, billed_tokens, cached_tokens, reasoning_tokens) since they already default to None in their respective Usage classes. - Anthropic: Extract cached_tokens from cache_read_input_tokens - Google: Remove billed_tokens and cached_tokens explicit None - OpenAI: Remove billed_tokens explicit None - XAI: Remove billed_tokens explicit None - ByteDance: Remove input_tokens and output_tokens explicit None
Handle Magistral array format in content parsing for reasoning models. When content is an array, extract text from blocks with type 'text'.
Pull Request Review - PR #53SummaryThis PR makes two types of changes:
✅ Positive FindingsCode Quality:
Anthropic Enhancement:
Mistral Feature:
🔍 Issues & Concerns1. Potential Bug in Mistral Content Parsing (HIGH PRIORITY)Location: The Recommendation: Add type checking before calling Same issue exists in: 2. Missing Test Coverage (MEDIUM PRIORITY)The Mistral Magistral array format handling is a significant new feature, but there are no tests for it:
Recommendation: Add unit tests covering array format, multiple blocks, malformed blocks, and backward compatibility 3. Incomplete Documentation (LOW PRIORITY)No inline comments explaining why this array format exists or reference to Mistral API documentation. Future maintainers might not understand this is model-specific behavior. 4. Code Duplication (LOW PRIORITY)The streaming implementation duplicates the array parsing logic. Consider extracting to a shared helper method for DRY principles. 📊 Testing & ValidationMissing:
🔒 Security & PerformanceNo security concerns identified - Changes are purely data parsing/transformation Performance: Negligible impact 📝 Overall AssessmentRefactoring portion (explicit None removal): ✅ Excellent - clean improvement Mistral feature portion:
🎯 RecommendationsBefore merging:
Nice to have:
Approval Status: ⏸️ Requesting changes Review generated with Claude Code |
Prevent AttributeError on malformed responses by checking that content blocks are dictionaries before calling .get() method. Addresses PR review feedback.
Code ReviewI've reviewed PR #53 and have the following feedback: ✅ Strengths
|
Summary
This PR removes unnecessary explicit
Noneassignments for optional usage fields since they already default toNonein their respective Usage classes.Changes
Commit 1: Usage Cleanup
cached_tokensfromcache_read_input_tokensinstead of setting toNonebilled_tokensandcached_tokensexplicitNonebilled_tokensexplicitNonebilled_tokensexplicitNoneinput_tokensandoutput_tokensexplicitNoneCommit 2: Mistral Reasoning Support
Impact