Skip to content

Commit

Permalink
extra
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 5, 2024
1 parent c3d9a1b commit ca284f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll-chatgpt-translate/chatgpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def translate(markdown, min: 32, window_length: 2000)
par = pa.dup
par.strip!
if @source == @target
Jekyll.logger.debug("No need to translate from #{@source.inspect} to #{@target.inspect}: #{par.inspect}")
Jekyll.logger.debug("No need to translate from #{@source.inspect} to itself: #{par.inspect}")
ready[i] = par
elsif par.length < min
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
Expand Down
17 changes: 11 additions & 6 deletions test/test_chatgpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# License:: MIT
class GptTranslate::ChatGPTTest < Minitest::Test
def test_short_text
chat = GptTranslate::ChatGPT.new('fake-key', 'foo', 'xx', 'xx')
chat = GptTranslate::ChatGPT.new('fake-key', 'foo', 'xx', 'zz')
assert_equal('Hello, world!', chat.translate('Hello, world!'))
end

Expand All @@ -56,12 +56,12 @@ def test_ordered_list_item
end

def test_dry_mode
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'xx')
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'zz')
assert_equal(38, chat.translate('This text should not be sent to OpenAI', min: 100).length)
end

def test_no_translation
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'xx')
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'zz')
chat.translate(
"
How are you, my friend? This text must be translated through ChatGPT.
Expand All @@ -82,12 +82,17 @@ def test_no_translation
end

def test_markup
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', 'xx')
assert_equal('<img src="a"/>', chat.translate('<img src="a"/>'))
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', 'zz')
assert_equal('<img src="a"/>', chat.translate('<img src="a"/>', min: 1))
end

def test_image
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', 'zz')
assert_equal('![some image](/foo.png)', chat.translate('![some image](/foo.png)', min: 1))
end

def test_code_block
chat = GptTranslate::ChatGPT.new('fake-key', '', 'xx', 'xx')
chat = GptTranslate::ChatGPT.new('fake-key', '', 'xx', 'zz')
chat.translate("```\ntest\n```", min: 0)
end

Expand Down

0 comments on commit ca284f1

Please sign in to comment.