llm_translate 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/llm_translate/config.rb +56 -4
- data/lib/llm_translate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ab1da1df23759b64860a8f6c5e33e022d8a73aa842ed494448cb121a55ecaf8
|
4
|
+
data.tar.gz: 1f3536587e0a55c4c09720584cb798538084953a1dd0bec004517f7a28eb46e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e9bd1e7166440b416dc9b1bc92fb6ca3b2a4f96ce9460973753cdae24ed7868cca9fd270c05a0316e3c33c96bbef9000f704a71e0f9564815e6b597e103d35
|
7
|
+
data.tar.gz: 262162b0d498b1673a1cebc5ca7ea1fcd97924ee5019fd7b000e7c8a089ac97d87e57ec0686d0cc84d755b5f3500218449f273be35cfc34ecc9b5057902691d5
|
data/lib/llm_translate/config.rb
CHANGED
@@ -39,7 +39,7 @@ module LlmTranslate
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def max_tokens
|
42
|
-
data.dig('ai', 'max_tokens') ||
|
42
|
+
data.dig('ai', 'max_tokens') || 40_000
|
43
43
|
end
|
44
44
|
|
45
45
|
def retry_attempts
|
@@ -85,15 +85,24 @@ module LlmTranslate
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def input_file
|
88
|
+
return cli_options[:input] if cli_options[:input]
|
89
|
+
|
88
90
|
data.dig('files', 'input_file')
|
89
91
|
end
|
90
92
|
|
91
93
|
def output_file
|
94
|
+
return cli_options[:output] if cli_options[:input] && cli_options[:output]
|
95
|
+
|
92
96
|
data.dig('files', 'output_file')
|
93
97
|
end
|
94
98
|
|
95
99
|
def single_file_mode?
|
96
|
-
|
100
|
+
input_file_path = input_file
|
101
|
+
output_file_path = output_file
|
102
|
+
|
103
|
+
# Both must be present and input must be a file (not directory) for single file mode
|
104
|
+
!input_file_path.nil? && !output_file_path.nil? &&
|
105
|
+
File.exist?(input_file_path) && File.file?(input_file_path)
|
97
106
|
end
|
98
107
|
|
99
108
|
def filename_strategy
|
@@ -196,9 +205,52 @@ module LlmTranslate
|
|
196
205
|
'API key is required. Set LLM_TRANSLATE_API_KEY environment variable or configure in config file.'
|
197
206
|
end
|
198
207
|
|
199
|
-
|
208
|
+
# Validate input/output based on mode
|
209
|
+
if single_file_mode?
|
210
|
+
validate_single_file_mode
|
211
|
+
else
|
212
|
+
validate_directory_mode
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def validate_single_file_mode
|
217
|
+
# Validate input file exists
|
218
|
+
unless input_file && File.exist?(input_file)
|
219
|
+
raise ConfigurationError, "Input file does not exist: #{input_file || 'not specified'}"
|
220
|
+
end
|
221
|
+
|
222
|
+
# Validate input is actually a file
|
223
|
+
unless File.file?(input_file)
|
224
|
+
raise ConfigurationError, "Input path is not a file: #{input_file}"
|
225
|
+
end
|
200
226
|
|
201
|
-
|
227
|
+
# Validate output file path
|
228
|
+
unless output_file
|
229
|
+
raise ConfigurationError, "Output file must be specified for single file mode"
|
230
|
+
end
|
231
|
+
|
232
|
+
# Ensure output directory exists
|
233
|
+
output_dir = File.dirname(output_file)
|
234
|
+
unless Dir.exist?(output_dir)
|
235
|
+
begin
|
236
|
+
FileUtils.mkdir_p(output_dir)
|
237
|
+
rescue StandardError => e
|
238
|
+
raise ConfigurationError, "Cannot create output directory #{output_dir}: #{e.message}"
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def validate_directory_mode
|
244
|
+
# Validate input directory
|
245
|
+
unless Dir.exist?(input_directory)
|
246
|
+
raise ConfigurationError, "Input directory does not exist: #{input_directory}"
|
247
|
+
end
|
248
|
+
|
249
|
+
# Ensure output directory parent exists
|
250
|
+
output_parent = File.dirname(output_directory)
|
251
|
+
unless Dir.exist?(output_parent)
|
252
|
+
raise ConfigurationError, "Output directory parent does not exist: #{output_parent}"
|
253
|
+
end
|
202
254
|
end
|
203
255
|
|
204
256
|
def resolve_env_var(value)
|