jekyll-chatgpt-translate 0.0.41 → 0.0.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rultor.yml +3 -2
- data/Gemfile +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +6 -3
- data/Rakefile +1 -1
- data/features/step_definitions/steps.rb +1 -1
- data/features/support/env.rb +1 -1
- data/jekyll-chatgpt-translate.gemspec +2 -2
- data/lib/jekyll-chatgpt-translate/chatgpt.rb +21 -8
- data/lib/jekyll-chatgpt-translate/generator.rb +2 -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/test/test__helper.rb +4 -4
- data/test/test_chatgpt.rb +44 -10
- 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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 282a1bba0105b06241fdc1f97d2b57884da35af5c0f582bc30aade82ce534973
|
4
|
+
data.tar.gz: 552423230bc60635277ab13b2d5d4551cbda16f1a08892aea4515a376cfb93ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82ad30f07e2a226211bd0e433883b1580f16ce2f8ddfd3bb871e40a85c27e0b8e5ec5017e5832ee262b232175e6447e002ebda58318352b5bb21310bcc27919
|
7
|
+
data.tar.gz: 691c9dc95ad30131b71325f2380b4d867fb9a510df961de7bba6ba5965c56be401d28e2460727dc6a8e6c3609b048b31d33956c14e8b3fc468bac4287a2d4496
|
data/.rultor.yml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
docker:
|
2
|
-
image: yegor256/rultor-image:1.
|
2
|
+
image: yegor256/rultor-image:1.22.0
|
3
3
|
assets:
|
4
4
|
rubygems.yml: yegor256/home#assets/rubygems.yml
|
5
5
|
install: |
|
6
6
|
pdd -f /dev/null
|
7
|
-
|
7
|
+
bundle install --no-color
|
8
8
|
release:
|
9
|
+
pre: false
|
9
10
|
script: |-
|
10
11
|
bundle exec rake
|
11
12
|
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
|
@@ -27,9 +27,9 @@ gemspec
|
|
27
27
|
|
28
28
|
gem 'cucumber', '9.1.0', require: false
|
29
29
|
gem 'kramdown-parser-gfm', '1.1.0', require: false
|
30
|
-
gem 'minitest', '5.
|
30
|
+
gem 'minitest', '5.21.1', require: false
|
31
31
|
gem 'rake', '13.1.0', require: false
|
32
|
-
gem 'rubocop', '1.
|
33
|
-
gem 'rubocop-rspec', '2.
|
32
|
+
gem 'rubocop', '1.59.0', require: false
|
33
|
+
gem 'rubocop-rspec', '2.26.1', require: false
|
34
34
|
gem 'simplecov', '0.22.0', require: false
|
35
35
|
gem 'webmock', '3.19.1', require: false
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -36,13 +36,16 @@ chatgpt-translate:
|
|
36
36
|
permalink: :year-:month-:day-:title-french.html
|
37
37
|
```
|
38
38
|
|
39
|
-
Here, the source language is English (`en`), the
|
40
|
-
the layout is `_layout/translated.html`
|
39
|
+
Here, the source language is English (`en`), the targets are Chinese (`zh`) and French (`fr`),
|
40
|
+
where the layout for Chinese is `_layout/chinese-translated.html` and for
|
41
|
+
French is `_layout/translated.html` (you must have these files).
|
41
42
|
|
42
|
-
OpenAI API KEY must be set in `OPENAI_API_KEY` environment variable, otherwise
|
43
|
+
OpenAI API KEY must be set in the `OPENAI_API_KEY` environment variable, otherwise
|
43
44
|
the plugin will not do any translation and won't generate translated pages.
|
44
45
|
You can get your key [here](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key).
|
45
46
|
|
47
|
+
OpenAI API BASE (optional) — the base URL for the OpenAI API. Can be customized in "OPENAI_API_BASE" environment variable. If this variable is not set, the default value is "https://api.openai.com/".
|
48
|
+
|
46
49
|
Inside the original page you can use `{{ page.chatgpt-translate.urls[XX] }}` in order to render the URL
|
47
50
|
of the translated page, where `XX` is the [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
48
51
|
code of the target language.
|
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
|
@@ -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
|
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.43'
|
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,12 +45,25 @@ 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)
|
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
|
52
52
|
@source = source
|
53
53
|
@target = target
|
54
|
+
@client = client
|
55
|
+
end
|
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
|
+
|
61
|
+
warning_msg = 'Warning: You\'re using a custom endpoint for the OpenAI API. ' \
|
62
|
+
'The provider of this endpoint may have access to all details ' \
|
63
|
+
'of your requests. Only use a custom endpoint if you trust the provider.'
|
64
|
+
Jekyll.logger.warn(warning_msg) if url != 'https://api.openai.com/'
|
65
|
+
|
66
|
+
url
|
54
67
|
end
|
55
68
|
|
56
69
|
def translate(markdown, min: 32, window_length: 2000)
|
@@ -61,7 +74,7 @@ class GptTranslate::ChatGPT
|
|
61
74
|
par = pa.dup
|
62
75
|
par.strip!
|
63
76
|
if @source == @target
|
64
|
-
Jekyll.logger.debug("No need to translate from #{@source.inspect} to
|
77
|
+
Jekyll.logger.debug("No need to translate from #{@source.inspect} to itself: #{par.inspect}")
|
65
78
|
ready[i] = par
|
66
79
|
elsif par.length < min
|
67
80
|
Jekyll.logger.debug("Not translating this, b/c too short: #{par.inspect}")
|
@@ -115,9 +128,8 @@ class GptTranslate::ChatGPT
|
|
115
128
|
end
|
116
129
|
|
117
130
|
def translate_par(par)
|
118
|
-
client = OpenAI::Client.new(access_token: @key)
|
119
131
|
if @@models_printed
|
120
|
-
Jekyll.logger.info("Available ChatGPT models: #{client.models.list['data'].map { |m| m['id'] }.join(', ')}")
|
132
|
+
Jekyll.logger.info("Available ChatGPT models: #{@client.models.list['data'].map { |m| m['id'] }.join(', ')}")
|
121
133
|
@@models_printed = true
|
122
134
|
end
|
123
135
|
prompt = GptTranslate::Prompt.new(par, @source, @target).to_s
|
@@ -125,14 +137,15 @@ class GptTranslate::ChatGPT
|
|
125
137
|
answer = nil
|
126
138
|
attempt = 0
|
127
139
|
begin
|
128
|
-
response = client.chat(
|
140
|
+
response = @client.chat(
|
129
141
|
parameters: {
|
130
142
|
model: @model,
|
131
143
|
messages: [{ role: 'user', content: prompt }],
|
132
144
|
temperature: 0.7
|
133
145
|
}
|
134
146
|
)
|
135
|
-
|
147
|
+
json = response.is_a?(Hash) ? response : JSON.parse(response)
|
148
|
+
answer = json.dig('choices', 0, 'message', 'content')
|
136
149
|
if answer.nil?
|
137
150
|
Jekyll.logger.error("No content returned by ChatGPT: #{response}")
|
138
151
|
raise 'No content returned by ChatGPT'
|
@@ -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
|
@@ -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.43'
|
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/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
|
|
@@ -109,10 +114,39 @@ class GptTranslate::ChatGPTTest < Minitest::Test
|
|
109
114
|
)
|
110
115
|
end
|
111
116
|
|
117
|
+
def test_with_json
|
118
|
+
client = Object.new
|
119
|
+
def client.chat(*)
|
120
|
+
{ 'choices' => [{ 'message' => { 'content' => 'done!' } }] }
|
121
|
+
end
|
122
|
+
chat = GptTranslate::ChatGPT.new('fake-key', 'gpt-3.5-turbo', 'en', 'ru', client: client)
|
123
|
+
assert_equal(
|
124
|
+
"done!\n\ndone!",
|
125
|
+
chat.translate(
|
126
|
+
"This is the first paragraph\n\nThis is second\n\nThis is third",
|
127
|
+
min: 1, window_length: 4
|
128
|
+
)
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
112
132
|
private
|
113
133
|
|
114
134
|
def stub_it!
|
115
|
-
|
116
|
-
|
135
|
+
url = "#{api_base_url}v1/chat/completions"
|
136
|
+
stub_request(:any, url).to_return(
|
137
|
+
body: '{"choices":[{"message":{"content": "done!"}}]}'
|
138
|
+
)
|
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
|
117
151
|
end
|
118
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.43
|
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-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: humanize
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.4.10
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Translate Jekyll Pages Through ChatGPT
|