Class: Postnhost::Translation::ArticleVariantTranslator
- Inherits:
-
BaseService
- Object
- BaseService
- Postnhost::Translation::ArticleVariantTranslator
- Defined in:
- app/services/postnhost/translation/article_variant_translator.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(article_id:, language_id:, llm_client: OpenaiLlmClient.new) ⇒ ArticleVariantTranslator
constructor
A new instance of ArticleVariantTranslator.
Methods inherited from BaseService
Constructor Details
#initialize(article_id:, language_id:, llm_client: OpenaiLlmClient.new) ⇒ ArticleVariantTranslator
Returns a new instance of ArticleVariantTranslator.
4 5 6 7 8 |
# File 'app/services/postnhost/translation/article_variant_translator.rb', line 4 def initialize(article_id:, language_id:, llm_client: OpenaiLlmClient.new) @article_id = article_id @language_id = language_id @llm_client = llm_client end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/services/postnhost/translation/article_variant_translator.rb', line 10 def call load_records return failure("Translation source or language not found") unless article && language return failure("Published translation source not found") unless source load_variant return failure("Translation variant not found") unless variant attributes = translated_attributes return finish_with_failure("Translation failed") if attributes[:title].blank? || attributes[:content].blank? variant.update!(attributes.merge(generating: false)) success(variant) rescue StandardError => e mark_generation_finished failure(e.) end |