jekyll-chatgpt-translate 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 496c59378248bd1973071e0ed6d01d0e55253cf0c47dce9f72b2704ba315e9e3
4
- data.tar.gz: 13905a9d5f52ed1558f1e0679af7ec236936b4d77eb97d0c8e63ce3e0cb72ac7
3
+ metadata.gz: 76c9c7e2f01f4350b38e1343d88918c9a89bfb5ace6bc84855bba6cd401cf027
4
+ data.tar.gz: 35dbf1ac0f89d6a3a68de2a1f36ae451686b665a8ef4a3f9adc4054623d45dc9
5
5
  SHA512:
6
- metadata.gz: 63e2c67379437c2f6aa20cff512452fcb2d2237b1e5d8a1d8bb0155c67a4ee044bfb4957765bff3daab4d24fdb875779ec9bffd8419e1331f0efd3667ee19d38
7
- data.tar.gz: 84ab3c8daa5173849cbcaeeb067ddf7470fa04b099c1793582c99f44f4a64e0fbf65b842817e0c489996cd742d8335de3f4fc62576aaede50212aeb4ff7d7c22
6
+ metadata.gz: db448c1104508d9084c1b28ea687fda646b72c6c03b78e72c4423106c28d9414120b323957f0c967a7932926870fac33a7a7dc713571c0179f58cd5cdfca0f00
7
+ data.tar.gz: 96f431eb35b166ab4cc82575f8dbee0b80e845f5801d3d7436aede3d75becb196e3dd2aee36595742f0a664237bbe804d449e1f10348579b509111384beabb73
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ AllCops:
3
3
  - 'bin/**/*'
4
4
  - 'assets/**/*'
5
5
  DisplayCopNames: true
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.7
7
7
  SuggestExtensions: false
8
8
  NewCops: enable
9
9
 
data/README.md CHANGED
@@ -60,9 +60,14 @@ Full list of options available to specify in `_config.yml`:
60
60
  * `api_key_file` (optional) — the file with OpenAI API key. If this option is not specified,
61
61
  it is expected to have the key in the `OPENAI_API_KEY` environment variable.
62
62
 
63
- * `model` (optional) — specifies the model to use by ChatGPT.
63
+ * `api_key` (optional) — the OpenAI API key itself. This is a very bad idea to
64
+ specify it right in the `_config.yml` file, but it's still possible.
64
65
 
