jekyll-chatgpt-translate 0.0.42 → 0.0.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +22 -0
- data/.github/workflows/markdown-lint.yml +40 -0
- data/.github/workflows/rake.yml +21 -0
- data/.github/workflows/yamllint.yml +36 -0
- data/.rubocop.yml +23 -1
- data/.rultor.yml +24 -1
- data/Gemfile +7 -7
- data/LICENSE.txt +1 -1
- data/README.md +96 -55
- data/Rakefile +1 -1
- data/features/cli.feature +35 -0
- data/features/step_definitions/steps.rb +5 -1
- data/features/support/env.rb +1 -1
- data/jekyll-chatgpt-translate.gemspec +2 -2
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +26 -9
- data/lib/jekyll-chatgpt-translate/generator.rb +8 -2
- data/lib/jekyll-chatgpt-translate/pars.rb +2 -2
- data/lib/jekyll-chatgpt-translate/permalink.rb +2 -2
- data/lib/jekyll-chatgpt-translate/ping.rb +2 -2
- data/lib/jekyll-chatgpt-translate/plain.rb +2 -2
- data/lib/jekyll-chatgpt-translate/prompt.rb +2 -2
- data/lib/jekyll-chatgpt-translate/version.rb +2 -2
- data/lib/jekyll-chatgpt-translate.rb +1 -1
- data/logo.png +0 -0
- data/test/test__helper.rb +4 -4
- data/test/test_chatgpt.rb +27 -9
- data/test/test_generator.rb +2 -2
- data/test/test_pars.rb +2 -2
- data/test/test_permalink.rb +2 -2
- data/test/test_ping.rb +2 -2
- data/test/test_plain.rb +2 -2
- data/test/test_prompt.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac33cf289fbc970376efe2e1b6af0693db8a2c8875d059dec1d228c89baee96b
|
4
|
+
data.tar.gz: 3baa2cb4e88e93f3fe26cfb253b7ca939269d351930ba56f10c10aa6f5766c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 629df2b5bbdaf7f51a562d5e941c93e9a18d07dbd868694010076c8657896e7827123b71478d60d903b645dc722e81bd274478de80b68b87bbfe78316cea69ea
|
7
|
+
data.tar.gz: a8099c472aeb3e73f71b94a8221f2bbd549571f1d9414e8b9d787b66823f3d1db9b5411a1a7047376684925c457110e62b1578af463857c3b95d7ab02271ec2d
|
data/.0pdd.yml
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
errors:
|
2
24
|
- yegor256@gmail.com
|
3
25
|
# alerts:
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included
|
13
|
+
# in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
23
|
+
name: markdown-lint
|
24
|
+
'on':
|
25
|
+
push:
|
26
|
+
branches:
|
27
|
+
- master
|
28
|
+
pull_request:
|
29
|
+
branches:
|
30
|
+
- master
|
31
|
+
paths-ignore: ['paper/**', 'sandbox/**']
|
32
|
+
concurrency:
|
33
|
+
group: markdown-lint-${{ github.ref }}
|
34
|
+
cancel-in-progress: true
|
35
|
+
jobs:
|
36
|
+
markdown-lint:
|
37
|
+
runs-on: ubuntu-22.04
|
38
|
+
steps:
|
39
|
+
- uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017
|
40
|
+
- uses: articulate/actions-markdownlint@v1
|
data/.github/workflows/rake.yml
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
1
22
|
---
|
2
23
|
name: rake
|
3
24
|
on:
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included
|
13
|
+
# in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
23
|
+
name: yamllint
|
24
|
+
'on':
|
25
|
+
push:
|
26
|
+
branches:
|
27
|
+
- master
|
28
|
+
pull_request:
|
29
|
+
branches:
|
30
|
+
- master
|
31
|
+
jobs:
|
32
|
+
yamllint:
|
33
|
+
runs-on: ubuntu-22.04
|
34
|
+
steps:
|
35
|
+
- uses: actions/checkout@v4
|
36
|
+
- uses: ibiqlik/action-yamllint@v3
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
AllCops:
|
2
24
|
Exclude:
|
3
25
|
- 'bin/**/*'
|
@@ -20,7 +42,7 @@ Metrics/AbcSize:
|
|
20
42
|
Metrics/BlockLength:
|
21
43
|
Max: 100
|
22
44
|
Metrics/CyclomaticComplexity:
|
23
|
-
Max:
|
45
|
+
Max: 35
|
24
46
|
Metrics/PerceivedComplexity:
|
25
47
|
Max: 40
|
26
48
|
Layout/EmptyLineAfterGuardClause:
|
data/.rultor.yml
CHANGED
@@ -1,11 +1,34 @@
|
|
1
|
+
# (The MIT License)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in all
|
13
|
+
# copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
# SOFTWARE.
|
22
|
+
---
|
1
23
|
docker:
|
2
|
-
image: yegor256/rultor-image:1.
|
24
|
+
image: yegor256/rultor-image:1.23.1
|
3
25
|
assets:
|
4
26
|
rubygems.yml: yegor256/home#assets/rubygems.yml
|
5
27
|
install: |
|
6
28
|
pdd -f /dev/null
|
7
29
|
bundle install --no-color
|
8
30
|
release:
|
31
|
+
pre: false
|
9
32
|
script: |-
|
10
33
|
bundle exec rake
|
11
34
|
rm -rf *.gem
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -25,11 +25,11 @@
|
|
25
25
|
source 'https://rubygems.org'
|
26
26
|
gemspec
|
27
27
|
|
28
|
-
gem 'cucumber', '9.
|
28
|
+
gem 'cucumber', '9.2.0', require: false
|
29
29
|
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
30
|
-
gem 'minitest', '5.
|
31
|
-
gem 'rake', '13.1
|
32
|
-
gem 'rubocop', '1.
|
33
|
-
gem 'rubocop-rspec', '2.
|
30
|
+
gem 'minitest', '5.22.3', require: false
|
31
|
+
gem 'rake', '13.2.1', require: false
|
32
|
+
gem 'rubocop', '1.63.2', require: false
|
33
|
+
gem 'rubocop-rspec', '2.29.1', require: false
|
34
34
|
gem 'simplecov', '0.22.0', require: false
|
35
|
-
gem 'webmock', '3.
|
35
|
+
gem 'webmock', '3.23.0', require: false
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
|
1
|
+
# Translator of Jekyll Pages via ChatGPT
|
2
|
+
|
3
|
+
![logo](logo.png)
|
2
4
|
|
3
5
|
[![rake](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/jekyll-chatgpt-translate/actions/workflows/rake.yml)
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/jekyll-chatgpt-translate.svg)](http://badge.fury.io/rb/jekyll-chatgpt-translate)
|
5
7
|
|
6
|
-
If you have a [Jekyll](https://jekyllrb.com/) static site,
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
If you have a [Jekyll](https://jekyllrb.com/) static site,
|
9
|
+
this plugin may help you automatically
|
10
|
+
translate its pages to another language, through
|
11
|
+
[ChatGPT](https://chat.openai.com/). See how it
|
12
|
+
works for [my blog](https://github.com/yegor256/ru.yegor256.com),
|
13
|
+
for example [this page](https://ru.yegor256.com/2023-08-13-dictators.html)
|
14
|
+
is translated to
|
10
15
|
[English](https://ru.yegor256.com/english/2023-08-13-dictators.html).
|
11
16
|
|
12
|
-
Install it first (you need
|
17
|
+
Install it first (you need
|
18
|
+
[Ruby 3+](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/)
|
13
19
|
and [Jekyll 3+](https://jekyllrb.com/)):
|
14
20
|
|
15
|
-
```
|
21
|
+
```bash
|
16
22
|
gem install jekyll-chatgpt-translate
|
17
23
|
```
|
18
24
|
|
@@ -32,89 +38,124 @@ chatgpt-translate:
|
|
32
38
|
permalink: :year-:month-:day-:slug-chinese.html
|
33
39
|
layout: chinese-translated
|
34
40
|
-
|
41
|
+
only: ru-post
|
35
42
|
language: fr
|
36
43
|
permalink: :year-:month-:day-:title-french.html
|
37
44
|
```
|
38
45
|
|
39
|
-
Here, the source language is English (`en`), the
|
40
|
-
|
46
|
+
Here, the source language is English (`en`), the targets are
|
47
|
+
Chinese (`zh`) and French (`fr`),
|
48
|
+
where the layout for Chinese is `_layout/chinese-translated.html` and for
|
49
|
+
French is `_layout/translated.html` (you must have these files).
|
41
50
|
|
42
|
-
OpenAI API KEY must be set in `OPENAI_API_KEY` environment variable,
|
43
|
-
|
44
|
-
|
51
|
+
OpenAI API KEY must be set in the `OPENAI_API_KEY` environment variable,
|
52
|
+
otherwise
|
53
|
+
the plugin will not do any translation and won't generate translated pages.
|
54
|
+
You can get your key
|
55
|
+
[here][open-ai].
|
45
56
|
|
46
|
-
|
47
|
-
|
57
|
+
OpenAI API base URL can be customized by the `OPENAI_API_BASE`
|
58
|
+
environment variable.
|
59
|
+
If this variable is not set, the default value is `https://api.openai.com/`.
|
60
|
+
|
61
|
+
Inside the original page you can use `{{ page.chatgpt-translate.urls[XX] }}`
|
62
|
+
in order to render the URL
|
63
|
+
of the translated page, where `XX` is the [ISO-639-1][iso-639]
|
48
64
|
code of the target language.
|
49
|
-
Inside the translated page you can use
|
50
|
-
|
65
|
+
Inside the translated page you can use
|
66
|
+
`{{ page.chatgpt-translate.original-url }}` in order
|
67
|
+
to get the URL of the page that was translated.
|
51
68
|
|
52
69
|
You can also use `{{ page.chatgpt-translate.model }}`
|
53
|
-
inside both the original page and the translated one,
|
70
|
+
inside both the original page and the translated one,
|
71
|
+
to refer to the model of ChatGPT.
|
54
72
|
The presence of `{{ page.chatgpt-translate }}` means that the
|
55
|
-
page was translated or the translated HTML was downloaded
|
73
|
+
page was translated or the translated HTML was downloaded
|
74
|
+
and placed into the `_site` directory.
|
56
75
|
|
57
76
|
## Options
|
58
77
|
|
59
78
|
Full list of options available to specify in `_config.yml`:
|
60
79
|
|
61
|
-
|
62
|
-
|
80
|
+
* `api_key_file` (optional) — the file with OpenAI API key.
|
81
|
+
If this option is not specified,
|
82
|
+
it is expected to have the key in the `OPENAI_API_KEY` environment variable.
|
83
|
+
|
84
|
+
* `api_key` (optional) — the OpenAI API key itself. This is a very bad idea to
|
85
|
+
specify it right in the `_config.yml` file, but it's still possible.
|
63
86
|
|
64
|
-
|
65
|
-
|
87
|
+
* `model` (optional) — specifies the model to use by ChatGPT,
|
88
|
+
[examples are here](https://github.com/alexrudall/ruby-openai#models).
|
66
89
|
|
67
|
-
|
68
|
-
[examples are here](https://github.com/alexrudall/ruby-openai#models).
|
90
|
+
* `source` (optional) — is the [ISO-639-1][iso-639] code of the source language.
|
69
91
|
|
70
|
-
|
71
|
-
|
92
|
+
* `no_download` (optional) — if this attribute is present, the plugin won't try
|
93
|
+
to find HTML versions of translated pages in the Internet and won't try to
|
94
|
+
download them and place into the `_site` directory. Thus, your entire site
|
95
|
+
will have to be re-translated on every build (might be very ineffective
|
96
|
+
if the site is big!)
|
72
97
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
98
|
+
* `min_chars` (optional) — minimum number of chars that must be present in
|
99
|
+
a paragraph in order for it to be feasible to go to ChatGPT. The robot
|
100
|
+
doesn't translate short paragraphs pretty enough. It's better to keep this
|
101
|
+
number big enough, to avoid silly translations. The default is 128.
|
77
102
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
number big enough, to avoid silly translations. The default is 128.
|
103
|
+
* `window_length` (optional) — maximum number of words to be sent to
|
104
|
+
OpenAI API in one
|
105
|
+
request. The default is 2048.
|
82
106
|
|
83
|
-
|
84
|
-
|
107
|
+
* `layout` (optional) — is name of the file in `_layouts` directory,
|
108
|
+
without the extension.
|
109
|
+
This layout will be specified for the pages generated by this plugin.
|
110
|
+
The default value is `translated` (expecting you to have
|
111
|
+
`_layouts/translated.html` file available).
|
85
112
|
|
86
|
-
|
87
|
-
|
88
|
-
The default value is `translated` (expecting you to have `_layouts/translated.html` file available).
|
113
|
+
* `targets` (mandatory) — an array of target languages, each of
|
114
|
+
which has the following attributes
|
89
115
|
|
90
|
-
* `
|
116
|
+
* `only` (optional) —
|
117
|
+
it this is present, only the posts with the provided "layout"
|
118
|
+
will be translated to this target
|
91
119
|
|
92
|
-
|
120
|
+
* `language` (mandatory) —
|
121
|
+
[ISO-639-1][iso-639] code of the target language
|
93
122
|
|
94
|
-
|
123
|
+
* `permalink` (mandatory) — template to use for newly generated pages
|
95
124
|
|
96
|
-
|
125
|
+
* `layout` (optional) — the name of the file in the `_layouts` directory
|
97
126
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
127
|
+
* `threshold` (optional) — maximum number of pages to generate
|
128
|
+
in one build cycle.
|
129
|
+
The default value is 1024. It is recommended to use smaller number, in order
|
130
|
+
to avoid too long builds. You can re-run the build again and missing pages
|
131
|
+
will be generated. Thus, in a few builds the entire site will be translated.
|
102
132
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
133
|
+
* `version` (optional) — the version that will be attached to each
|
134
|
+
generated page,
|
135
|
+
in order to avoid repetitive translations on one hand
|
136
|
+
and enable re-translations
|
137
|
+
when the `version` is changed on another hand. By default, the version of
|
138
|
+
this plugin will be used, unless you set your own value.
|
107
139
|
|
108
|
-
|
109
|
-
|
140
|
+
* `tmpdir` (optional) — the name of the directory where to keep temporary files,
|
141
|
+
`_chatgpt-translate` is the default value.
|
110
142
|
|
111
143
|
## How to Contribute
|
112
144
|
|
113
145
|
Make a fork and then test it locally like this:
|
114
146
|
|
115
147
|
```bash
|
116
|
-
|
117
|
-
|
148
|
+
bundle update
|
149
|
+
bundle exec rake
|
118
150
|
```
|
119
151
|
|
120
152
|
If it works, make changes, test again, and then submit a pull request.
|
153
|
+
|
154
|
+
In order to run a single test, do this:
|
155
|
+
|
156
|
+
```bash
|
157
|
+
bundle exec ruby test/test_generator.rb
|
158
|
+
```
|
159
|
+
|
160
|
+
[open-ai]: https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key
|
161
|
+
[iso-639]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/features/cli.feature
CHANGED
@@ -207,3 +207,38 @@ Feature: Simple site building
|
|
207
207
|
And Stdout contains "The page is absent, need to translate"
|
208
208
|
And File "_site/2023/01/01/hello.html" exists
|
209
209
|
And File "_site/2023/01/01/hello.html" contains "NO TRANSLATION!"
|
210
|
+
|
211
|
+
Scenario: Translation skipped due to the ONLY tag
|
212
|
+
Given I have a "_config.yml" file with content:
|
213
|
+
"""
|
214
|
+
url: https://www.yegor256.com
|
215
|
+
markdown: kramdown
|
216
|
+
plugins:
|
217
|
+
- jekyll-chatgpt-translate
|
218
|
+
chatgpt-translate:
|
219
|
+
source: en
|
220
|
+
threshold: 0
|
221
|
+
api_key: "it-is-not-used, because EN to EN translation"
|
222
|
+
layout: default
|
223
|
+
targets:
|
224
|
+
-
|
225
|
+
only: ABC
|
226
|
+
language: en
|
227
|
+
permalink: :slug-en.html
|
228
|
+
"""
|
229
|
+
And I have a "_layouts/default.html" file with content:
|
230
|
+
"""
|
231
|
+
{{ content }}
|
232
|
+
"""
|
233
|
+
And I have a "_posts/2023-01-01-hello.md" file with content:
|
234
|
+
"""
|
235
|
+
---
|
236
|
+
layout: default
|
237
|
+
title: foo
|
238
|
+
---
|
239
|
+
Hello, world!
|
240
|
+
"""
|
241
|
+
Then I build Jekyll site
|
242
|
+
And Exit code is zero
|
243
|
+
And File "_site/2023/01/01/hello.html" exists
|
244
|
+
And File "_site/2023/01/01/hello-en.html" doesn't exist
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -53,6 +53,10 @@ Then('File {string} exists') do |string|
|
|
53
53
|
raise "The file \"#{string}\" is absent:\n#{`tree -s`}" unless File.exist?(string)
|
54
54
|
end
|
55
55
|
|
56
|
+
Then('File {string} doesn\'t exist') do |string|
|
57
|
+
raise "The file \"#{string}\" is present:\n#{`tree -s`}" if File.exist?(string)
|
58
|
+
end
|
59
|
+
|
56
60
|
Then('File {string} contains {string}') do |string, string2|
|
57
61
|
raise "The file \"#{string}\" is absent" unless File.exist?(string)
|
58
62
|
content = File.read(string)
|
data/features/support/env.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -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 = '>= 3.0'
|
30
30
|
s.name = 'jekyll-chatgpt-translate'
|
31
|
-
s.version = '0.0.
|
31
|
+
s.version = '0.0.44'
|
32
32
|
s.license = 'MIT'
|
33
33
|
s.summary = 'Translate Jekyll Pages Through ChatGPT'
|
34
34
|
s.description = [
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -35,7 +35,7 @@ module GptTranslate; end
|
|
35
35
|
|
36
36
|
# Abstraction of ChatGPT.
|
37
37
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
38
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
38
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
39
39
|
# License:: MIT
|
40
40
|
class GptTranslate::ChatGPT
|
41
41
|
# Is TRUE if we already shown to the user the available models.
|
@@ -45,7 +45,7 @@ class GptTranslate::ChatGPT
|
|
45
45
|
# +key+ OpenAI API Key, which can't be nil, but can be empty string, which means dry mode (no calls to OpenAI)
|
46
46
|
# +source+ The language to translate from
|
47
47
|
# +target+ The language to translate into
|
48
|
-
def initialize(key, model, source, target, client: OpenAI::Client.new(access_token: key))
|
48
|
+
def initialize(key, model, source, target, client: OpenAI::Client.new(access_token: key, uri_base: api_base_url))
|
49
49
|
raise 'OpenAI key cannot be nil' if key.nil?
|
50
50
|
@key = key
|
51
51
|
@model = model
|
@@ -54,6 +54,19 @@ class GptTranslate::ChatGPT
|
|
54
54
|
@client = client
|
55
55
|
end
|
56
56
|
|
57
|
+
def api_base_url
|
58
|
+
url = ENV.fetch('OPENAI_API_BASE', 'https://api.openai.com/')
|
59
|
+
Jekyll.logger.info("Current OpenAI API Base URL: #{url.inspect}")
|
60
|
+
unless url == 'https://api.openai.com/'
|
61
|
+
Jekyll.logger.warn(
|
62
|
+
'Warning: You\'re using a custom endpoint for the OpenAI API. ' \
|
63
|
+
'The provider of this endpoint may have access to all details ' \
|
64
|
+
'of your requests. Only use a custom endpoint if you trust the provider.'
|
65
|
+
)
|
66
|
+
end
|
67
|
+
url
|
68
|
+
end
|
69
|
+
|
57
70
|
def translate(markdown, min: 32, window_length: 2000)
|
58
71
|
pars = GptTranslate::Pars.new(markdown).to_a
|
59
72
|
ready = []
|
@@ -62,7 +75,7 @@ class GptTranslate::ChatGPT
|
|
62
75
|
par = pa.dup
|
63
76
|
par.strip!
|
64
77
|
if @source == @target
|
65
|
-
Jekyll.logger.debug("No need to translate from #{@source.inspect} to
|
78
|
+
Jekyll.logger.debug("No need to translate from #{@source.inspect} to itself: #{par.inspect}")
|
66
79
|
ready[i] = par
|
67
80
|
elsif par.length < min
|
68
81
|
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
|
@@ -142,15 +155,19 @@ class GptTranslate::ChatGPT
|
|
142
155
|
rescue StandardError => e
|
143
156
|
attempt += 1
|
144
157
|
if attempt < 4
|
145
|
-
Jekyll.logger.error(
|
146
|
-
|
158
|
+
Jekyll.logger.error(
|
159
|
+
"ChatGPT failed to answer to #{prompt.inspect}" \
|
160
|
+
"(attempt no.#{attempt}): #{e.message.inspect}"
|
161
|
+
)
|
147
162
|
retry
|
148
163
|
end
|
149
164
|
raise e
|
150
165
|
end
|
151
|
-
Jekyll.logger.info(
|
152
|
-
|
153
|
-
|
166
|
+
Jekyll.logger.info(
|
167
|
+
"Translated #{par.split.count} #{@source.upcase} words " \
|
168
|
+
"to #{answer.split.count} #{@target.upcase} words " \
|
169
|
+
"through #{@model} in #{(Time.now - start).round(2)}s: #{"#{par[0..24]}...".inspect}"
|
170
|
+
)
|
154
171
|
answer
|
155
172
|
end
|
156
173
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -36,7 +36,7 @@ module GptTranslate; end
|
|
36
36
|
|
37
37
|
# Pages generator.
|
38
38
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
39
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
39
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
40
40
|
# License:: MIT
|
41
41
|
class GptTranslate::Generator < Jekyll::Generator
|
42
42
|
safe true
|
@@ -63,11 +63,17 @@ class GptTranslate::Generator < Jekyll::Generator
|
|
63
63
|
marker = "Translated by ChatGPT #{model}#{version.empty? ? '' : "/#{version}"}"
|
64
64
|
site.posts.docs.shuffle.each_with_index do |doc, pos|
|
65
65
|
plain = GptTranslate::Plain.new(doc.content).to_s
|
66
|
+
layout = doc['layout']
|
66
67
|
config['targets'].each do |target|
|
67
68
|
pstart = Time.now
|
68
69
|
link = GptTranslate::Permalink.new(doc, target['permalink']).to_path
|
69
70
|
lang = target['language']
|
70
71
|
raise 'Language must be defined for each target' if target.nil?
|
72
|
+
only = target['only']
|
73
|
+
if !only.nil? && layout != only
|
74
|
+
Jekyll.logger.debug("Not translating #{link.inspect}, b/c 'only' set to '#{only}'")
|
75
|
+
next
|
76
|
+
end
|
71
77
|
path = File.join(home, lang, doc.basename.gsub(/\.md$/, "-#{lang}.md"))
|
72
78
|
FileUtils.mkdir_p(File.dirname(path))
|
73
79
|
File.write(
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,7 +27,7 @@ module GptTranslate; end
|
|
27
27
|
|
28
28
|
# Markdown broken down ito pars.
|
29
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
30
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
30
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
31
31
|
# License:: MIT
|
32
32
|
class GptTranslate::Pars
|
33
33
|
# Ctor.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,7 +29,7 @@ module GptTranslate; end
|
|
29
29
|
|
30
30
|
# Permalink.
|
31
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
33
33
|
# License:: MIT
|
34
34
|
class GptTranslate::Permalink
|
35
35
|
def initialize(doc, template)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -36,7 +36,7 @@ module GptTranslate; end
|
|
36
36
|
|
37
37
|
# Ping one page of a site.
|
38
38
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
39
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
39
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
40
40
|
# License:: MIT
|
41
41
|
class GptTranslate::Ping
|
42
42
|
# Ctor.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,7 +29,7 @@ module GptTranslate; end
|
|
29
29
|
|
30
30
|
# Markdown to plain text.
|
31
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
33
33
|
# License:: MIT
|
34
34
|
class GptTranslate::Plain
|
35
35
|
# Ctor.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -30,7 +30,7 @@ module GptTranslate; end
|
|
30
30
|
|
31
31
|
# Prompt for ChatGPT.
|
32
32
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
33
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
33
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
34
34
|
# License:: MIT
|
35
35
|
class GptTranslate::Prompt
|
36
36
|
# Ctor.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -23,5 +23,5 @@
|
|
23
23
|
# SOFTWARE.
|
24
24
|
|
25
25
|
module GptTranslate
|
26
|
-
VERSION = '0.0.
|
26
|
+
VERSION = '0.0.44'
|
27
27
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/logo.png
CHANGED
Binary file
|
data/test/test__helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
3
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -33,7 +33,7 @@ module GptTranslate; end
|
|
33
33
|
|
34
34
|
# Fake.
|
35
35
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
36
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
36
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
37
37
|
# License:: MIT
|
38
38
|
class GptTranslate::FakeSite
|
39
39
|
attr_reader :config, :pages, :static_files
|
@@ -81,7 +81,7 @@ end
|
|
81
81
|
|
82
82
|
# Fake.
|
83
83
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
84
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
84
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
85
85
|
# License:: MIT
|
86
86
|
class GptTranslate::FakeDocument
|
87
87
|
attr_reader :data
|
@@ -118,7 +118,7 @@ end
|
|
118
118
|
|
119
119
|
# Fake.
|
120
120
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
121
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
121
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
122
122
|
# License:: MIT
|
123
123
|
class GptTranslate::FakePosts
|
124
124
|
attr_reader :config
|
data/test/test_chatgpt.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -29,11 +29,11 @@ require_relative '../lib/jekyll-chatgpt-translate/chatgpt'
|
|
29
29
|
|
30
30
|
# ChatGPT test.
|
31
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
32
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
32
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
33
33
|
# License:: MIT
|
34
34
|
class GptTranslate::ChatGPTTest < Minitest::Test
|
35
35
|
def test_short_text
|
36
|
-
chat = GptTranslate::ChatGPT.new('fake-key', 'foo', 'xx', '
|
36
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'foo', 'xx', 'zz')
|
37
37
|
assert_equal('Hello, world!', chat.translate('Hello, world!'))
|
38
38
|
end
|
39
39
|
|
@@ -56,12 +56,12 @@ class GptTranslate::ChatGPTTest < Minitest::Test
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_dry_mode
|
59
|
-
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', '
|
59
|
+
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'zz')
|
60
60
|
assert_equal(38, chat.translate('This text should not be sent to OpenAI', min: 100).length)
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_no_translation
|
64
|
-
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', '
|
64
|
+
chat = GptTranslate::ChatGPT.new('', 'foo', 'xx', 'zz')
|
65
65
|
chat.translate(
|
66
66
|
"
|
67
67
|
How are you, my friend? This text must be translated through ChatGPT.
|
@@ -82,12 +82,17 @@ class GptTranslate::ChatGPTTest < Minitest::Test
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_markup
|
85
|
-
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', '
|
86
|
-
assert_equal('<img src="a"/>', chat.translate('<img src="a"/>'))
|
85
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', 'zz')
|
86
|
+
assert_equal('<img src="a"/>', chat.translate('<img src="a"/>', min: 1))
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_image
|
90
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'xx', 'zz')
|
91
|
+
assert_equal('![some image](/foo.png)', chat.translate('![some image](/foo.png)', min: 1))
|
87
92
|
end
|
88
93
|
|
89
94
|
def test_code_block
|
90
|
-
chat = GptTranslate::ChatGPT.new('fake-key', '', 'xx', '
|
95
|
+
chat = GptTranslate::ChatGPT.new('fake-key', '', 'xx', 'zz')
|
91
96
|
chat.translate("```\ntest\n```", min: 0)
|
92
97
|
end
|
93
98
|
|
@@ -127,8 +132,21 @@ class GptTranslate::ChatGPTTest < Minitest::Test
|
|
127
132
|
private
|
128
133
|
|
129
134
|
def stub_it!
|
130
|
-
|
135
|
+
url = "#{api_base_url}v1/chat/completions"
|
136
|
+
stub_request(:any, url).to_return(
|
131
137
|
body: '{"choices":[{"message":{"content": "done!"}}]}'
|
132
138
|
)
|
133
139
|
end
|
140
|
+
|
141
|
+
def api_base_url
|
142
|
+
url = ENV.fetch('OPENAI_API_BASE', 'https://api.openai.com/')
|
143
|
+
Jekyll.logger.info("Current OpenAI API Base URL: #{url.inspect}")
|
144
|
+
|
145
|
+
warning_msg = 'Warning: You\'re using a custom endpoint for the OpenAI API. ' \
|
146
|
+
'The provider of this endpoint may have access to all details ' \
|
147
|
+
'of your requests. Only use a custom endpoint if you trust the provider.'
|
148
|
+
Jekyll.logger.warn(warning_msg) if url != 'https://api.openai.com/'
|
149
|
+
|
150
|
+
url
|
151
|
+
end
|
134
152
|
end
|
data/test/test_generator.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -30,7 +30,7 @@ require_relative '../lib/jekyll-chatgpt-translate/generator'
|
|
30
30
|
|
31
31
|
# Generator test.
|
32
32
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
33
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
33
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
34
34
|
# License:: MIT
|
35
35
|
class GptTranslate::GeneratorTest < Minitest::Test
|
36
36
|
def test_simple_scenario
|
data/test/test_pars.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/jekyll-chatgpt-translate/pars'
|
|
28
28
|
|
29
29
|
# Test for Pars.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class GptTranslate::ParsTest < Minitest::Test
|
34
34
|
def test_simple_cases
|
data/test/test_permalink.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/jekyll-chatgpt-translate/permalink'
|
|
28
28
|
|
29
29
|
# Permalink test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class GptTranslate::PermalinkTest < Minitest::Test
|
34
34
|
def test_simple_link
|
data/test/test_ping.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -31,7 +31,7 @@ require_relative '../lib/jekyll-chatgpt-translate/ping'
|
|
31
31
|
|
32
32
|
# Ping test.
|
33
33
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
34
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
34
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
35
35
|
# License:: MIT
|
36
36
|
class GptTranslate::PingTest < Minitest::Test
|
37
37
|
def test_when_exists
|
data/test/test_plain.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/jekyll-chatgpt-translate/plain'
|
|
28
28
|
|
29
29
|
# Plain test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class GptTranslate::PlainTest < Minitest::Test
|
34
34
|
def test_simple_map
|
data/test/test_prompt.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# (The MIT License)
|
4
4
|
#
|
5
|
-
# Copyright (c) 2023 Yegor Bugayenko
|
5
|
+
# Copyright (c) 2023-2024 Yegor Bugayenko
|
6
6
|
#
|
7
7
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +28,7 @@ require_relative '../lib/jekyll-chatgpt-translate/prompt'
|
|
28
28
|
|
29
29
|
# Prompt test.
|
30
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
-
# Copyright:: Copyright (c) 2023 Yegor Bugayenko
|
31
|
+
# Copyright:: Copyright (c) 2023-2024 Yegor Bugayenko
|
32
32
|
# License:: MIT
|
33
33
|
class GptTranslate::PromptTest < Minitest::Test
|
34
34
|
def head(source, target)
|
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.
|
4
|
+
version: 0.0.44
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: humanize
|
@@ -132,7 +132,9 @@ extra_rdoc_files:
|
|
132
132
|
- LICENSE.txt
|
133
133
|
files:
|
134
134
|
- ".0pdd.yml"
|
135
|
+
- ".github/workflows/markdown-lint.yml"
|
135
136
|
- ".github/workflows/rake.yml"
|
137
|
+
- ".github/workflows/yamllint.yml"
|
136
138
|
- ".gitignore"
|
137
139
|
- ".pdd"
|
138
140
|
- ".rubocop.yml"
|