mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-15 11:36:26 +08:00
There is a bug now where if the new DiscourseAi translator does not return values back in `<translator>` tags, we return the full response. This commit scopes both the input and output in its respective tags, and returns an empty string if there is no output tag. The problem only exists on topic translations, not post translations, as posts contain html and the prompt for translating indicates there will be html (topics do not have them). So an accompanying migration has been added example incorrect result: ``` "To provide a translation, I first need the original text in a specific language to translate it into \"pt\". Could you please provide the text you wish to translate, including any HTML tags?" ```
16 lines
371 B
Ruby
16 lines
371 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CleanupAiTranslations < ActiveRecord::Migration[7.2]
|
|
def up
|
|
execute <<~SQL
|
|
DELETE FROM discourse_translator_topic_translations
|
|
WHERE translation LIKE 'To%'
|
|
AND translation ILIKE '%translat%'
|
|
AND LENGTH(translation) > 100;
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|