Class: LlmTranslate::Config
- Inherits:
-
Object
- Object
- LlmTranslate::Config
- Defined in:
- lib/llm_translate/config.rb
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #ai_host ⇒ Object
- #ai_model ⇒ Object
- #ai_provider ⇒ Object
-
#api_key ⇒ Object
AI Configuration.
- #concurrent_chunks ⇒ Object
-
#concurrent_files ⇒ Object
Performance Configuration.
-
#default_prompt ⇒ Object
Translation Configuration.
- #enable_document_splitting? ⇒ Boolean
- #exclude_patterns ⇒ Object
- #filename_strategy ⇒ Object
- #filename_suffix ⇒ Object
- #generate_error_report? ⇒ Boolean
-
#generate_report? ⇒ Boolean
Output Configuration.
- #include_patterns ⇒ Object
-
#initialize(config_path, cli_options = {}) ⇒ Config
constructor
A new instance of Config.
-
#input_directory ⇒ Object
File Configuration.
- #input_file ⇒ Object
-
#log_level ⇒ Object
Logging Configuration.
- #log_output ⇒ Object
-
#max_chars_for_splitting ⇒ Object
Document Splitting Configuration.
- #max_consecutive_errors ⇒ Object
- #max_tokens ⇒ Object
-
#on_error ⇒ Object
Error Handling Configuration.
- #output_directory ⇒ Object
- #output_file ⇒ Object
- #overwrite_policy ⇒ Object
- #preserve_directory_structure? ⇒ Boolean
- #preserve_formatting? ⇒ Boolean
- #report_path ⇒ Object
- #request_interval ⇒ Object
- #retry_attempts ⇒ Object
- #retry_delay ⇒ Object
- #retry_on_failure ⇒ Object
- #should_stop_on_error?(error_count) ⇒ Boolean
- #single_file_mode? ⇒ Boolean
- #source_language ⇒ Object
- #split_every_chars ⇒ Object
- #target_language ⇒ Object
- #temperature ⇒ Object
- #timeout ⇒ Object
- #translate_code_comments? ⇒ Boolean
- #verbose_translation? ⇒ Boolean
Constructor Details
#initialize(config_path, cli_options = {}) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 |
# File 'lib/llm_translate/config.rb', line 13 def initialize(config_path, = {}) = @data = load_config_file(config_path) apply_cli_overrides validate_config end |
Instance Attribute Details
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options.
7 8 9 |
# File 'lib/llm_translate/config.rb', line 7 def end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/llm_translate/config.rb', line 7 def data @data end |
Class Method Details
.load(config_path, cli_options = {}) ⇒ Object
9 10 11 |
# File 'lib/llm_translate/config.rb', line 9 def self.load(config_path, = {}) new(config_path, ) end |
Instance Method Details
#ai_host ⇒ Object
25 26 27 |
# File 'lib/llm_translate/config.rb', line 25 def ai_host resolve_env_var(data.dig('ai', 'host')) || 'https://aihubmix.com' end |
#ai_model ⇒ Object
33 34 35 |
# File 'lib/llm_translate/config.rb', line 33 def ai_model data.dig('ai', 'model') || 'claude-3-7-sonnet-20250219' end |
#ai_provider ⇒ Object
29 30 31 |
# File 'lib/llm_translate/config.rb', line 29 def ai_provider data.dig('ai', 'provider') || 'openai' end |
#api_key ⇒ Object
AI Configuration
21 22 23 |
# File 'lib/llm_translate/config.rb', line 21 def api_key resolve_env_var(data.dig('ai', 'api_key')) end |
#concurrent_chunks ⇒ Object
91 92 93 |
# File 'lib/llm_translate/config.rb', line 91 def concurrent_chunks data.dig('translation', 'concurrent_chunks') || 3 end |
#concurrent_files ⇒ Object
Performance Configuration
184 185 186 |
# File 'lib/llm_translate/config.rb', line 184 def concurrent_files data.dig('performance', 'concurrent_files') || 3 end |
#default_prompt ⇒ Object
Translation Configuration
58 59 60 |
# File 'lib/llm_translate/config.rb', line 58 def default_prompt [:prompt] || data.dig('translation', 'default_prompt') || default_translation_prompt end |
#enable_document_splitting? ⇒ Boolean
87 88 89 |
# File 'lib/llm_translate/config.rb', line 87 def enable_document_splitting? data.dig('translation', 'enable_splitting') != false end |
#exclude_patterns ⇒ Object
137 138 139 |
# File 'lib/llm_translate/config.rb', line 137 def exclude_patterns data.dig('files', 'exclude_patterns') || [] end |
#filename_strategy ⇒ Object
125 126 127 |
# File 'lib/llm_translate/config.rb', line 125 def filename_strategy data.dig('files', 'filename_strategy') || 'suffix' end |
#filename_suffix ⇒ Object
129 130 131 |
# File 'lib/llm_translate/config.rb', line 129 def filename_suffix data.dig('files', 'filename_suffix') || '.zh' end |
#generate_error_report? ⇒ Boolean
175 176 177 |
# File 'lib/llm_translate/config.rb', line 175 def generate_error_report? data.dig('error_handling', 'generate_error_report') != false end |
#generate_report? ⇒ Boolean
Output Configuration
193 194 195 |
# File 'lib/llm_translate/config.rb', line 193 def generate_report? data.dig('output', 'generate_report') != false end |
#include_patterns ⇒ Object
133 134 135 |
# File 'lib/llm_translate/config.rb', line 133 def include_patterns data.dig('files', 'include_patterns') || ['**/*.md', '**/*.markdown'] end |
#input_directory ⇒ Object
File Configuration
96 97 98 |
# File 'lib/llm_translate/config.rb', line 96 def input_directory [:input] || data.dig('files', 'input_directory') || './docs' end |
#input_file ⇒ Object
104 105 106 107 108 |
# File 'lib/llm_translate/config.rb', line 104 def input_file return [:input] if [:input] data.dig('files', 'input_file') end |
#log_level ⇒ Object
Logging Configuration
150 151 152 |
# File 'lib/llm_translate/config.rb', line 150 def log_level [:verbose] ? 'debug' : (data.dig('logging', 'level') || 'info') end |
#log_output ⇒ Object
154 155 156 |
# File 'lib/llm_translate/config.rb', line 154 def log_output data.dig('logging', 'output') || 'console' end |
#max_chars_for_splitting ⇒ Object
Document Splitting Configuration
79 80 81 |
# File 'lib/llm_translate/config.rb', line 79 def max_chars_for_splitting data.dig('translation', 'max_chars') || 20_000 end |
#max_consecutive_errors ⇒ Object
167 168 169 |
# File 'lib/llm_translate/config.rb', line 167 def max_consecutive_errors data.dig('error_handling', 'max_consecutive_errors') || 5 end |
#max_tokens ⇒ Object
41 42 43 |
# File 'lib/llm_translate/config.rb', line 41 def max_tokens data.dig('ai', 'max_tokens') || 40_000 end |
#on_error ⇒ Object
Error Handling Configuration
163 164 165 |
# File 'lib/llm_translate/config.rb', line 163 def on_error data.dig('error_handling', 'on_error') || 'log_and_continue' end |
#output_directory ⇒ Object
100 101 102 |
# File 'lib/llm_translate/config.rb', line 100 def output_directory [:output] || data.dig('files', 'output_directory') || './docs-translated' end |
#output_file ⇒ Object
110 111 112 113 114 |
# File 'lib/llm_translate/config.rb', line 110 def output_file return [:output] if [:input] && [:output] data.dig('files', 'output_file') end |
#overwrite_policy ⇒ Object
145 146 147 |
# File 'lib/llm_translate/config.rb', line 145 def overwrite_policy data.dig('files', 'overwrite_policy') || 'ask' end |
#preserve_directory_structure? ⇒ Boolean
141 142 143 |
# File 'lib/llm_translate/config.rb', line 141 def preserve_directory_structure? data.dig('files', 'preserve_directory_structure') != false end |
#preserve_formatting? ⇒ Boolean
70 71 72 |
# File 'lib/llm_translate/config.rb', line 70 def preserve_formatting? data.dig('translation', 'preserve_formatting') != false end |
#report_path ⇒ Object
197 198 199 |
# File 'lib/llm_translate/config.rb', line 197 def report_path data.dig('output', 'report_path') || './reports/translation_report.md' end |
#request_interval ⇒ Object
188 189 190 |
# File 'lib/llm_translate/config.rb', line 188 def request_interval data.dig('performance', 'request_interval') || 1 end |
#retry_attempts ⇒ Object
45 46 47 |
# File 'lib/llm_translate/config.rb', line 45 def retry_attempts data.dig('ai', 'retry_attempts') || 3 end |
#retry_delay ⇒ Object
49 50 51 |
# File 'lib/llm_translate/config.rb', line 49 def retry_delay data.dig('ai', 'retry_delay') || 2 end |
#retry_on_failure ⇒ Object
171 172 173 |
# File 'lib/llm_translate/config.rb', line 171 def retry_on_failure data.dig('error_handling', 'retry_on_failure') || 2 end |
#should_stop_on_error?(error_count) ⇒ Boolean
179 180 181 |
# File 'lib/llm_translate/config.rb', line 179 def should_stop_on_error?(error_count) on_error == 'stop' || error_count >= max_consecutive_errors end |
#single_file_mode? ⇒ Boolean
116 117 118 119 120 121 122 123 |
# File 'lib/llm_translate/config.rb', line 116 def single_file_mode? input_file_path = input_file output_file_path = output_file # Both must be present and input must be a file (not directory) for single file mode !input_file_path.nil? && !output_file_path.nil? && File.exist?(input_file_path) && File.file?(input_file_path) end |
#source_language ⇒ Object
66 67 68 |
# File 'lib/llm_translate/config.rb', line 66 def source_language data.dig('translation', 'source_language') || 'auto' end |
#split_every_chars ⇒ Object
83 84 85 |
# File 'lib/llm_translate/config.rb', line 83 def split_every_chars data.dig('translation', 'every_chars') || 20_000 end |
#target_language ⇒ Object
62 63 64 |
# File 'lib/llm_translate/config.rb', line 62 def target_language data.dig('translation', 'target_language') || 'zh-CN' end |
#temperature ⇒ Object
37 38 39 |
# File 'lib/llm_translate/config.rb', line 37 def temperature data.dig('ai', 'temperature') || 0.3 end |
#timeout ⇒ Object
53 54 55 |
# File 'lib/llm_translate/config.rb', line 53 def timeout data.dig('ai', 'timeout') || 60 end |
#translate_code_comments? ⇒ Boolean
74 75 76 |
# File 'lib/llm_translate/config.rb', line 74 def translate_code_comments? data.dig('translation', 'translate_code_comments') == true end |
#verbose_translation? ⇒ Boolean
158 159 160 |
# File 'lib/llm_translate/config.rb', line 158 def verbose_translation? [:verbose] || data.dig('logging', 'verbose_translation') == true end |