65
- * `source` (optional) — is the ISO-839-1 code of the source language.
66
+ * `model` (optional) — specifies the model to use by ChatGPT,
67
+ [examples are here](https://github.com/alexrudall/ruby-openai#models).
68
+
69
+ * `source` (optional) — is the [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
70
+ code of the source language.
66
71
 
67
72
  * `no_download` (optional) — if this attribute is present, the plugin won't try
68
73
  to find HTML versions of translated pages in the Internet and won't try to
@@ -79,7 +84,7 @@ This layout will be specified for the pages generated by this plugin.
79
84
 
80
85
  * `targets` (mandatory) — an array of target languages, each of which has the following attributes
81
86
 
82
- * `language` (mandatory) — ISO-839-1 code of the target language
87
+ * `language` (mandatory) — [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code of the target language
83
88
 
84
89
  * `permalink` (mandatory) — template to use for newly generated pages
85
90
 
@@ -93,7 +98,7 @@ This layout will be specified for the pages generated by this plugin.
93
98
  * `version` (optional) — the version that will be attached to each generated page,
94
99
  in order to avoid repetitive translations on one hand and enable re-translations
95
100
  when the `version` is changed on another hand. By default, the version of
96
- the plugin will be used here, unless you set your own value.
101
+ this plugin will be used, unless you set your own value.
97
102
 
98
103
  ## How to Contribute
99
104
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
29
29
  s.required_ruby_version = '>= 2.6'
30
30
  s.name = 'jekyll-chatgpt-translate'
31
- s.version = '0.0.24'
31
+ s.version = '0.0.25'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -64,6 +64,10 @@ class GptTranslate::ChatGPT
64
64
  par
65
65
  elsif @key.empty?
66
66
  par
67
+ elsif par.start_with?('* ')
68
+ "* #{translate_par(par[2..])}"
69
+ elsif par =~ /^[0-9]+\. /
70
+ "1. #{translate_par(par.split('.', 2)[1])}"
67
71
  else
68
72
  translate_par(par)
69
73
  end
@@ -106,8 +106,8 @@ class GptTranslate::Plain
106
106
  content
107
107
  end
108
108
 
109
- def list_item(content, _type)
110
- "#{content.strip}\n\n"
109
+ def list_item(content, type)
110
+ "#{type == :ordered ? '1.' : '*'} #{content.strip}\n\n"
111
111
  end
112
112
 
113
113
  def paragraph(text)
@@ -23,5 +23,5 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  module GptTranslate
26
- VERSION = '0.0.24'
26
+ VERSION = '0.0.25'
27
27
  end
data/test/test_chatgpt.rb CHANGED
@@ -44,6 +44,20 @@ class GptTranslate::ChatGPTTest < Minitest::Test
44
44
  assert_equal('done!', chat.translate('[OpenAI](https://openai.com) is the creator of ChatGPT', min: 10))
45
45
  end
46
46
 
47
+ def test_unordered_list_item
48
+ stub_request(:any, 'https://api.openai.com/v1/chat/completions')
49
+ .to_return(body: '{"choices":[{"message":{"content": "done!"}}]}')
50
+ chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'en', 'ru')
51
+ assert_equal("* done!\n\n* done!", chat.translate("* First\n\n* Second", min: 1))
52
+ end
53
+
54
+ def test_ordered_list_item
55
+ stub_request(:any, 'https://api.openai.com/v1/chat/completions')
56
+ .to_return(body: '{"choices":[{"message":{"content": "done!"}}]}')
57
+ chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'en', 'ru')
58
+ assert_equal("1. done!\n\n1. done!", chat.translate("1. First\n\n2. Second", min: 1))
59
+ end
60
+
47
61
  def test_dry_mode
48
62
  chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'xx')
49
63
  assert_equal(38, chat.translate('This text should not be sent to OpenAI', min: 100).length)
data/test/test_plain.rb CHANGED
@@ -42,25 +42,25 @@ class GptTranslate::PlainTest < Minitest::Test
42
42
 
43
43
  def test_lists
44
44
  assert_equal(
45
- "first\n\nsecond\n\nthird",
45
+ "* first\n\n* second\n\n* third",
46
46
  GptTranslate::Plain.new("* first\n\n* second\n\n* third").to_s
47
47
  )
48
48
  assert_equal(
49
- 'first',
49
+ '* first',
50
50
  GptTranslate::Plain.new("* first\n\n\n\n").to_s
51
51
  )
52
52
  end
53
53
 
54
54
  def test_ordered_list
55
55
  assert_equal(
56
- "first\n\nsecond\n\nthird",
56
+ "1. first\n\n1. second\n\n1. third",
57
57
  GptTranslate::Plain.new("1. first\n\n2. second\n\n3. third").to_s
58
58
  )
59
59
  end
60
60
 
61
61
  def test_compact_list
62
62
  assert_equal(
63
- "first\n\nsecond\n\nthird",
63
+ "* first\n\n* second\n\n* third",
64
64
  GptTranslate::Plain.new("* first\n* second\n* third").to_s
65
65
  )
66
66
  end
@@ -151,11 +151,11 @@ class GptTranslate::PlainTest < Minitest::Test
151
151
 
152
152
  In this *lovely* letter I will explain how objects work in C++:
153
153
 
154
- Declare a class
154
+ * Declare a class
155
155
 
156
- Make an instance of it
156
+ * Make an instance of it
157
157
 
158
- Delete the instance
158
+ * Delete the instance
159
159
 
160
160
  ## More details
161
161
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko