|
2 | 2 |
|
3 | 3 | require_relative "htm/version" |
4 | 4 | require_relative "htm/errors" |
5 | | -require_relative "htm/configuration" |
| 5 | +require_relative "htm/config" |
6 | 6 | require_relative "htm/circuit_breaker" |
7 | 7 | require_relative "htm/active_record_config" |
8 | 8 | require_relative "htm/database" |
@@ -170,7 +170,7 @@ def remember(content, tags: [], metadata: {}) |
170 | 170 | enqueue_tags_job(node_id, manual_tags: tags) |
171 | 171 |
|
172 | 172 | # Enqueue proposition extraction if enabled and not already a proposition |
173 | | - if HTM.configuration.extract_propositions && !metadata[:is_proposition] |
| 173 | + if HTM.config.extract_propositions && !metadata[:is_proposition] |
174 | 174 | enqueue_propositions_job(node_id) |
175 | 175 | end |
176 | 176 | else |
@@ -679,4 +679,125 @@ def validate_metadata!(metadata) |
679 | 679 | end |
680 | 680 | end |
681 | 681 |
|
| 682 | + # =========================================================================== |
| 683 | + # Class Methods |
| 684 | + # =========================================================================== |
| 685 | + |
| 686 | + class << self |
| 687 | + # Get current configuration (singleton) |
| 688 | + # |
| 689 | + # @return [HTM::Config] |
| 690 | + # |
| 691 | + def config |
| 692 | + @config ||= Config.new |
| 693 | + end |
| 694 | + |
| 695 | + # Alias for backward compatibility |
| 696 | + alias configuration config |
| 697 | + |
| 698 | + # Configure HTM |
| 699 | + # |
| 700 | + # @yield [config] Configuration object |
| 701 | + # @yieldparam config [HTM::Config] |
| 702 | + # |
| 703 | + # @example Custom configuration |
| 704 | + # HTM.configure do |config| |
| 705 | + # config.embedding_generator = ->(text) { MyEmbedder.embed(text) } |
| 706 | + # config.tag_extractor = ->(text, ontology) { MyTagger.extract(text, ontology) } |
| 707 | + # end |
| 708 | + # |
| 709 | + # @example Default configuration |
| 710 | + # HTM.configure # Uses RubyLLM defaults |
| 711 | + # |
| 712 | + def configure |
| 713 | + yield(config) if block_given? |
| 714 | + config.validate! |
| 715 | + config |
| 716 | + end |
| 717 | + |
| 718 | + # Reset configuration to defaults |
| 719 | + def reset_configuration! |
| 720 | + @config = nil |
| 721 | + end |
| 722 | + |
| 723 | + # Get current environment |
| 724 | + # |
| 725 | + # @return [String] Current environment name |
| 726 | + # |
| 727 | + def env |
| 728 | + Config.env |
| 729 | + end |
| 730 | + |
| 731 | + # Check if running in test environment |
| 732 | + # |
| 733 | + # @return [Boolean] |
| 734 | + # |
| 735 | + def test? |
| 736 | + env == 'test' |
| 737 | + end |
| 738 | + |
| 739 | + # Check if running in development environment |
| 740 | + # |
| 741 | + # @return [Boolean] |
| 742 | + # |
| 743 | + def development? |
| 744 | + env == 'development' |
| 745 | + end |
| 746 | + |
| 747 | + # Check if running in production environment |
| 748 | + # |
| 749 | + # @return [Boolean] |
| 750 | + # |
| 751 | + def production? |
| 752 | + env == 'production' |
| 753 | + end |
| 754 | + |
| 755 | + # Generate embedding using EmbeddingService |
| 756 | + # |
| 757 | + # @param text [String] Text to embed |
| 758 | + # @return [Array<Float>] Embedding vector (original, not padded) |
| 759 | + # |
| 760 | + def embed(text) |
| 761 | + result = HTM::EmbeddingService.generate(text) |
| 762 | + result[:embedding] |
| 763 | + end |
| 764 | + |
| 765 | + # Extract tags using TagService |
| 766 | + # |
| 767 | + # @param text [String] Text to analyze |
| 768 | + # @param existing_ontology [Array<String>] Sample of existing tags for context |
| 769 | + # @return [Array<String>] Extracted and validated tag names |
| 770 | + # |
| 771 | + def extract_tags(text, existing_ontology: []) |
| 772 | + HTM::TagService.extract(text, existing_ontology: existing_ontology) |
| 773 | + end |
| 774 | + |
| 775 | + # Extract propositions using PropositionService |
| 776 | + # |
| 777 | + # @param text [String] Text to analyze |
| 778 | + # @return [Array<String>] Extracted atomic propositions |
| 779 | + # |
| 780 | + def extract_propositions(text) |
| 781 | + HTM::PropositionService.extract(text) |
| 782 | + end |
| 783 | + |
| 784 | + # Count tokens using configured counter |
| 785 | + # |
| 786 | + # @param text [String] Text to count tokens for |
| 787 | + # @return [Integer] Token count |
| 788 | + # |
| 789 | + def count_tokens(text) |
| 790 | + config.token_counter.call(text) |
| 791 | + rescue StandardError => e |
| 792 | + raise HTM::ValidationError, "Token counting failed: #{e.message}" |
| 793 | + end |
| 794 | + |
| 795 | + # Get configured logger |
| 796 | + # |
| 797 | + # @return [Logger] Configured logger instance |
| 798 | + # |
| 799 | + def logger |
| 800 | + config.logger |
| 801 | + end |
| 802 | + end |
682 | 803 | end |
0 commit comments