jekyll-chatgpt-translate 0.0.23 → 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: 245b89b06aae1508c1fd00fa9575ba342ac7340212946f92308307da1e01de1e
4
- data.tar.gz: 62a7ba956bc489efe84cf119457ffd181208882dd0c1939242df08a123c11b10
3
+ metadata.gz: 76c9c7e2f01f4350b38e1343d88918c9a89bfb5ace6bc84855bba6cd401cf027
4
+ data.tar.gz: 35dbf1ac0f89d6a3a68de2a1f36ae451686b665a8ef4a3f9adc4054623d45dc9
5
5
  SHA512:
6
- metadata.gz: 8516fa43643cd48288761e4fbe4afdb628dab9281482ce6e486b05e33d214c610604958d70810ce6ba61918956952fadeadfa4397ffa0e0079d671bc379c01e9
7
- data.tar.gz: f962f34852a2184821635ed8683f0cdcd3373934f185a716f5f1e4e20c8bacd8b671746209ce829fd241da5a61dffe52e2eae74187b957c245e64783b049d86c
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.23'
31
+ s.version = '0.0.25'
32
32
  s.license = 'MIT'
33
33
  s.summary = 'Translate Jekyll Pages Through ChatGPT'
34
34
  s.description = [
@@ -59,11 +59,15 @@ class GptTranslate::ChatGPT
59
59
  elsif par.start_with?('```') || par.end_with?('```')
60
60
  Jekyll.logger.debug("Not translating this code block: #{par.inspect}")
61
61
  par
62
- elsif par =~ /^[^\p{Alnum}\*'"]/
62
+ elsif par =~ /^[^\p{Alnum}\*'"\[]/
63
63
  Jekyll.logger.debug("Not translating this, b/c it's not a plain text: #{par.inspect}")
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
@@ -62,6 +62,7 @@ class GptTranslate::Generator < Jekyll::Generator
62
62
  site.posts.docs.shuffle.each do |doc|
63
63
  plain = GptTranslate::Plain.new(doc.content).to_s
64
64
  config['targets'].each do |target|
65
+ start = Time.now
65
66
  link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
66
67
  lang = target['language']
67
68
  raise 'Language must be defined for each target' if target.nil?
@@ -106,7 +107,8 @@ class GptTranslate::Generator < Jekyll::Generator
106
107
  )
107
108
  site.pages << Jekyll::Page.new(site, site.source, File.dirname(path), File.basename(path))
108
109
  translated += 1
109
- Jekyll.logger.info("Translated via ChatGPT: #{path} (#{File.size(path)} bytes)")
110
+ Jekyll.logger.info("Translated via ChatGPT \
111
+ in #{(Time.now - start).round(2)}s: #{path} (#{File.size(path)} bytes)")
110
112
  end
111
113
  doc.data["translated-#{lang}-url"] = link
112
114
  doc.data['chatgpt-model'] = model
@@ -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.23'
26
+ VERSION = '0.0.25'
27
27
  end
data/test/test_chatgpt.rb CHANGED
@@ -37,6 +37,27 @@ class GptTranslate::ChatGPTTest < Minitest::Test
37
37
  assert_equal('Hello, world!', chat.translate('Hello, world!'))
38
38
  end
39
39
 
40
+ def test_start_with_link
41
+ stub_request(:any, 'https://api.openai.com/v1/chat/completions')
42
+ .to_return(body: '{"choices":[{"message":{"content": "done!"}}]}')
43
+ chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'en', 'ru')
44
+ assert_equal('done!', chat.translate('[OpenAI](https://openai.com) is the creator of ChatGPT', min: 10))
45
+ end
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
+
40
61
  def test_dry_mode
41
62
  chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'xx')
42
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-chatgpt-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-23 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iri