Add Phase 3 operations: detect_language, generate_tags, anonymize, and compare#3
Add Phase 3 operations: detect_language, generate_tags, anonymize, and compare#3
Conversation
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
- Add require statements and module methods to main Text module - Add model configuration attributes for all new operations - Add String extension methods with special handling for compare() Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
- Complete test suites for all 4 operations with 151 total tests - Tests cover simple/structured responses, error handling, configuration - Updated String extension tests for new methods - All tests passing with established mocking patterns Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
- Create Validation module with ValidationError class - Add validate_text!, validate_required!, validate_array!, validate_one_of! helpers - All 13 operations now validate inputs before LLM calls - Consistent error messages: "text cannot be nil", "schema is required", etc. - Update manual-test binstub with Phase 3 operations - Full test coverage for validation (186 tests, 516 assertions) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds Phase 3 operations to the ruby_llm-text gem, introducing four new text processing methods with comprehensive validation and test coverage. The changes build upon the existing Phase 1 and Phase 2 operations by adding language detection, tag generation, PII anonymization, and text comparison capabilities.
Changes:
- Four new text operations:
detect_language,generate_tags,anonymize, andcomparewith configurable behavior and structured outputs - New
Validationmodule providing consistent input validation across all operations (replacing ad-hoc ArgumentError usage) - Extended string monkey-patching support for all new operations
- Version bump from 0.2.0 to 0.3.0 with comprehensive documentation updates
Reviewed changes
Copilot reviewed 30 out of 31 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/ruby_llm/text/validation.rb | New validation module with ValidationError class and helper methods for consistent input validation |
| lib/ruby_llm/text/detect_language.rb | Language detection with optional confidence scores and ISO language codes |
| lib/ruby_llm/text/generate_tags.rb | Tag/keyword generation with multiple style options (keywords, topics, hashtags) |
| lib/ruby_llm/text/anonymize.rb | PII anonymization supporting multiple entity types and replacement styles |
| lib/ruby_llm/text/compare.rb | Text comparison with similarity scoring and multiple comparison modes |
| lib/ruby_llm/text/configuration.rb | Added configuration attributes for the four new operations |
| lib/ruby_llm/text.rb | Module-level API methods for new operations |
| lib/ruby_llm/text/string_ext.rb | String extensions for new operations |
| lib/ruby_llm/text/{summarize,translate,extract,classify,rewrite,answer,sentiment,key_points,grammar}.rb | Updated existing operations to use Validation module |
| test/ruby_llm/text/validation_test.rb | Comprehensive validation module tests including integration tests |
| test/ruby_llm/text/{detect_language,generate_tags,anonymize,compare}_test.rb | Full test suites for new operations |
| test/ruby_llm/text/string_ext_test.rb | Tests for new string extensions |
| test/ruby_llm/text/{rewrite,extract,classify}_test.rb | Updated tests to expect ValidationError instead of ArgumentError |
| README.md | Documentation for all four new operations with examples |
| CHANGELOG.md | Version 0.3.0 release notes |
| AI.md | New AI assistant context document |
| bin/manual-test | Manual testing script updated with Phase 3 examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The else branch was recursively calling build_prompt, which returns a complete prompt string. This caused the instruction to contain a nested prompt instead of just the instruction text. Now uses the instruction string directly, matching the pattern in generate_tags.rb. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 31 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add ALL_PII_TYPES constant with all 6 PII types - Make :all shortcut expand to ALL_PII_TYPES (not just defaults) - Add SSN and credit_cards handling to :numbered style - Add SSN and credit_cards handling to :descriptive style Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 30 out of 31 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adds 4 new text operations with input validation and comprehensive test coverage.
New Operations
detect_language- Identifies the language of input textgenerate_tags- Extracts relevant tags/keywords from textanonymize- Redacts PII (names, emails, phone numbers, etc.) from textcompare- Compares two texts and identifies similarities/differencesChanges
lib/ruby_llm/text/Validationmodule for consistent input validation